@midscene/visualizer 0.26.2-beta-20250812091127.0 → 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.
Files changed (124) hide show
  1. package/dist/es/blank_polyfill.mjs +2 -0
  2. package/dist/es/component/blackboard.css +12 -5
  3. package/dist/es/component/blackboard.mjs +266 -0
  4. package/dist/es/component/color.mjs +35 -0
  5. package/dist/es/component/describer.css +9 -5
  6. package/dist/es/component/describer.mjs +128 -0
  7. package/dist/es/component/env-config.mjs +112 -0
  8. package/dist/es/component/github-star.css +1 -0
  9. package/dist/es/component/github-star.mjs +20 -0
  10. package/dist/es/component/logo.css +5 -3
  11. package/dist/es/component/logo.mjs +20 -0
  12. package/dist/es/component/misc.mjs +54 -0
  13. package/dist/es/component/pixi-loader.mjs +16 -0
  14. package/dist/es/component/player.css +88 -70
  15. package/dist/es/component/player.mjs +628 -0
  16. package/dist/es/component/playground/ConfigSelector.mjs +53 -0
  17. package/dist/es/component/playground/ContextPreview.mjs +39 -0
  18. package/dist/es/component/playground/HistorySelector.mjs +193 -0
  19. package/dist/es/component/playground/PlaygroundResult.mjs +60 -0
  20. package/dist/es/component/playground/PromptInput.mjs +225 -0
  21. package/dist/es/component/playground/ServiceModeControl.mjs +100 -0
  22. package/dist/es/component/playground/index.css +140 -98
  23. package/dist/es/component/playground/playground-constants.mjs +45 -0
  24. package/dist/es/component/playground/playground-utils.mjs +89 -0
  25. package/dist/es/component/playground/useServerValid.mjs +27 -0
  26. package/dist/es/component/playground/useStaticPageAgent.mjs +12 -0
  27. package/dist/es/component/replay-scripts.mjs +271 -0
  28. package/dist/es/component/shiny-text.css +33 -22
  29. package/dist/es/component/shiny-text.mjs +15 -0
  30. package/dist/es/component/store/history.mjs +55 -0
  31. package/dist/es/component/store/store.mjs +128 -0
  32. package/dist/es/icons/close.mjs +19 -0
  33. package/dist/es/icons/history.mjs +30 -0
  34. package/dist/es/icons/magnifying-glass.mjs +39 -0
  35. package/dist/es/icons/setting.mjs +20 -0
  36. package/dist/es/index.mjs +21 -0
  37. package/dist/es/init.mjs +10 -0
  38. package/dist/es/{utils.js → utils.mjs} +51 -75
  39. package/dist/lib/blank_polyfill.js +34 -38
  40. package/dist/lib/component/blackboard.css +12 -5
  41. package/dist/lib/component/blackboard.js +293 -306
  42. package/dist/lib/component/color.js +64 -74
  43. package/dist/lib/component/describer.css +9 -5
  44. package/dist/lib/component/describer.js +158 -198
  45. package/dist/lib/component/env-config.js +142 -147
  46. package/dist/lib/component/github-star.css +1 -0
  47. package/dist/lib/component/github-star.js +51 -62
  48. package/dist/lib/component/logo.css +5 -3
  49. package/dist/lib/component/logo.js +53 -56
  50. package/dist/lib/component/misc.js +85 -84
  51. package/dist/lib/component/pixi-loader.js +49 -80
  52. package/dist/lib/component/player.css +88 -70
  53. package/dist/lib/component/player.js +627 -738
  54. package/dist/lib/component/playground/ConfigSelector.js +91 -92
  55. package/dist/lib/component/playground/ContextPreview.js +80 -72
  56. package/dist/lib/component/playground/HistorySelector.js +234 -197
  57. package/dist/lib/component/playground/PlaygroundResult.js +100 -103
  58. package/dist/lib/component/playground/PromptInput.js +250 -237
  59. package/dist/lib/component/playground/ServiceModeControl.js +124 -124
  60. package/dist/lib/component/playground/index.css +140 -98
  61. package/dist/lib/component/playground/playground-constants.js +97 -73
  62. package/dist/lib/component/playground/playground-types.js +17 -31
  63. package/dist/lib/component/playground/playground-utils.js +140 -168
  64. package/dist/lib/component/playground/useServerValid.js +55 -86
  65. package/dist/lib/component/playground/useStaticPageAgent.js +45 -51
  66. package/dist/lib/component/replay-scripts.js +291 -373
  67. package/dist/lib/component/shiny-text.css +33 -22
  68. package/dist/lib/component/shiny-text.js +46 -57
  69. package/dist/lib/component/store/history.js +58 -64
  70. package/dist/lib/component/store/store.js +132 -128
  71. package/dist/lib/icons/close.js +53 -0
  72. package/dist/lib/icons/history.js +64 -0
  73. package/dist/lib/icons/magnifying-glass.js +73 -0
  74. package/dist/lib/icons/setting.js +54 -0
  75. package/dist/lib/index.js +158 -124
  76. package/dist/lib/init.js +39 -46
  77. package/dist/lib/utils.js +105 -109
  78. package/dist/types/blank_polyfill.d.ts +2 -2
  79. package/dist/types/component/playground/ConfigSelector.d.ts +1 -0
  80. package/dist/types/component/playground/ContextPreview.d.ts +1 -0
  81. package/dist/types/component/playground/HistorySelector.d.ts +1 -0
  82. package/dist/types/component/playground/PlaygroundResult.d.ts +1 -0
  83. package/dist/types/component/playground/PromptInput.d.ts +1 -0
  84. package/dist/types/component/playground/ServiceModeControl.d.ts +1 -0
  85. package/package.json +16 -18
  86. package/dist/es/assets/close.909351c0.svg +0 -4
  87. package/dist/es/assets/history.164a4eab.svg +0 -4
  88. package/dist/es/assets/magnifying-glass.9498e70e.svg +0 -12
  89. package/dist/es/assets/setting.80ab7285.svg +0 -11
  90. package/dist/es/blank_polyfill.js +0 -10
  91. package/dist/es/component/blackboard.js +0 -286
  92. package/dist/es/component/color.js +0 -49
  93. package/dist/es/component/describer.js +0 -173
  94. package/dist/es/component/env-config.js +0 -117
  95. package/dist/es/component/github-star.js +0 -31
  96. package/dist/es/component/logo.js +0 -25
  97. package/dist/es/component/misc.js +0 -63
  98. package/dist/es/component/pixi-loader.js +0 -51
  99. package/dist/es/component/player.js +0 -746
  100. package/dist/es/component/playground/ConfigSelector.js +0 -64
  101. package/dist/es/component/playground/ContextPreview.js +0 -42
  102. package/dist/es/component/playground/HistorySelector.js +0 -168
  103. package/dist/es/component/playground/PlaygroundResult.js +0 -73
  104. package/dist/es/component/playground/PromptInput.js +0 -212
  105. package/dist/es/component/playground/ServiceModeControl.js +0 -100
  106. package/dist/es/component/playground/playground-constants.js +0 -39
  107. package/dist/es/component/playground/playground-types.js +0 -6
  108. package/dist/es/component/playground/playground-utils.js +0 -141
  109. package/dist/es/component/playground/useServerValid.js +0 -58
  110. package/dist/es/component/playground/useStaticPageAgent.js +0 -20
  111. package/dist/es/component/replay-scripts.js +0 -361
  112. package/dist/es/component/shiny-text.js +0 -30
  113. package/dist/es/component/store/history.js +0 -34
  114. package/dist/es/component/store/store.js +0 -99
  115. package/dist/es/index.js +0 -79
  116. package/dist/es/init.js +0 -17
  117. package/dist/index.css +0 -595
  118. package/dist/index.js +0 -1
  119. package/dist/lib/assets/close.909351c0.svg +0 -4
  120. package/dist/lib/assets/history.164a4eab.svg +0 -4
  121. package/dist/lib/assets/magnifying-glass.9498e70e.svg +0 -12
  122. package/dist/lib/assets/setting.80ab7285.svg +0 -11
  123. package/dist/lib/component/common.css +0 -0
  124. /package/dist/es/component/{common.css → playground/playground-types.mjs} +0 -0
