@midscene/visualizer 0.26.2 → 0.26.3-beta-20250813021342.0
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/dist/es/blank_polyfill.mjs +2 -0
- package/dist/es/component/blackboard.css +12 -5
- package/dist/es/component/blackboard.mjs +266 -0
- package/dist/es/component/color.mjs +35 -0
- package/dist/es/component/describer.css +9 -5
- package/dist/es/component/describer.mjs +128 -0
- package/dist/es/component/env-config.mjs +112 -0
- package/dist/es/component/github-star.css +1 -0
- package/dist/es/component/github-star.mjs +20 -0
- package/dist/es/component/logo.css +5 -3
- package/dist/es/component/logo.mjs +20 -0
- package/dist/es/component/misc.mjs +54 -0
- package/dist/es/component/pixi-loader.mjs +16 -0
- package/dist/es/component/player.css +88 -70
- package/dist/es/component/player.mjs +628 -0
- package/dist/es/component/playground/ConfigSelector.mjs +53 -0
- package/dist/es/component/playground/ContextPreview.mjs +39 -0
- package/dist/es/component/playground/HistorySelector.mjs +193 -0
- package/dist/es/component/playground/PlaygroundResult.mjs +60 -0
- package/dist/es/component/playground/PromptInput.mjs +225 -0
- package/dist/es/component/playground/ServiceModeControl.mjs +100 -0
- package/dist/es/component/playground/index.css +140 -98
- package/dist/es/component/playground/playground-constants.mjs +45 -0
- package/dist/es/component/playground/playground-utils.mjs +89 -0
- package/dist/es/component/playground/useServerValid.mjs +27 -0
- package/dist/es/component/playground/useStaticPageAgent.mjs +12 -0
- package/dist/es/component/replay-scripts.mjs +271 -0
- package/dist/es/component/shiny-text.css +33 -22
- package/dist/es/component/shiny-text.mjs +15 -0
- package/dist/es/component/store/history.mjs +55 -0
- package/dist/es/component/store/store.mjs +128 -0
- package/dist/es/icons/close.mjs +19 -0
- package/dist/es/icons/history.mjs +30 -0
- package/dist/es/icons/magnifying-glass.mjs +39 -0
- package/dist/es/icons/setting.mjs +20 -0
- package/dist/es/index.mjs +21 -0
- package/dist/es/init.mjs +10 -0
- package/dist/es/{utils.js → utils.mjs} +51 -75
- package/dist/lib/blank_polyfill.js +34 -38
- package/dist/lib/component/blackboard.css +12 -5
- package/dist/lib/component/blackboard.js +293 -306
- package/dist/lib/component/color.js +64 -74
- package/dist/lib/component/describer.css +9 -5
- package/dist/lib/component/describer.js +158 -198
- package/dist/lib/component/env-config.js +142 -147
- package/dist/lib/component/github-star.css +1 -0
- package/dist/lib/component/github-star.js +51 -62
- package/dist/lib/component/logo.css +5 -3
- package/dist/lib/component/logo.js +53 -56
- package/dist/lib/component/misc.js +85 -84
- package/dist/lib/component/pixi-loader.js +49 -80
- package/dist/lib/component/player.css +88 -70
- package/dist/lib/component/player.js +627 -738
- package/dist/lib/component/playground/ConfigSelector.js +91 -92
- package/dist/lib/component/playground/ContextPreview.js +80 -72
- package/dist/lib/component/playground/HistorySelector.js +234 -197
- package/dist/lib/component/playground/PlaygroundResult.js +100 -103
- package/dist/lib/component/playground/PromptInput.js +250 -237
- package/dist/lib/component/playground/ServiceModeControl.js +124 -124
- package/dist/lib/component/playground/index.css +140 -98
- package/dist/lib/component/playground/playground-constants.js +97 -73
- package/dist/lib/component/playground/playground-types.js +17 -31
- package/dist/lib/component/playground/playground-utils.js +140 -168
- package/dist/lib/component/playground/useServerValid.js +55 -86
- package/dist/lib/component/playground/useStaticPageAgent.js +45 -51
- package/dist/lib/component/replay-scripts.js +291 -373
- package/dist/lib/component/shiny-text.css +33 -22
- package/dist/lib/component/shiny-text.js +46 -57
- package/dist/lib/component/store/history.js +58 -64
- package/dist/lib/component/store/store.js +132 -128
- package/dist/lib/icons/close.js +53 -0
- package/dist/lib/icons/history.js +64 -0
- package/dist/lib/icons/magnifying-glass.js +73 -0
- package/dist/lib/icons/setting.js +54 -0
- package/dist/lib/index.js +158 -124
- package/dist/lib/init.js +39 -46
- package/dist/lib/utils.js +105 -109
- package/dist/types/blank_polyfill.d.ts +2 -2
- package/dist/types/component/playground/ConfigSelector.d.ts +1 -0
- package/dist/types/component/playground/ContextPreview.d.ts +1 -0
- package/dist/types/component/playground/HistorySelector.d.ts +1 -0
- package/dist/types/component/playground/PlaygroundResult.d.ts +1 -0
- package/dist/types/component/playground/PromptInput.d.ts +1 -0
- package/dist/types/component/playground/ServiceModeControl.d.ts +1 -0
- package/package.json +16 -18
- package/dist/es/assets/close.909351c0.svg +0 -4
- package/dist/es/assets/history.164a4eab.svg +0 -4
- package/dist/es/assets/magnifying-glass.9498e70e.svg +0 -12
- package/dist/es/assets/setting.80ab7285.svg +0 -11
- package/dist/es/blank_polyfill.js +0 -10
- package/dist/es/component/blackboard.js +0 -286
- package/dist/es/component/color.js +0 -49
- package/dist/es/component/describer.js +0 -173
- package/dist/es/component/env-config.js +0 -117
- package/dist/es/component/github-star.js +0 -31
- package/dist/es/component/logo.js +0 -25
- package/dist/es/component/misc.js +0 -63
- package/dist/es/component/pixi-loader.js +0 -51
- package/dist/es/component/player.js +0 -746
- package/dist/es/component/playground/ConfigSelector.js +0 -64
- package/dist/es/component/playground/ContextPreview.js +0 -42
- package/dist/es/component/playground/HistorySelector.js +0 -168
- package/dist/es/component/playground/PlaygroundResult.js +0 -73
- package/dist/es/component/playground/PromptInput.js +0 -212
- package/dist/es/component/playground/ServiceModeControl.js +0 -100
- package/dist/es/component/playground/playground-constants.js +0 -39
- package/dist/es/component/playground/playground-types.js +0 -6
- package/dist/es/component/playground/playground-utils.js +0 -141
- package/dist/es/component/playground/useServerValid.js +0 -58
- package/dist/es/component/playground/useStaticPageAgent.js +0 -20
- package/dist/es/component/replay-scripts.js +0 -361
- package/dist/es/component/shiny-text.js +0 -30
- package/dist/es/component/store/history.js +0 -34
- package/dist/es/component/store/store.js +0 -99
- package/dist/es/index.js +0 -79
- package/dist/es/init.js +0 -17
- package/dist/index.css +0 -595
- package/dist/index.js +0 -1
- package/dist/lib/assets/close.909351c0.svg +0 -4
- package/dist/lib/assets/history.164a4eab.svg +0 -4
- package/dist/lib/assets/magnifying-glass.9498e70e.svg +0 -12
- package/dist/lib/assets/setting.80ab7285.svg +0 -11
- package/dist/lib/component/common.css +0 -0
- /package/dist/es/component/{common.css → playground/playground-types.mjs} +0 -0
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
var __async = (__this, __arguments, generator) => {
|
|
3
|
-
return new Promise((resolve, reject) => {
|
|
4
|
-
var fulfilled = (value) => {
|
|
5
|
-
try {
|
|
6
|
-
step(generator.next(value));
|
|
7
|
-
} catch (e) {
|
|
8
|
-
reject(e);
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
var rejected = (value) => {
|
|
12
|
-
try {
|
|
13
|
-
step(generator.throw(value));
|
|
14
|
-
} catch (e) {
|
|
15
|
-
reject(e);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
19
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
import Buffer2 from "buffer";
|
|
23
|
-
import processBrowser from "process/browser";
|
|
24
|
-
import console from "console-browserify";
|
|
25
|
-
var buffer = {
|
|
26
|
-
Buffer: Buffer2
|
|
27
|
-
};
|
|
28
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
29
|
-
import "pixi.js/unsafe-eval";
|
|
30
|
-
import { Checkbox } from "antd";
|
|
31
|
-
import * as PIXI from "pixi.js";
|
|
32
|
-
import { useEffect, useMemo, useRef, useState } from "react";
|
|
33
|
-
import { colorForName, highlightColorForType } from "./color";
|
|
34
|
-
import "./blackboard.css";
|
|
35
|
-
import { treeToList } from "@midscene/shared/extractor";
|
|
36
|
-
import { DropShadowFilter } from "pixi-filters";
|
|
37
|
-
import { useBlackboardPreference } from "./store/store";
|
|
38
|
-
const itemFillAlpha = 0.4;
|
|
39
|
-
const highlightAlpha = 0.4;
|
|
40
|
-
const pointRadius = 10;
|
|
41
|
-
const pointMarkForItem = (point, type) => {
|
|
42
|
-
const [x, y] = point;
|
|
43
|
-
const themeColor = highlightColorForType("element");
|
|
44
|
-
const graphics = new PIXI.Graphics();
|
|
45
|
-
graphics.beginFill(themeColor, itemFillAlpha);
|
|
46
|
-
graphics.drawCircle(x, y, pointRadius);
|
|
47
|
-
graphics.endFill();
|
|
48
|
-
return graphics;
|
|
49
|
-
};
|
|
50
|
-
const rectMarkForItem = (rect, name, type) => {
|
|
51
|
-
const { left, top, width, height } = rect;
|
|
52
|
-
let themeColor;
|
|
53
|
-
if (type === "element") {
|
|
54
|
-
themeColor = colorForName(name);
|
|
55
|
-
} else if (type === "searchArea") {
|
|
56
|
-
themeColor = highlightColorForType("searchArea");
|
|
57
|
-
} else {
|
|
58
|
-
themeColor = highlightColorForType("element");
|
|
59
|
-
}
|
|
60
|
-
const alpha = type === "highlight" ? highlightAlpha : itemFillAlpha;
|
|
61
|
-
const graphics = new PIXI.Graphics();
|
|
62
|
-
graphics.beginFill(themeColor, alpha);
|
|
63
|
-
graphics.lineStyle(1, themeColor, 1);
|
|
64
|
-
graphics.drawRect(left, top, width, height);
|
|
65
|
-
graphics.endFill();
|
|
66
|
-
const dropShadowFilter = new DropShadowFilter({
|
|
67
|
-
blur: 2,
|
|
68
|
-
quality: 3,
|
|
69
|
-
alpha: 0.4,
|
|
70
|
-
offset: { x: 4, y: 4 },
|
|
71
|
-
color: 3355443
|
|
72
|
-
});
|
|
73
|
-
graphics.filters = [dropShadowFilter];
|
|
74
|
-
const nameFontSize = 18;
|
|
75
|
-
if (!name) {
|
|
76
|
-
return [graphics];
|
|
77
|
-
}
|
|
78
|
-
const texts = new PIXI.Text(name, {
|
|
79
|
-
fontSize: nameFontSize,
|
|
80
|
-
fill: 0
|
|
81
|
-
});
|
|
82
|
-
texts.x = left;
|
|
83
|
-
texts.y = Math.max(top - (nameFontSize + 4), 0);
|
|
84
|
-
return [graphics, texts];
|
|
85
|
-
};
|
|
86
|
-
const Blackboard = (props) => {
|
|
87
|
-
const highlightElements = props.highlightElements || [];
|
|
88
|
-
const highlightIds = highlightElements.map((e) => e.id);
|
|
89
|
-
const highlightRect = props.highlightRect;
|
|
90
|
-
const highlightPoints = props.highlightPoints;
|
|
91
|
-
const context = props.uiContext;
|
|
92
|
-
const { size, screenshotBase64 } = context;
|
|
93
|
-
const screenWidth = size.width;
|
|
94
|
-
const screenHeight = size.height;
|
|
95
|
-
const domRef = useRef(null);
|
|
96
|
-
const app = useMemo(() => new PIXI.Application(), []);
|
|
97
|
-
const [appInitialed, setAppInitialed] = useState(false);
|
|
98
|
-
const highlightContainer = useMemo(() => new PIXI.Container(), []);
|
|
99
|
-
const elementMarkContainer = useMemo(() => new PIXI.Container(), []);
|
|
100
|
-
const [hoverElement, setHoverElement] = useState(null);
|
|
101
|
-
const pixiBgRef = useRef(void 0);
|
|
102
|
-
const { markerVisible, setMarkerVisible, elementsVisible, setTextsVisible } = useBlackboardPreference();
|
|
103
|
-
useEffect(() => {
|
|
104
|
-
Promise.resolve(
|
|
105
|
-
(() => __async(void 0, null, function* () {
|
|
106
|
-
if (!domRef.current || !screenWidth) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
yield app.init({
|
|
110
|
-
width: screenWidth,
|
|
111
|
-
height: screenHeight,
|
|
112
|
-
background: 16777215
|
|
113
|
-
});
|
|
114
|
-
const canvasEl = domRef.current;
|
|
115
|
-
domRef.current.appendChild(app.canvas);
|
|
116
|
-
const { clientWidth } = domRef.current.parentElement;
|
|
117
|
-
const targetHeight = window.innerHeight * 0.6;
|
|
118
|
-
const viewportRatio = clientWidth / targetHeight;
|
|
119
|
-
if (screenWidth / screenHeight <= viewportRatio) {
|
|
120
|
-
const ratio = targetHeight / screenHeight;
|
|
121
|
-
canvasEl.style.width = `${Math.floor(screenWidth * ratio)}px`;
|
|
122
|
-
canvasEl.style.height = `${Math.floor(screenHeight * ratio)}px`;
|
|
123
|
-
}
|
|
124
|
-
app.stage.addChild(highlightContainer);
|
|
125
|
-
app.stage.addChild(elementMarkContainer);
|
|
126
|
-
setAppInitialed(true);
|
|
127
|
-
}))()
|
|
128
|
-
);
|
|
129
|
-
return () => {
|
|
130
|
-
console.log("will destroy");
|
|
131
|
-
try {
|
|
132
|
-
app.destroy(true, { children: true, texture: true });
|
|
133
|
-
} catch (e) {
|
|
134
|
-
console.warn("destroy failed", e);
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
}, [app, screenWidth, screenHeight]);
|
|
138
|
-
useEffect(() => {
|
|
139
|
-
if (!appInitialed) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
app.stage.eventMode = "static";
|
|
143
|
-
app.stage.hitArea = new PIXI.Rectangle(0, 0, screenWidth, screenHeight);
|
|
144
|
-
const clickHandler = (event) => {
|
|
145
|
-
var _a;
|
|
146
|
-
console.log("pixi click", event);
|
|
147
|
-
const { x, y } = event.data.global;
|
|
148
|
-
(_a = props.onCanvasClick) == null ? void 0 : _a.call(props, [Math.round(x), Math.round(y)]);
|
|
149
|
-
};
|
|
150
|
-
app.stage.on("click", clickHandler);
|
|
151
|
-
return () => {
|
|
152
|
-
var _a;
|
|
153
|
-
(_a = app == null ? void 0 : app.stage) == null ? void 0 : _a.off("click");
|
|
154
|
-
};
|
|
155
|
-
}, [appInitialed, props.onCanvasClick, screenWidth, screenHeight]);
|
|
156
|
-
useEffect(() => {
|
|
157
|
-
if (!appInitialed) {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
const img = new Image();
|
|
161
|
-
img.onload = () => {
|
|
162
|
-
if (!app.stage)
|
|
163
|
-
return;
|
|
164
|
-
const screenshotTexture = PIXI.Texture.from(img);
|
|
165
|
-
const backgroundSprite = new PIXI.Sprite(screenshotTexture);
|
|
166
|
-
backgroundSprite.x = 0;
|
|
167
|
-
backgroundSprite.y = 0;
|
|
168
|
-
backgroundSprite.width = screenWidth;
|
|
169
|
-
backgroundSprite.height = screenHeight;
|
|
170
|
-
backgroundSprite.eventMode = "passive";
|
|
171
|
-
app.stage.addChildAt(backgroundSprite, 0);
|
|
172
|
-
pixiBgRef.current = backgroundSprite;
|
|
173
|
-
};
|
|
174
|
-
img.onerror = (e) => {
|
|
175
|
-
console.error("load screenshot failed", e);
|
|
176
|
-
};
|
|
177
|
-
img.src = screenshotBase64;
|
|
178
|
-
}, [app.stage, appInitialed, screenWidth, screenHeight]);
|
|
179
|
-
const { highlightElementRects } = useMemo(() => {
|
|
180
|
-
const highlightElementRects2 = [];
|
|
181
|
-
highlightContainer.removeChildren();
|
|
182
|
-
elementMarkContainer.removeChildren();
|
|
183
|
-
highlightContainer.eventMode = "passive";
|
|
184
|
-
elementMarkContainer.eventMode = "passive";
|
|
185
|
-
if (highlightRect) {
|
|
186
|
-
const [graphics] = rectMarkForItem(
|
|
187
|
-
highlightRect,
|
|
188
|
-
"Search Area",
|
|
189
|
-
"searchArea"
|
|
190
|
-
);
|
|
191
|
-
highlightContainer.addChild(graphics);
|
|
192
|
-
}
|
|
193
|
-
if (highlightElements.length) {
|
|
194
|
-
highlightElements.forEach((element) => {
|
|
195
|
-
const { rect, content, id } = element;
|
|
196
|
-
const [graphics] = rectMarkForItem(rect, content, "highlight");
|
|
197
|
-
highlightContainer.addChild(graphics);
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
if (highlightPoints == null ? void 0 : highlightPoints.length) {
|
|
201
|
-
highlightPoints.forEach((point) => {
|
|
202
|
-
const graphics = pointMarkForItem(point, "highlightPoint");
|
|
203
|
-
highlightContainer.addChild(graphics);
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
const elements = treeToList(context.tree);
|
|
207
|
-
elements.forEach((element) => {
|
|
208
|
-
const { rect, content, id } = element;
|
|
209
|
-
const ifHighlight = highlightIds.includes(id) || (hoverElement == null ? void 0 : hoverElement.id) === id;
|
|
210
|
-
if (ifHighlight) {
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
const [graphics] = rectMarkForItem(rect, content, "element");
|
|
214
|
-
elementMarkContainer.addChild(graphics);
|
|
215
|
-
});
|
|
216
|
-
elementMarkContainer.visible = elementsVisible;
|
|
217
|
-
return {
|
|
218
|
-
highlightElementRects: highlightElementRects2
|
|
219
|
-
};
|
|
220
|
-
}, [
|
|
221
|
-
app,
|
|
222
|
-
appInitialed,
|
|
223
|
-
highlightElements,
|
|
224
|
-
context.tree,
|
|
225
|
-
hoverElement,
|
|
226
|
-
highlightRect,
|
|
227
|
-
highlightPoints
|
|
228
|
-
// bgVisible,
|
|
229
|
-
// elementsVisible,
|
|
230
|
-
]);
|
|
231
|
-
const onSetMarkerVisible = (e) => {
|
|
232
|
-
setMarkerVisible(e.target.checked);
|
|
233
|
-
if (pixiBgRef.current) {
|
|
234
|
-
pixiBgRef.current.visible = e.target.checked;
|
|
235
|
-
}
|
|
236
|
-
};
|
|
237
|
-
const onSetElementsVisible = (e) => {
|
|
238
|
-
setTextsVisible(e.target.checked);
|
|
239
|
-
elementMarkContainer.visible = e.target.checked;
|
|
240
|
-
};
|
|
241
|
-
let bottomTipA = null;
|
|
242
|
-
if (highlightElementRects.length === 1) {
|
|
243
|
-
bottomTipA = /* @__PURE__ */ jsx("div", { className: "bottom-tip", children: /* @__PURE__ */ jsxs("div", { className: "bottom-tip-item", children: [
|
|
244
|
-
"Element: ",
|
|
245
|
-
JSON.stringify(highlightElementRects[0])
|
|
246
|
-
] }) });
|
|
247
|
-
} else if (highlightElementRects.length > 1) {
|
|
248
|
-
bottomTipA = /* @__PURE__ */ jsx("div", { className: "bottom-tip", children: /* @__PURE__ */ jsxs("div", { className: "bottom-tip-item", children: [
|
|
249
|
-
"Element: ",
|
|
250
|
-
JSON.stringify(highlightElementRects)
|
|
251
|
-
] }) });
|
|
252
|
-
}
|
|
253
|
-
return /* @__PURE__ */ jsxs("div", { className: "blackboard", children: [
|
|
254
|
-
/* @__PURE__ */ jsx(
|
|
255
|
-
"div",
|
|
256
|
-
{
|
|
257
|
-
className: "blackboard-main-content",
|
|
258
|
-
style: { width: "100%" },
|
|
259
|
-
ref: domRef
|
|
260
|
-
}
|
|
261
|
-
),
|
|
262
|
-
/* @__PURE__ */ jsx(
|
|
263
|
-
"div",
|
|
264
|
-
{
|
|
265
|
-
className: "blackboard-filter",
|
|
266
|
-
style: { display: props.hideController ? "none" : "block" },
|
|
267
|
-
children: /* @__PURE__ */ jsx("div", { className: "overlay-control", children: /* @__PURE__ */ jsx(Checkbox, { checked: elementsVisible, onChange: onSetElementsVisible, children: "Elements" }) })
|
|
268
|
-
}
|
|
269
|
-
),
|
|
270
|
-
/* @__PURE__ */ jsx(
|
|
271
|
-
"div",
|
|
272
|
-
{
|
|
273
|
-
className: "bottom-tip",
|
|
274
|
-
style: { display: props.hideController ? "none" : "block" },
|
|
275
|
-
children: bottomTipA
|
|
276
|
-
}
|
|
277
|
-
)
|
|
278
|
-
] });
|
|
279
|
-
};
|
|
280
|
-
var blackboard_default = Blackboard;
|
|
281
|
-
export {
|
|
282
|
-
Blackboard,
|
|
283
|
-
blackboard_default as default,
|
|
284
|
-
pointMarkForItem,
|
|
285
|
-
rectMarkForItem
|
|
286
|
-
};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import Buffer from "buffer";
|
|
2
|
-
import processBrowser from "process/browser";
|
|
3
|
-
import console from "console-browserify";
|
|
4
|
-
var buffer = {
|
|
5
|
-
Buffer
|
|
6
|
-
};
|
|
7
|
-
const elementColor = ["#01204E"];
|
|
8
|
-
const highlightColorForSearchArea = "#028391";
|
|
9
|
-
const highlightColorForElement = "#fd5907";
|
|
10
|
-
function djb2Hash(str) {
|
|
11
|
-
if (!str) {
|
|
12
|
-
str = "unnamed";
|
|
13
|
-
}
|
|
14
|
-
let hash = 5381;
|
|
15
|
-
for (let i = 0; i < str.length; i++) {
|
|
16
|
-
hash = (hash << 5) + hash + str.charCodeAt(i);
|
|
17
|
-
}
|
|
18
|
-
return hash >>> 0;
|
|
19
|
-
}
|
|
20
|
-
function colorForName(name) {
|
|
21
|
-
const hashNumber = djb2Hash(name);
|
|
22
|
-
return elementColor[hashNumber % elementColor.length];
|
|
23
|
-
}
|
|
24
|
-
function highlightColorForType(type) {
|
|
25
|
-
if (type === "searchArea") {
|
|
26
|
-
return highlightColorForSearchArea;
|
|
27
|
-
}
|
|
28
|
-
return highlightColorForElement;
|
|
29
|
-
}
|
|
30
|
-
function globalThemeConfig() {
|
|
31
|
-
return {
|
|
32
|
-
token: {
|
|
33
|
-
colorPrimary: "#2B83FF"
|
|
34
|
-
},
|
|
35
|
-
components: {
|
|
36
|
-
Layout: {
|
|
37
|
-
headerHeight: 60,
|
|
38
|
-
headerPadding: "0 30px",
|
|
39
|
-
headerBg: "#FFF",
|
|
40
|
-
bodyBg: "#FFF"
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
export {
|
|
46
|
-
colorForName,
|
|
47
|
-
globalThemeConfig,
|
|
48
|
-
highlightColorForType
|
|
49
|
-
};
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __spreadValues = (a, b) => {
|
|
10
|
-
for (var prop in b || (b = {}))
|
|
11
|
-
if (__hasOwnProp.call(b, prop))
|
|
12
|
-
__defNormalProp(a, prop, b[prop]);
|
|
13
|
-
if (__getOwnPropSymbols)
|
|
14
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
-
if (__propIsEnum.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
}
|
|
18
|
-
return a;
|
|
19
|
-
};
|
|
20
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
-
var __async = (__this, __arguments, generator) => {
|
|
22
|
-
return new Promise((resolve, reject) => {
|
|
23
|
-
var fulfilled = (value) => {
|
|
24
|
-
try {
|
|
25
|
-
step(generator.next(value));
|
|
26
|
-
} catch (e) {
|
|
27
|
-
reject(e);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
var rejected = (value) => {
|
|
31
|
-
try {
|
|
32
|
-
step(generator.throw(value));
|
|
33
|
-
} catch (e) {
|
|
34
|
-
reject(e);
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
38
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
import Buffer2 from "buffer";
|
|
42
|
-
import processBrowser from "process/browser";
|
|
43
|
-
import console from "console-browserify";
|
|
44
|
-
var buffer = {
|
|
45
|
-
Buffer: Buffer2
|
|
46
|
-
};
|
|
47
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
48
|
-
import { useEffect, useRef, useState } from "react";
|
|
49
|
-
import { useStaticPageAgent } from "./playground/useStaticPageAgent";
|
|
50
|
-
import "./describer.css";
|
|
51
|
-
import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
|
|
52
|
-
import { Blackboard } from "./blackboard";
|
|
53
|
-
import { PlaygroundResultView } from "./playground/PlaygroundResult";
|
|
54
|
-
const Describer = (props) => {
|
|
55
|
-
var _a;
|
|
56
|
-
const { uiContext } = props;
|
|
57
|
-
const image = uiContext.screenshotBase64;
|
|
58
|
-
const canvasRef = useRef(null);
|
|
59
|
-
const [highlightPoints, setHighlightPoints] = useState(
|
|
60
|
-
[]
|
|
61
|
-
);
|
|
62
|
-
const [highlightRect, setHighlightRect] = useState();
|
|
63
|
-
const [error, setError] = useState();
|
|
64
|
-
const [loading, setLoading] = useState(false);
|
|
65
|
-
const [result, setResult] = useState();
|
|
66
|
-
const agent = useStaticPageAgent(uiContext);
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
const canvas = canvasRef.current;
|
|
69
|
-
if (!canvas || !image)
|
|
70
|
-
return;
|
|
71
|
-
const ctx = canvas.getContext("2d");
|
|
72
|
-
if (!ctx)
|
|
73
|
-
return;
|
|
74
|
-
const img = new Image();
|
|
75
|
-
img.onload = () => {
|
|
76
|
-
canvas.width = img.width;
|
|
77
|
-
canvas.height = img.height;
|
|
78
|
-
ctx.drawImage(img, 0, 0);
|
|
79
|
-
};
|
|
80
|
-
img.src = image;
|
|
81
|
-
}, [image]);
|
|
82
|
-
const handleClick = (position) => __async(void 0, null, function* () {
|
|
83
|
-
var _a2;
|
|
84
|
-
if (!agent) {
|
|
85
|
-
console.error("agent is not initialized");
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
setLoading(true);
|
|
89
|
-
setError(void 0);
|
|
90
|
-
setResult(void 0);
|
|
91
|
-
setHighlightPoints([]);
|
|
92
|
-
setHighlightRect(void 0);
|
|
93
|
-
try {
|
|
94
|
-
const userLocation = [position[0], position[1]];
|
|
95
|
-
setHighlightPoints([userLocation]);
|
|
96
|
-
const result2 = yield agent == null ? void 0 : agent.describeElementAtPoint(userLocation);
|
|
97
|
-
console.log("describe result", result2);
|
|
98
|
-
setResult(result2);
|
|
99
|
-
if ((_a2 = result2.verifyResult) == null ? void 0 : _a2.rect) {
|
|
100
|
-
setHighlightRect(result2.verifyResult.rect);
|
|
101
|
-
}
|
|
102
|
-
} catch (error2) {
|
|
103
|
-
setError(error2.message);
|
|
104
|
-
} finally {
|
|
105
|
-
setLoading(false);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
let resultText = "";
|
|
109
|
-
if (error) {
|
|
110
|
-
resultText = error;
|
|
111
|
-
} else if (result && !((_a = result.verifyResult) == null ? void 0 : _a.pass)) {
|
|
112
|
-
resultText = `Locate failed with prompt: ${result.prompt}`;
|
|
113
|
-
} else if (result) {
|
|
114
|
-
if (result.deepThink) {
|
|
115
|
-
resultText = `Deep think: ${result.prompt}`;
|
|
116
|
-
} else {
|
|
117
|
-
resultText = result.prompt;
|
|
118
|
-
}
|
|
119
|
-
} else if (loading) {
|
|
120
|
-
resultText = "Loading...";
|
|
121
|
-
}
|
|
122
|
-
return /* @__PURE__ */ jsx("div", { className: "image-describer", children: /* @__PURE__ */ jsxs(PanelGroup, { autoSaveId: "describer-layout", direction: "horizontal", children: [
|
|
123
|
-
/* @__PURE__ */ jsx(
|
|
124
|
-
Panel,
|
|
125
|
-
{
|
|
126
|
-
defaultSize: 32,
|
|
127
|
-
maxSize: 60,
|
|
128
|
-
minSize: 20,
|
|
129
|
-
style: { paddingRight: "24px" },
|
|
130
|
-
children: /* @__PURE__ */ jsxs("div", { className: "form-part context-panel", children: [
|
|
131
|
-
/* @__PURE__ */ jsx("h3", { children: "Screenshot" }),
|
|
132
|
-
/* @__PURE__ */ jsx("div", { className: "form-sub-title", children: "Click on the screenshot, Midscene will help you describe the element at the clicked point." }),
|
|
133
|
-
/* @__PURE__ */ jsx(
|
|
134
|
-
Blackboard,
|
|
135
|
-
{
|
|
136
|
-
uiContext: __spreadProps(__spreadValues({}, uiContext), {
|
|
137
|
-
tree: {
|
|
138
|
-
node: null,
|
|
139
|
-
children: []
|
|
140
|
-
}
|
|
141
|
-
}),
|
|
142
|
-
highlightPoints,
|
|
143
|
-
highlightRect,
|
|
144
|
-
onCanvasClick: handleClick,
|
|
145
|
-
hideController: true
|
|
146
|
-
}
|
|
147
|
-
)
|
|
148
|
-
] })
|
|
149
|
-
}
|
|
150
|
-
),
|
|
151
|
-
/* @__PURE__ */ jsx(PanelResizeHandle, { className: "panel-resize-handle" }),
|
|
152
|
-
/* @__PURE__ */ jsx(Panel, { children: /* @__PURE__ */ jsx(
|
|
153
|
-
PlaygroundResultView,
|
|
154
|
-
{
|
|
155
|
-
result: {
|
|
156
|
-
result: resultText,
|
|
157
|
-
error: error || null
|
|
158
|
-
},
|
|
159
|
-
loading,
|
|
160
|
-
serverValid: true,
|
|
161
|
-
serviceMode: "In-Browser",
|
|
162
|
-
replayScriptsInfo: null,
|
|
163
|
-
replayCounter: 0,
|
|
164
|
-
loadingProgressText: ""
|
|
165
|
-
}
|
|
166
|
-
) })
|
|
167
|
-
] }) });
|
|
168
|
-
};
|
|
169
|
-
var describer_default = Describer;
|
|
170
|
-
export {
|
|
171
|
-
Describer,
|
|
172
|
-
describer_default as default
|
|
173
|
-
};
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import Buffer from "buffer";
|
|
2
|
-
import processBrowser from "process/browser";
|
|
3
|
-
import console from "console-browserify";
|
|
4
|
-
var buffer = {
|
|
5
|
-
Buffer
|
|
6
|
-
};
|
|
7
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
-
import { SettingOutlined } from "@ant-design/icons";
|
|
9
|
-
import { Input, Modal, Tooltip } from "antd";
|
|
10
|
-
import { useEffect, useRef, useState } from "react";
|
|
11
|
-
import { useEnvConfig } from "./store/store";
|
|
12
|
-
function EnvConfig({
|
|
13
|
-
showTooltipWhenEmpty = true,
|
|
14
|
-
showModelName = true,
|
|
15
|
-
tooltipPlacement = "bottom",
|
|
16
|
-
mode = "icon"
|
|
17
|
-
}) {
|
|
18
|
-
const { config, configString, loadConfig, syncFromStorage } = useEnvConfig();
|
|
19
|
-
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
20
|
-
const [tempConfigString, setTempConfigString] = useState(configString);
|
|
21
|
-
const midsceneModelName = config.MIDSCENE_MODEL_NAME;
|
|
22
|
-
const componentRef = useRef(null);
|
|
23
|
-
const showModal = (e) => {
|
|
24
|
-
syncFromStorage();
|
|
25
|
-
setIsModalOpen(true);
|
|
26
|
-
e.preventDefault();
|
|
27
|
-
e.stopPropagation();
|
|
28
|
-
};
|
|
29
|
-
const handleOk = () => {
|
|
30
|
-
setIsModalOpen(false);
|
|
31
|
-
loadConfig(tempConfigString);
|
|
32
|
-
};
|
|
33
|
-
const handleCancel = () => {
|
|
34
|
-
setIsModalOpen(false);
|
|
35
|
-
};
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
if (isModalOpen) {
|
|
38
|
-
setTempConfigString(configString);
|
|
39
|
-
}
|
|
40
|
-
}, [isModalOpen, configString]);
|
|
41
|
-
return /* @__PURE__ */ jsxs(
|
|
42
|
-
"div",
|
|
43
|
-
{
|
|
44
|
-
style: {
|
|
45
|
-
display: "flex",
|
|
46
|
-
justifyContent: "flex-end",
|
|
47
|
-
gap: "10px",
|
|
48
|
-
alignItems: "center",
|
|
49
|
-
height: "100%",
|
|
50
|
-
minHeight: "32px"
|
|
51
|
-
},
|
|
52
|
-
ref: componentRef,
|
|
53
|
-
children: [
|
|
54
|
-
showModelName ? midsceneModelName : null,
|
|
55
|
-
/* @__PURE__ */ jsx(
|
|
56
|
-
Tooltip,
|
|
57
|
-
{
|
|
58
|
-
title: "Please set up your environment variables before using.",
|
|
59
|
-
placement: tooltipPlacement,
|
|
60
|
-
align: { offset: [-10, 5] },
|
|
61
|
-
getPopupContainer: () => componentRef.current,
|
|
62
|
-
open: (
|
|
63
|
-
// undefined for default behavior of tooltip, hover for show
|
|
64
|
-
// close tooltip when modal is open
|
|
65
|
-
isModalOpen ? false : showTooltipWhenEmpty ? Object.keys(config).length === 0 : void 0
|
|
66
|
-
),
|
|
67
|
-
children: mode === "icon" ? /* @__PURE__ */ jsx(SettingOutlined, { onClick: showModal }) : /* @__PURE__ */ jsx(
|
|
68
|
-
"span",
|
|
69
|
-
{
|
|
70
|
-
onClick: showModal,
|
|
71
|
-
style: { color: "#006AFF", cursor: "pointer" },
|
|
72
|
-
children: "set up"
|
|
73
|
-
}
|
|
74
|
-
)
|
|
75
|
-
}
|
|
76
|
-
),
|
|
77
|
-
/* @__PURE__ */ jsxs(
|
|
78
|
-
Modal,
|
|
79
|
-
{
|
|
80
|
-
title: "Model Env Config",
|
|
81
|
-
open: isModalOpen,
|
|
82
|
-
onOk: handleOk,
|
|
83
|
-
onCancel: handleCancel,
|
|
84
|
-
okText: "Save",
|
|
85
|
-
style: { width: "800px", height: "100%", marginTop: "10%" },
|
|
86
|
-
destroyOnClose: true,
|
|
87
|
-
maskClosable: true,
|
|
88
|
-
centered: true,
|
|
89
|
-
children: [
|
|
90
|
-
/* @__PURE__ */ jsx(
|
|
91
|
-
Input.TextArea,
|
|
92
|
-
{
|
|
93
|
-
rows: 7,
|
|
94
|
-
placeholder: "OPENAI_API_KEY=sk-...\nMIDSCENE_MODEL_NAME=gpt-4o-2024-08-06\n...",
|
|
95
|
-
value: tempConfigString,
|
|
96
|
-
onChange: (e) => setTempConfigString(e.target.value),
|
|
97
|
-
style: { whiteSpace: "nowrap", wordWrap: "break-word" }
|
|
98
|
-
}
|
|
99
|
-
),
|
|
100
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
101
|
-
/* @__PURE__ */ jsx("p", { children: "The format is KEY=VALUE and separated by new lines." }),
|
|
102
|
-
/* @__PURE__ */ jsxs("p", { children: [
|
|
103
|
-
"These data will be saved ",
|
|
104
|
-
/* @__PURE__ */ jsx("strong", { children: "locally in your browser" }),
|
|
105
|
-
"."
|
|
106
|
-
] })
|
|
107
|
-
] })
|
|
108
|
-
]
|
|
109
|
-
}
|
|
110
|
-
)
|
|
111
|
-
]
|
|
112
|
-
}
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
export {
|
|
116
|
-
EnvConfig
|
|
117
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import Buffer from "buffer";
|
|
2
|
-
import processBrowser from "process/browser";
|
|
3
|
-
import console from "console-browserify";
|
|
4
|
-
var buffer = {
|
|
5
|
-
Buffer
|
|
6
|
-
};
|
|
7
|
-
import { jsx } from "react/jsx-runtime";
|
|
8
|
-
import "./github-star.css";
|
|
9
|
-
const GithubStar = () => {
|
|
10
|
-
return /* @__PURE__ */ jsx(
|
|
11
|
-
"a",
|
|
12
|
-
{
|
|
13
|
-
href: "https://github.com/web-infra-dev/midscene",
|
|
14
|
-
target: "_blank",
|
|
15
|
-
rel: "noreferrer",
|
|
16
|
-
style: { display: "flex", alignItems: "center" },
|
|
17
|
-
children: /* @__PURE__ */ jsx(
|
|
18
|
-
"img",
|
|
19
|
-
{
|
|
20
|
-
className: "github-star",
|
|
21
|
-
src: "https://img.shields.io/github/stars/web-infra-dev/midscene?style=social",
|
|
22
|
-
alt: "Github star",
|
|
23
|
-
style: { display: "block" }
|
|
24
|
-
}
|
|
25
|
-
)
|
|
26
|
-
}
|
|
27
|
-
);
|
|
28
|
-
};
|
|
29
|
-
export {
|
|
30
|
-
GithubStar
|
|
31
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import Buffer from "buffer";
|
|
2
|
-
import processBrowser from "process/browser";
|
|
3
|
-
import console from "console-browserify";
|
|
4
|
-
var buffer = {
|
|
5
|
-
Buffer
|
|
6
|
-
};
|
|
7
|
-
import { jsx } from "react/jsx-runtime";
|
|
8
|
-
import "./logo.css";
|
|
9
|
-
const LogoUrl = "https://lf3-static.bytednsdoc.com/obj/eden-cn/vhaeh7vhabf/Midscene.png";
|
|
10
|
-
const Logo = ({ hideLogo = false }) => {
|
|
11
|
-
if (hideLogo) {
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
return /* @__PURE__ */ jsx("div", { className: "logo", children: /* @__PURE__ */ jsx("a", { href: "https://midscenejs.com/", target: "_blank", rel: "noreferrer", children: /* @__PURE__ */ jsx(
|
|
15
|
-
"img",
|
|
16
|
-
{
|
|
17
|
-
alt: "Midscene_logo",
|
|
18
|
-
src: "https://lf3-static.bytednsdoc.com/obj/eden-cn/vhaeh7vhabf/Midscene.png"
|
|
19
|
-
}
|
|
20
|
-
) }) });
|
|
21
|
-
};
|
|
22
|
-
export {
|
|
23
|
-
Logo,
|
|
24
|
-
LogoUrl
|
|
25
|
-
};
|