@@ -1,322 +1,309 @@
1
+ 'use client';
1
2
  "use strict";
2
- "use client";
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __export = (target, all) => {
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
12
- };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
- }
19
- return to;
20
- };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
- var __async = (__this, __arguments, generator) => {
31
- return new Promise((resolve, reject) => {
32
- var fulfilled = (value) => {
33
- try {
34
- step(generator.next(value));
35
- } catch (e) {
36
- reject(e);
37
- }
3
+ var __webpack_require__ = {};
4
+ (()=>{
5
+ __webpack_require__.d = (exports1, definition)=>{
6
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ get: definition[key]
9
+ });
38
10
  };
39
- var rejected = (value) => {
40
- try {
41
- step(generator.throw(value));
42
- } catch (e) {
43
- reject(e);
44
- }
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.r = (exports1)=>{
17
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
18
+ value: 'Module'
19
+ });
20
+ Object.defineProperty(exports1, '__esModule', {
21
+ value: true
22
+ });
45
23
  };
46
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
47
- step((generator = generator.apply(__this, __arguments)).next());
48
- });
49
- };
50
- var blackboard_exports = {};
51
- __export(blackboard_exports, {
52
- Blackboard: () => Blackboard,
53
- default: () => blackboard_default,
54
- pointMarkForItem: () => pointMarkForItem,
55
- rectMarkForItem: () => rectMarkForItem
24
+ })();
25
+ var __webpack_exports__ = {};
26
+ __webpack_require__.r(__webpack_exports__);
27
+ __webpack_require__.d(__webpack_exports__, {
28
+ pointMarkForItem: ()=>pointMarkForItem,
29
+ default: ()=>blackboard,
30
+ Blackboard: ()=>Blackboard,
31
+ rectMarkForItem: ()=>rectMarkForItem
56
32
  });
57
- module.exports = __toCommonJS(blackboard_exports);
58
- var import_buffer = __toESM(require("buffer"));
59
- var import_browser = __toESM(require("process/browser"));
60
- var import_console_browserify = __toESM(require("console-browserify"));
61
- var buffer = {
62
- Buffer: import_buffer.default
63
- };
64
- var import_jsx_runtime = require("react/jsx-runtime");
65
- var import_unsafe_eval = require("pixi.js/unsafe-eval");
66
- var import_antd = require("antd");
67
- var PIXI = __toESM(require("pixi.js"));
68
- var import_react = require("react");
69
- var import_color = require("./color");
70
- var import_blackboard = require("./blackboard.css");
71
- var import_extractor = require("@midscene/shared/extractor");
72
- var import_pixi_filters = require("pixi-filters");
73
- var import_store = require("./store/store");
33
+ const jsx_runtime_namespaceObject = require("react/jsx-runtime");
34
+ require("pixi.js/unsafe-eval");
35
+ const external_antd_namespaceObject = require("antd");
36
+ const external_pixi_js_namespaceObject = require("pixi.js");
37
+ const external_react_namespaceObject = require("react");
38
+ const external_color_js_namespaceObject = require("./color.js");
39
+ require("./blackboard.css");
40
+ const extractor_namespaceObject = require("@midscene/shared/extractor");
41
+ const external_pixi_filters_namespaceObject = require("pixi-filters");
42
+ const store_js_namespaceObject = require("./store/store.js");
74
43
  const itemFillAlpha = 0.4;
75
44
  const highlightAlpha = 0.4;
76
45
  const pointRadius = 10;
77
- const pointMarkForItem = (point, type) => {
78
- const [x, y] = point;
79
- const themeColor = (0, import_color.highlightColorForType)("element");
80
- const graphics = new PIXI.Graphics();
81
- graphics.beginFill(themeColor, itemFillAlpha);
82
- graphics.drawCircle(x, y, pointRadius);
83
- graphics.endFill();
84
- return graphics;
46
+ const pointMarkForItem = (point, type)=>{
47
+ const [x, y] = point;
48
+ const themeColor = (0, external_color_js_namespaceObject.highlightColorForType)('element');
49
+ const graphics = new external_pixi_js_namespaceObject.Graphics();
50
+ graphics.beginFill(themeColor, itemFillAlpha);
51
+ graphics.drawCircle(x, y, pointRadius);
52
+ graphics.endFill();
53
+ return graphics;
85
54
  };
86
- const rectMarkForItem = (rect, name, type) => {
87
- const { left, top, width, height } = rect;
88
- let themeColor;
89
- if (type === "element") {
90
- themeColor = (0, import_color.colorForName)(name);
91
- } else if (type === "searchArea") {
92
- themeColor = (0, import_color.highlightColorForType)("searchArea");
93
- } else {
94
- themeColor = (0, import_color.highlightColorForType)("element");
95
- }
96
- const alpha = type === "highlight" ? highlightAlpha : itemFillAlpha;
97
- const graphics = new PIXI.Graphics();
98
- graphics.beginFill(themeColor, alpha);
99
- graphics.lineStyle(1, themeColor, 1);
100
- graphics.drawRect(left, top, width, height);
101
- graphics.endFill();
102
- const dropShadowFilter = new import_pixi_filters.DropShadowFilter({
103
- blur: 2,
104
- quality: 3,
105
- alpha: 0.4,
106
- offset: { x: 4, y: 4 },
107
- color: 3355443
108
- });
109
- graphics.filters = [dropShadowFilter];
110
- const nameFontSize = 18;
111
- if (!name) {
112
- return [graphics];
113
- }
114
- const texts = new PIXI.Text(name, {
115
- fontSize: nameFontSize,
116
- fill: 0
117
- });
118
- texts.x = left;
119
- texts.y = Math.max(top - (nameFontSize + 4), 0);
120
- return [graphics, texts];
55
+ const rectMarkForItem = (rect, name, type)=>{
56
+ const { left, top, width, height } = rect;
57
+ let themeColor;
58
+ themeColor = 'element' === type ? (0, external_color_js_namespaceObject.colorForName)(name) : 'searchArea' === type ? (0, external_color_js_namespaceObject.highlightColorForType)('searchArea') : (0, external_color_js_namespaceObject.highlightColorForType)('element');
59
+ const alpha = 'highlight' === type ? highlightAlpha : itemFillAlpha;
60
+ const graphics = new external_pixi_js_namespaceObject.Graphics();
61
+ graphics.beginFill(themeColor, alpha);
62
+ graphics.lineStyle(1, themeColor, 1);
63
+ graphics.drawRect(left, top, width, height);
64
+ graphics.endFill();
65
+ const dropShadowFilter = new external_pixi_filters_namespaceObject.DropShadowFilter({
66
+ blur: 2,
67
+ quality: 3,
68
+ alpha: 0.4,
69
+ offset: {
70
+ x: 4,
71
+ y: 4
72
+ },
73
+ color: 0x333333
74
+ });
75
+ graphics.filters = [
76
+ dropShadowFilter
77
+ ];
78
+ const nameFontSize = 18;
79
+ if (!name) return [
80
+ graphics
81
+ ];
82
+ const texts = new external_pixi_js_namespaceObject.Text(name, {
83
+ fontSize: nameFontSize,
84
+ fill: 0x0
85
+ });
86
+ texts.x = left;
87
+ texts.y = Math.max(top - (nameFontSize + 4), 0);
88
+ return [
89
+ graphics,
90
+ texts
91
+ ];
121
92
  };
122
- const Blackboard = (props) => {
123
- const highlightElements = props.highlightElements || [];
124
- const highlightIds = highlightElements.map((e) => e.id);
125
- const highlightRect = props.highlightRect;
126
- const highlightPoints = props.highlightPoints;
127
- const context = props.uiContext;
128
- const { size, screenshotBase64 } = context;
129
- const screenWidth = size.width;
130
- const screenHeight = size.height;
131
- const domRef = (0, import_react.useRef)(null);
132
- const app = (0, import_react.useMemo)(() => new PIXI.Application(), []);
133
- const [appInitialed, setAppInitialed] = (0, import_react.useState)(false);
134
- const highlightContainer = (0, import_react.useMemo)(() => new PIXI.Container(), []);
135
- const elementMarkContainer = (0, import_react.useMemo)(() => new PIXI.Container(), []);
136
- const [hoverElement, setHoverElement] = (0, import_react.useState)(null);
137
- const pixiBgRef = (0, import_react.useRef)(void 0);
138
- const { markerVisible, setMarkerVisible, elementsVisible, setTextsVisible } = (0, import_store.useBlackboardPreference)();
139
- (0, import_react.useEffect)(() => {
140
- Promise.resolve(
141
- (() => __async(void 0, null, function* () {
142
- if (!domRef.current || !screenWidth) {
143
- return;
93
+ const Blackboard = (props)=>{
94
+ const highlightElements = props.highlightElements || [];
95
+ const highlightIds = highlightElements.map((e)=>e.id);
96
+ const highlightRect = props.highlightRect;
97
+ const highlightPoints = props.highlightPoints;
98
+ const context = props.uiContext;
99
+ const { size, screenshotBase64 } = context;
100
+ const screenWidth = size.width;
101
+ const screenHeight = size.height;
102
+ const domRef = (0, external_react_namespaceObject.useRef)(null);
103
+ const app = (0, external_react_namespaceObject.useMemo)(()=>new external_pixi_js_namespaceObject.Application(), []);
104
+ const [appInitialed, setAppInitialed] = (0, external_react_namespaceObject.useState)(false);
105
+ const highlightContainer = (0, external_react_namespaceObject.useMemo)(()=>new external_pixi_js_namespaceObject.Container(), []);
106
+ const elementMarkContainer = (0, external_react_namespaceObject.useMemo)(()=>new external_pixi_js_namespaceObject.Container(), []);
107
+ const [hoverElement, setHoverElement] = (0, external_react_namespaceObject.useState)(null);
108
+ const pixiBgRef = (0, external_react_namespaceObject.useRef)(void 0);
109
+ const { markerVisible, setMarkerVisible, elementsVisible, setTextsVisible } = (0, store_js_namespaceObject.useBlackboardPreference)();
110
+ (0, external_react_namespaceObject.useEffect)(()=>{
111
+ Promise.resolve((async ()=>{
112
+ if (!domRef.current || !screenWidth) return;
113
+ await app.init({
114
+ width: screenWidth,
115
+ height: screenHeight,
116
+ background: 0xffffff
117
+ });
118
+ const canvasEl = domRef.current;
119
+ domRef.current.appendChild(app.canvas);
120
+ const { clientWidth } = domRef.current.parentElement;
121
+ const targetHeight = 0.6 * window.innerHeight;
122
+ const viewportRatio = clientWidth / targetHeight;
123
+ if (screenWidth / screenHeight <= viewportRatio) {
124
+ const ratio = targetHeight / screenHeight;
125
+ canvasEl.style.width = `${Math.floor(screenWidth * ratio)}px`;
126
+ canvasEl.style.height = `${Math.floor(screenHeight * ratio)}px`;
127
+ }
128
+ app.stage.addChild(highlightContainer);
129
+ app.stage.addChild(elementMarkContainer);
130
+ setAppInitialed(true);
131
+ })());
132
+ return ()=>{
133
+ console.log('will destroy');
134
+ try {
135
+ app.destroy(true, {
136
+ children: true,
137
+ texture: true
138
+ });
139
+ } catch (e) {
140
+ console.warn('destroy failed', e);
141
+ }
142
+ };
143
+ }, [
144
+ app,
145
+ screenWidth,
146
+ screenHeight
147
+ ]);
148
+ (0, external_react_namespaceObject.useEffect)(()=>{
149
+ if (!appInitialed) return;
150
+ app.stage.eventMode = 'static';
151
+ app.stage.hitArea = new external_pixi_js_namespaceObject.Rectangle(0, 0, screenWidth, screenHeight);
152
+ const clickHandler = (event)=>{
153
+ var _props_onCanvasClick;
154
+ console.log('pixi click', event);
155
+ const { x, y } = event.data.global;
156
+ null == (_props_onCanvasClick = props.onCanvasClick) || _props_onCanvasClick.call(props, [
157
+ Math.round(x),
158
+ Math.round(y)
159
+ ]);
160
+ };
161
+ app.stage.on('click', clickHandler);
162
+ return ()=>{
163
+ var _app_stage;
164
+ null == app || null == (_app_stage = app.stage) || _app_stage.off('click');
165
+ };
166
+ }, [
167
+ appInitialed,
168
+ props.onCanvasClick,
169
+ screenWidth,
170
+ screenHeight
171
+ ]);
172
+ (0, external_react_namespaceObject.useEffect)(()=>{
173
+ if (!appInitialed) return;
174
+ const img = new Image();
175
+ img.onload = ()=>{
176
+ if (!app.stage) return;
177
+ const screenshotTexture = external_pixi_js_namespaceObject.Texture.from(img);
178
+ const backgroundSprite = new external_pixi_js_namespaceObject.Sprite(screenshotTexture);
179
+ backgroundSprite.x = 0;
180
+ backgroundSprite.y = 0;
181
+ backgroundSprite.width = screenWidth;
182
+ backgroundSprite.height = screenHeight;
183
+ backgroundSprite.eventMode = 'passive';
184
+ app.stage.addChildAt(backgroundSprite, 0);
185
+ pixiBgRef.current = backgroundSprite;
186
+ };
187
+ img.onerror = (e)=>{
188
+ console.error('load screenshot failed', e);
189
+ };
190
+ img.src = screenshotBase64;
191
+ }, [
192
+ app.stage,
193
+ appInitialed,
194
+ screenWidth,
195
+ screenHeight
196
+ ]);
197
+ const { highlightElementRects } = (0, external_react_namespaceObject.useMemo)(()=>{
198
+ const highlightElementRects = [];
199
+ highlightContainer.removeChildren();
200
+ elementMarkContainer.removeChildren();
201
+ highlightContainer.eventMode = 'passive';
202
+ elementMarkContainer.eventMode = 'passive';
203
+ if (highlightRect) {
204
+ const [graphics] = rectMarkForItem(highlightRect, 'Search Area', 'searchArea');
205
+ highlightContainer.addChild(graphics);
144
206
  }
145
- yield app.init({
146
- width: screenWidth,
147
- height: screenHeight,
148
- background: 16777215
207
+ if (highlightElements.length) highlightElements.forEach((element)=>{
208
+ const { rect, content, id } = element;
209
+ const [graphics] = rectMarkForItem(rect, content, 'highlight');
210
+ highlightContainer.addChild(graphics);
149
211
  });
150
- const canvasEl = domRef.current;
151
- domRef.current.appendChild(app.canvas);
152
- const { clientWidth } = domRef.current.parentElement;
153
- const targetHeight = window.innerHeight * 0.6;
154
- const viewportRatio = clientWidth / targetHeight;
155
- if (screenWidth / screenHeight <= viewportRatio) {
156
- const ratio = targetHeight / screenHeight;
157
- canvasEl.style.width = `${Math.floor(screenWidth * ratio)}px`;
158
- canvasEl.style.height = `${Math.floor(screenHeight * ratio)}px`;
159
- }
160
- app.stage.addChild(highlightContainer);
161
- app.stage.addChild(elementMarkContainer);
162
- setAppInitialed(true);
163
- }))()
164
- );
165
- return () => {
166
- import_console_browserify.default.log("will destroy");
167
- try {
168
- app.destroy(true, { children: true, texture: true });
169
- } catch (e) {
170
- import_console_browserify.default.warn("destroy failed", e);
171
- }
172
- };
173
- }, [app, screenWidth, screenHeight]);
174
- (0, import_react.useEffect)(() => {
175
- if (!appInitialed) {
176
- return;
177
- }
178
- app.stage.eventMode = "static";
179
- app.stage.hitArea = new PIXI.Rectangle(0, 0, screenWidth, screenHeight);
180
- const clickHandler = (event) => {
181
- var _a;
182
- import_console_browserify.default.log("pixi click", event);
183
- const { x, y } = event.data.global;
184
- (_a = props.onCanvasClick) == null ? void 0 : _a.call(props, [Math.round(x), Math.round(y)]);
185
- };
186
- app.stage.on("click", clickHandler);
187
- return () => {
188
- var _a;
189
- (_a = app == null ? void 0 : app.stage) == null ? void 0 : _a.off("click");
190
- };
191
- }, [appInitialed, props.onCanvasClick, screenWidth, screenHeight]);
192
- (0, import_react.useEffect)(() => {
193
- if (!appInitialed) {
194
- return;
195
- }
196
- const img = new Image();
197
- img.onload = () => {
198
- if (!app.stage)
199
- return;
200
- const screenshotTexture = PIXI.Texture.from(img);
201
- const backgroundSprite = new PIXI.Sprite(screenshotTexture);
202
- backgroundSprite.x = 0;
203
- backgroundSprite.y = 0;
204
- backgroundSprite.width = screenWidth;
205
- backgroundSprite.height = screenHeight;
206
- backgroundSprite.eventMode = "passive";
207
- app.stage.addChildAt(backgroundSprite, 0);
208
- pixiBgRef.current = backgroundSprite;
209
- };
210
- img.onerror = (e) => {
211
- import_console_browserify.default.error("load screenshot failed", e);
212
- };
213
- img.src = screenshotBase64;
214
- }, [app.stage, appInitialed, screenWidth, screenHeight]);
215
- const { highlightElementRects } = (0, import_react.useMemo)(() => {
216
- const highlightElementRects2 = [];
217
- highlightContainer.removeChildren();
218
- elementMarkContainer.removeChildren();
219
- highlightContainer.eventMode = "passive";
220
- elementMarkContainer.eventMode = "passive";
221
- if (highlightRect) {
222
- const [graphics] = rectMarkForItem(
212
+ if (null == highlightPoints ? void 0 : highlightPoints.length) highlightPoints.forEach((point)=>{
213
+ const graphics = pointMarkForItem(point, 'highlightPoint');
214
+ highlightContainer.addChild(graphics);
215
+ });
216
+ const elements = (0, extractor_namespaceObject.treeToList)(context.tree);
217
+ elements.forEach((element)=>{
218
+ const { rect, content, id } = element;
219
+ const ifHighlight = highlightIds.includes(id) || (null == hoverElement ? void 0 : hoverElement.id) === id;
220
+ if (ifHighlight) return;
221
+ const [graphics] = rectMarkForItem(rect, content, 'element');
222
+ elementMarkContainer.addChild(graphics);
223
+ });
224
+ elementMarkContainer.visible = elementsVisible;
225
+ return {
226
+ highlightElementRects
227
+ };
228
+ }, [
229
+ app,
230
+ appInitialed,
231
+ highlightElements,
232
+ context.tree,
233
+ hoverElement,
223
234
  highlightRect,
224
- "Search Area",
225
- "searchArea"
226
- );
227
- highlightContainer.addChild(graphics);
228
- }
229
- if (highlightElements.length) {
230
- highlightElements.forEach((element) => {
231
- const { rect, content, id } = element;
232
- const [graphics] = rectMarkForItem(rect, content, "highlight");
233
- highlightContainer.addChild(graphics);
234
- });
235
- }
236
- if (highlightPoints == null ? void 0 : highlightPoints.length) {
237
- highlightPoints.forEach((point) => {
238
- const graphics = pointMarkForItem(point, "highlightPoint");
239
- highlightContainer.addChild(graphics);
240
- });
241
- }
242
- const elements = (0, import_extractor.treeToList)(context.tree);
243
- elements.forEach((element) => {
244
- const { rect, content, id } = element;
245
- const ifHighlight = highlightIds.includes(id) || (hoverElement == null ? void 0 : hoverElement.id) === id;
246
- if (ifHighlight) {
247
- return;
248
- }
249
- const [graphics] = rectMarkForItem(rect, content, "element");
250
- elementMarkContainer.addChild(graphics);
251
- });
252
- elementMarkContainer.visible = elementsVisible;
253
- return {
254
- highlightElementRects: highlightElementRects2
235
+ highlightPoints
236
+ ]);
237
+ const onSetElementsVisible = (e)=>{
238
+ setTextsVisible(e.target.checked);
239
+ elementMarkContainer.visible = e.target.checked;
255
240
  };
256
- }, [
257
- app,
258
- appInitialed,
259
- highlightElements,
260
- context.tree,
261
- hoverElement,
262
- highlightRect,
263
- highlightPoints
264
- // bgVisible,
265
- // elementsVisible,
266
- ]);
267
- const onSetMarkerVisible = (e) => {
268
- setMarkerVisible(e.target.checked);
269
- if (pixiBgRef.current) {
270
- pixiBgRef.current.visible = e.target.checked;
271
- }
272
- };
273
- const onSetElementsVisible = (e) => {
274
- setTextsVisible(e.target.checked);
275
- elementMarkContainer.visible = e.target.checked;
276
- };
277
- let bottomTipA = null;
278
- if (highlightElementRects.length === 1) {
279
- bottomTipA = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "bottom-tip", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "bottom-tip-item", children: [
280
- "Element: ",
281
- JSON.stringify(highlightElementRects[0])
282
- ] }) });
283
- } else if (highlightElementRects.length > 1) {
284
- bottomTipA = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "bottom-tip", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "bottom-tip-item", children: [
285
- "Element: ",
286
- JSON.stringify(highlightElementRects)
287
- ] }) });
288
- }
289
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "blackboard", children: [
290
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
291
- "div",
292
- {
293
- className: "blackboard-main-content",
294
- style: { width: "100%" },
295
- ref: domRef
296
- }
297
- ),
298
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
299
- "div",
300
- {
301
- className: "blackboard-filter",
302
- style: { display: props.hideController ? "none" : "block" },
303
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "overlay-control", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Checkbox, { checked: elementsVisible, onChange: onSetElementsVisible, children: "Elements" }) })
304
- }
305
- ),
306
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
307
- "div",
308
- {
241
+ let bottomTipA = null;
242
+ if (1 === highlightElementRects.length) bottomTipA = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
243
+ className: "bottom-tip",
244
+ children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
245
+ className: "bottom-tip-item",
246
+ children: [
247
+ "Element: ",
248
+ JSON.stringify(highlightElementRects[0])
249
+ ]
250
+ })
251
+ });
252
+ else if (highlightElementRects.length > 1) bottomTipA = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
309
253
  className: "bottom-tip",
310
- style: { display: props.hideController ? "none" : "block" },
311
- children: bottomTipA
312
- }
313
- )
314
- ] });
254
+ children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
255
+ className: "bottom-tip-item",
256
+ children: [
257
+ "Element: ",
258
+ JSON.stringify(highlightElementRects)
259
+ ]
260
+ })
261
+ });
262
+ return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
263
+ className: "blackboard",
264
+ children: [
265
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
266
+ className: "blackboard-main-content",
267
+ style: {
268
+ width: '100%'
269
+ },
270
+ ref: domRef
271
+ }),
272
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
273
+ className: "blackboard-filter",
274
+ style: {
275
+ display: props.hideController ? 'none' : 'block'
276
+ },
277
+ children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
278
+ className: "overlay-control",
279
+ children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Checkbox, {
280
+ checked: elementsVisible,
281
+ onChange: onSetElementsVisible,
282
+ children: "Elements"
283
+ })
284
+ })
285
+ }),
286
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
287
+ className: "bottom-tip",
288
+ style: {
289
+ display: props.hideController ? 'none' : 'block'
290
+ },
291
+ children: bottomTipA
292
+ })
293
+ ]
294
+ });
315
295
  };
316
- var blackboard_default = Blackboard;
317
- // Annotate the CommonJS export names for ESM import in node:
318
- 0 && (module.exports = {
319
- Blackboard,
320
- pointMarkForItem,
321
- rectMarkForItem
296
+ const blackboard = Blackboard;
297
+ exports.Blackboard = __webpack_exports__.Blackboard;
298
+ exports["default"] = __webpack_exports__["default"];
299
+ exports.pointMarkForItem = __webpack_exports__.pointMarkForItem;
300
+ exports.rectMarkForItem = __webpack_exports__.rectMarkForItem;
301
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
302
+ "Blackboard",
303
+ "default",
304
+ "pointMarkForItem",
305
+ "rectMarkForItem"
306
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
307
+ Object.defineProperty(exports, '__esModule', {
308
+ value: true
322
309
  });