@ninthpalace/cocos-test 0.0.0-stage → 0.1.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 (325) hide show
  1. package/README.md +339 -2
  2. package/assets/cocos-sdk/cocos-sdk.js +1942 -0
  3. package/assets/cocos-sdk/manifest.json +5 -0
  4. package/assets/templates/environment/fields.json +35 -0
  5. package/assets/templates/repo-example/README.md +23 -0
  6. package/assets/templates/repo-example/cases/.gitkeep +1 -0
  7. package/assets/templates/repo-example/game/load-env.ts +4 -0
  8. package/assets/templates/repo-example/game/resources.ts +6 -0
  9. package/assets/templates/repo-example/game/setup.ts +30 -0
  10. package/assets/templates/repo-example/gitignore.template +10 -0
  11. package/assets/templates/repo-example/knowledge/navigation/index.json +5 -0
  12. package/assets/templates/repo-example/midscene.config.ts +20 -0
  13. package/assets/templates/repo-example/nct.config.ts +18 -0
  14. package/assets/templates/repo-example/nodes/index.ts +3 -0
  15. package/assets/templates/repo-example/package.json +10 -0
  16. package/assets/templates/repo-example/pnpm-workspace.yaml +3 -0
  17. package/assets/templates/repo-example/reports/.gitkeep +1 -0
  18. package/assets/templates/repo-example/scripts/generate-node-spec.mjs +19 -0
  19. package/assets/templates/repo-example/tsconfig.json +4 -0
  20. package/assets/templates/report/template.html +16 -0
  21. package/dist/cli/commands/case-worker.d.ts +2 -0
  22. package/dist/cli/commands/case-worker.d.ts.map +1 -0
  23. package/dist/cli/commands/case-worker.js +47 -0
  24. package/dist/cli/commands/case-worker.js.map +1 -0
  25. package/dist/cli/commands/case.d.ts +3 -0
  26. package/dist/cli/commands/case.d.ts.map +1 -0
  27. package/dist/cli/commands/case.js +76 -0
  28. package/dist/cli/commands/case.js.map +1 -0
  29. package/dist/cli/commands/knowledge-worker.d.ts +2 -0
  30. package/dist/cli/commands/knowledge-worker.d.ts.map +1 -0
  31. package/dist/cli/commands/knowledge-worker.js +14 -0
  32. package/dist/cli/commands/knowledge-worker.js.map +1 -0
  33. package/dist/cli/commands/knowledge.d.ts +3 -0
  34. package/dist/cli/commands/knowledge.d.ts.map +1 -0
  35. package/dist/cli/commands/knowledge.js +69 -0
  36. package/dist/cli/commands/knowledge.js.map +1 -0
  37. package/dist/cli/commands/navigation.d.ts +3 -0
  38. package/dist/cli/commands/navigation.d.ts.map +1 -0
  39. package/dist/cli/commands/navigation.js +98 -0
  40. package/dist/cli/commands/navigation.js.map +1 -0
  41. package/dist/cli/commands/repl.d.ts +3 -0
  42. package/dist/cli/commands/repl.d.ts.map +1 -0
  43. package/dist/cli/commands/repl.js +81 -0
  44. package/dist/cli/commands/repl.js.map +1 -0
  45. package/dist/cli/commands/report-worker.d.ts +2 -0
  46. package/dist/cli/commands/report-worker.d.ts.map +1 -0
  47. package/dist/cli/commands/report-worker.js +11 -0
  48. package/dist/cli/commands/report-worker.js.map +1 -0
  49. package/dist/cli/commands/report.d.ts +3 -0
  50. package/dist/cli/commands/report.d.ts.map +1 -0
  51. package/dist/cli/commands/report.js +65 -0
  52. package/dist/cli/commands/report.js.map +1 -0
  53. package/dist/cli/commands/task-worker.d.ts +2 -0
  54. package/dist/cli/commands/task-worker.d.ts.map +1 -0
  55. package/dist/cli/commands/task-worker.js +12 -0
  56. package/dist/cli/commands/task-worker.js.map +1 -0
  57. package/dist/cli/commands/task.d.ts +3 -0
  58. package/dist/cli/commands/task.d.ts.map +1 -0
  59. package/dist/cli/commands/task.js +155 -0
  60. package/dist/cli/commands/task.js.map +1 -0
  61. package/dist/cli/index.d.ts +3 -0
  62. package/dist/cli/index.d.ts.map +1 -0
  63. package/dist/cli/index.js +19 -0
  64. package/dist/cli/index.js.map +1 -0
  65. package/dist/cli/output/run.d.ts +18 -0
  66. package/dist/cli/output/run.d.ts.map +1 -0
  67. package/dist/cli/output/run.js +45 -0
  68. package/dist/cli/output/run.js.map +1 -0
  69. package/dist/cli/program.d.ts +3 -0
  70. package/dist/cli/program.d.ts.map +1 -0
  71. package/dist/cli/program.js +152 -0
  72. package/dist/cli/program.js.map +1 -0
  73. package/dist/config.d.ts +42 -0
  74. package/dist/config.d.ts.map +1 -0
  75. package/dist/config.js +59 -0
  76. package/dist/config.js.map +1 -0
  77. package/dist/core/authoring/session.d.ts +27 -0
  78. package/dist/core/authoring/session.d.ts.map +1 -0
  79. package/dist/core/authoring/session.js +161 -0
  80. package/dist/core/authoring/session.js.map +1 -0
  81. package/dist/core/poco/agent.d.ts +57 -0
  82. package/dist/core/poco/agent.d.ts.map +1 -0
  83. package/dist/core/poco/agent.js +116 -0
  84. package/dist/core/poco/agent.js.map +1 -0
  85. package/dist/core/poco/conditions.d.ts +50 -0
  86. package/dist/core/poco/conditions.d.ts.map +1 -0
  87. package/dist/core/poco/conditions.js +25 -0
  88. package/dist/core/poco/conditions.js.map +1 -0
  89. package/dist/core/poco/driver.d.ts +60 -0
  90. package/dist/core/poco/driver.d.ts.map +1 -0
  91. package/dist/core/poco/driver.js +247 -0
  92. package/dist/core/poco/driver.js.map +1 -0
  93. package/dist/core/poco/errors.d.ts +5 -0
  94. package/dist/core/poco/errors.d.ts.map +1 -0
  95. package/dist/core/poco/errors.js +10 -0
  96. package/dist/core/poco/errors.js.map +1 -0
  97. package/dist/core/poco/hierarchy.d.ts +109 -0
  98. package/dist/core/poco/hierarchy.d.ts.map +1 -0
  99. package/dist/core/poco/hierarchy.js +131 -0
  100. package/dist/core/poco/hierarchy.js.map +1 -0
  101. package/dist/core/poco/index.d.ts +11 -0
  102. package/dist/core/poco/index.d.ts.map +1 -0
  103. package/dist/core/poco/index.js +4 -0
  104. package/dist/core/poco/index.js.map +1 -0
  105. package/dist/core/poco/input.d.ts +25 -0
  106. package/dist/core/poco/input.d.ts.map +1 -0
  107. package/dist/core/poco/input.js +135 -0
  108. package/dist/core/poco/input.js.map +1 -0
  109. package/dist/core/poco/proxy.d.ts +43 -0
  110. package/dist/core/poco/proxy.d.ts.map +1 -0
  111. package/dist/core/poco/proxy.js +88 -0
  112. package/dist/core/poco/proxy.js.map +1 -0
  113. package/dist/core/poco/sdk.d.ts +137 -0
  114. package/dist/core/poco/sdk.d.ts.map +1 -0
  115. package/dist/core/poco/sdk.js +104 -0
  116. package/dist/core/poco/sdk.js.map +1 -0
  117. package/dist/core/poco/session.d.ts +25 -0
  118. package/dist/core/poco/session.d.ts.map +1 -0
  119. package/dist/core/poco/session.js +2 -0
  120. package/dist/core/poco/session.js.map +1 -0
  121. package/dist/core/project/env.d.ts +6 -0
  122. package/dist/core/project/env.d.ts.map +1 -0
  123. package/dist/core/project/env.js +21 -0
  124. package/dist/core/project/env.js.map +1 -0
  125. package/dist/core/project/error.d.ts +9 -0
  126. package/dist/core/project/error.d.ts.map +1 -0
  127. package/dist/core/project/error.js +35 -0
  128. package/dist/core/project/error.js.map +1 -0
  129. package/dist/core/project/load.d.ts +26 -0
  130. package/dist/core/project/load.d.ts.map +1 -0
  131. package/dist/core/project/load.js +93 -0
  132. package/dist/core/project/load.js.map +1 -0
  133. package/dist/core/project/node-catalog.d.ts +4 -0
  134. package/dist/core/project/node-catalog.d.ts.map +1 -0
  135. package/dist/core/project/node-catalog.js +14 -0
  136. package/dist/core/project/node-catalog.js.map +1 -0
  137. package/dist/core/project/node-metadata.d.ts +18 -0
  138. package/dist/core/project/node-metadata.d.ts.map +1 -0
  139. package/dist/core/project/node-metadata.js +28 -0
  140. package/dist/core/project/node-metadata.js.map +1 -0
  141. package/dist/core/project/readiness.d.ts +81 -0
  142. package/dist/core/project/readiness.d.ts.map +1 -0
  143. package/dist/core/project/readiness.js +69 -0
  144. package/dist/core/project/readiness.js.map +1 -0
  145. package/dist/core/project/resources.d.ts +17 -0
  146. package/dist/core/project/resources.d.ts.map +1 -0
  147. package/dist/core/project/resources.js +81 -0
  148. package/dist/core/project/resources.js.map +1 -0
  149. package/dist/core/reporting/contract.d.ts +37 -0
  150. package/dist/core/reporting/contract.d.ts.map +1 -0
  151. package/dist/core/reporting/contract.js +2 -0
  152. package/dist/core/reporting/contract.js.map +1 -0
  153. package/dist/core/reporting/evidence.d.ts +5 -0
  154. package/dist/core/reporting/evidence.d.ts.map +1 -0
  155. package/dist/core/reporting/evidence.js +66 -0
  156. package/dist/core/reporting/evidence.js.map +1 -0
  157. package/dist/core/reporting/offline-preview.d.ts +2 -0
  158. package/dist/core/reporting/offline-preview.d.ts.map +1 -0
  159. package/dist/core/reporting/offline-preview.js +45 -0
  160. package/dist/core/reporting/offline-preview.js.map +1 -0
  161. package/dist/core/reporting/offline-types.d.ts +67 -0
  162. package/dist/core/reporting/offline-types.d.ts.map +1 -0
  163. package/dist/core/reporting/offline-types.js +2 -0
  164. package/dist/core/reporting/offline-types.js.map +1 -0
  165. package/dist/core/reporting/page.d.ts +11 -0
  166. package/dist/core/reporting/page.d.ts.map +1 -0
  167. package/dist/core/reporting/page.js +63 -0
  168. package/dist/core/reporting/page.js.map +1 -0
  169. package/dist/core/reporting/recorder.d.ts +4 -0
  170. package/dist/core/reporting/recorder.d.ts.map +1 -0
  171. package/dist/core/reporting/recorder.js +329 -0
  172. package/dist/core/reporting/recorder.js.map +1 -0
  173. package/dist/core/reporting/session-report.d.ts +19 -0
  174. package/dist/core/reporting/session-report.d.ts.map +1 -0
  175. package/dist/core/reporting/session-report.js +226 -0
  176. package/dist/core/reporting/session-report.js.map +1 -0
  177. package/dist/core/testing/calls.d.ts +25 -0
  178. package/dist/core/testing/calls.d.ts.map +1 -0
  179. package/dist/core/testing/calls.js +144 -0
  180. package/dist/core/testing/calls.js.map +1 -0
  181. package/dist/core/testing/contracts.d.ts +110 -0
  182. package/dist/core/testing/contracts.d.ts.map +1 -0
  183. package/dist/core/testing/contracts.js +104 -0
  184. package/dist/core/testing/contracts.js.map +1 -0
  185. package/dist/core/testing/replay.d.ts +44 -0
  186. package/dist/core/testing/replay.d.ts.map +1 -0
  187. package/dist/core/testing/replay.js +89 -0
  188. package/dist/core/testing/replay.js.map +1 -0
  189. package/dist/core/testing/result.d.ts +73 -0
  190. package/dist/core/testing/result.d.ts.map +1 -0
  191. package/dist/core/testing/result.js +51 -0
  192. package/dist/core/testing/result.js.map +1 -0
  193. package/dist/core/testing/session.d.ts +49 -0
  194. package/dist/core/testing/session.d.ts.map +1 -0
  195. package/dist/core/testing/session.js +82 -0
  196. package/dist/core/testing/session.js.map +1 -0
  197. package/dist/core/workspace/artifacts.d.ts +2 -0
  198. package/dist/core/workspace/artifacts.d.ts.map +1 -0
  199. package/dist/core/workspace/artifacts.js +17 -0
  200. package/dist/core/workspace/artifacts.js.map +1 -0
  201. package/dist/core/workspace/files.d.ts +5 -0
  202. package/dist/core/workspace/files.d.ts.map +1 -0
  203. package/dist/core/workspace/files.js +53 -0
  204. package/dist/core/workspace/files.js.map +1 -0
  205. package/dist/core/workspace/identity.d.ts +10 -0
  206. package/dist/core/workspace/identity.d.ts.map +1 -0
  207. package/dist/core/workspace/identity.js +70 -0
  208. package/dist/core/workspace/identity.js.map +1 -0
  209. package/dist/core/workspace/task.d.ts +69 -0
  210. package/dist/core/workspace/task.d.ts.map +1 -0
  211. package/dist/core/workspace/task.js +81 -0
  212. package/dist/core/workspace/task.js.map +1 -0
  213. package/dist/core/workspace/yaml.d.ts +10 -0
  214. package/dist/core/workspace/yaml.d.ts.map +1 -0
  215. package/dist/core/workspace/yaml.js +49 -0
  216. package/dist/core/workspace/yaml.js.map +1 -0
  217. package/dist/index.d.ts +30 -0
  218. package/dist/index.d.ts.map +1 -0
  219. package/dist/index.js +19 -0
  220. package/dist/index.js.map +1 -0
  221. package/dist/nodes/create.d.ts +31 -0
  222. package/dist/nodes/create.d.ts.map +1 -0
  223. package/dist/nodes/create.js +99 -0
  224. package/dist/nodes/create.js.map +1 -0
  225. package/dist/nodes/index.d.ts +9 -0
  226. package/dist/nodes/index.d.ts.map +1 -0
  227. package/dist/nodes/index.js +5 -0
  228. package/dist/nodes/index.js.map +1 -0
  229. package/dist/nodes/input.d.ts +10 -0
  230. package/dist/nodes/input.d.ts.map +1 -0
  231. package/dist/nodes/input.js +22 -0
  232. package/dist/nodes/input.js.map +1 -0
  233. package/dist/nodes/jev/index.d.ts +36 -0
  234. package/dist/nodes/jev/index.d.ts.map +1 -0
  235. package/dist/nodes/jev/index.js +141 -0
  236. package/dist/nodes/jev/index.js.map +1 -0
  237. package/dist/nodes/poco/actions.d.ts +175 -0
  238. package/dist/nodes/poco/actions.d.ts.map +1 -0
  239. package/dist/nodes/poco/actions.js +119 -0
  240. package/dist/nodes/poco/actions.js.map +1 -0
  241. package/dist/nodes/poco/index.d.ts +637 -0
  242. package/dist/nodes/poco/index.d.ts.map +1 -0
  243. package/dist/nodes/poco/index.js +254 -0
  244. package/dist/nodes/poco/index.js.map +1 -0
  245. package/dist/nodes/report.d.ts +17 -0
  246. package/dist/nodes/report.d.ts.map +1 -0
  247. package/dist/nodes/report.js +14 -0
  248. package/dist/nodes/report.js.map +1 -0
  249. package/dist/repl.d.ts +12 -0
  250. package/dist/repl.d.ts.map +1 -0
  251. package/dist/repl.js +125 -0
  252. package/dist/repl.js.map +1 -0
  253. package/dist/report/style.css +2 -0
  254. package/dist/report/template.html +280 -0
  255. package/dist/services/case/index.d.ts +22 -0
  256. package/dist/services/case/index.d.ts.map +1 -0
  257. package/dist/services/case/index.js +238 -0
  258. package/dist/services/case/index.js.map +1 -0
  259. package/dist/services/env/index.d.ts +34 -0
  260. package/dist/services/env/index.d.ts.map +1 -0
  261. package/dist/services/env/index.js +168 -0
  262. package/dist/services/env/index.js.map +1 -0
  263. package/dist/services/env/inspect.d.ts +2 -0
  264. package/dist/services/env/inspect.d.ts.map +1 -0
  265. package/dist/services/env/inspect.js +43 -0
  266. package/dist/services/env/inspect.js.map +1 -0
  267. package/dist/services/knowledge/index.d.ts +67 -0
  268. package/dist/services/knowledge/index.d.ts.map +1 -0
  269. package/dist/services/knowledge/index.js +163 -0
  270. package/dist/services/knowledge/index.js.map +1 -0
  271. package/dist/services/navigation/contracts.d.ts +76 -0
  272. package/dist/services/navigation/contracts.d.ts.map +1 -0
  273. package/dist/services/navigation/contracts.js +67 -0
  274. package/dist/services/navigation/contracts.js.map +1 -0
  275. package/dist/services/navigation/index.d.ts +82 -0
  276. package/dist/services/navigation/index.d.ts.map +1 -0
  277. package/dist/services/navigation/index.js +304 -0
  278. package/dist/services/navigation/index.js.map +1 -0
  279. package/dist/services/point/index.d.ts +13 -0
  280. package/dist/services/point/index.d.ts.map +1 -0
  281. package/dist/services/point/index.js +42 -0
  282. package/dist/services/point/index.js.map +1 -0
  283. package/dist/services/project/index.d.ts +43 -0
  284. package/dist/services/project/index.d.ts.map +1 -0
  285. package/dist/services/project/index.js +194 -0
  286. package/dist/services/project/index.js.map +1 -0
  287. package/dist/services/project/inspect.d.ts +2 -0
  288. package/dist/services/project/inspect.d.ts.map +1 -0
  289. package/dist/services/project/inspect.js +29 -0
  290. package/dist/services/project/inspect.js.map +1 -0
  291. package/dist/services/project/policy.d.ts +12 -0
  292. package/dist/services/project/policy.d.ts.map +1 -0
  293. package/dist/services/project/policy.js +33 -0
  294. package/dist/services/project/policy.js.map +1 -0
  295. package/dist/services/report/catalog.d.ts +4 -0
  296. package/dist/services/report/catalog.d.ts.map +1 -0
  297. package/dist/services/report/catalog.js +6 -0
  298. package/dist/services/report/catalog.js.map +1 -0
  299. package/dist/services/report/index.d.ts +71 -0
  300. package/dist/services/report/index.d.ts.map +1 -0
  301. package/dist/services/report/index.js +334 -0
  302. package/dist/services/report/index.js.map +1 -0
  303. package/dist/services/skill/index.d.ts +14 -0
  304. package/dist/services/skill/index.d.ts.map +1 -0
  305. package/dist/services/skill/index.js +110 -0
  306. package/dist/services/skill/index.js.map +1 -0
  307. package/dist/services/task/index.d.ts +111 -0
  308. package/dist/services/task/index.d.ts.map +1 -0
  309. package/dist/services/task/index.js +81 -0
  310. package/dist/services/task/index.js.map +1 -0
  311. package/docs/examples/select-item.html +7 -0
  312. package/docs/examples/select-item.ts +34 -0
  313. package/docs/node-development.md +62 -0
  314. package/package.json +106 -3
  315. package/sdk/cocos-runtime/README.md +52 -0
  316. package/sdk/cocos-runtime/agents.md +24 -0
  317. package/skills/nct-rookie/SKILL.md +112 -0
  318. package/skills/nct-rookie/agents/openai.yaml +4 -0
  319. package/skills/nct-rookie/references/knowledge.md +48 -0
  320. package/skills/nct-rookie/references/navigation.md +22 -0
  321. package/skills/nct-rookie/references/repl.md +169 -0
  322. package/skills/nct-rookie/references/testing.md +123 -0
  323. package/skills/nct-rookie/references/yaml.md +82 -0
  324. package/skills/nct-rookie/scripts/repl-host.mjs +167 -0
  325. package/src/agents.md +75 -0
@@ -0,0 +1,1942 @@
1
+ "use strict";
2
+ (() => {
3
+ // src/facts.js
4
+ function once(read) {
5
+ let ready = false, value;
6
+ return () => {
7
+ if (!ready) {
8
+ value = read();
9
+ ready = true;
10
+ }
11
+ return value;
12
+ };
13
+ }
14
+ var stateKey = Symbol("capture facts");
15
+ function defineFacts(groups) {
16
+ const fields = groups.flatMap((group) => group.fields);
17
+ const prototype = { toJSON() {
18
+ return completeFacts(this);
19
+ } };
20
+ groups.forEach(({ fields: fields2, read }, index) => {
21
+ for (const field of fields2) Object.defineProperty(prototype, field, {
22
+ get() {
23
+ const state = this[stateKey];
24
+ const values = state.values[index] ??= read(state);
25
+ return values[field];
26
+ }
27
+ });
28
+ });
29
+ return (target, state) => {
30
+ Object.setPrototypeOf(target, prototype);
31
+ Object.assign(state, { payload: target, fields, values: [] });
32
+ Object.defineProperty(target, stateKey, { value: state });
33
+ return target;
34
+ };
35
+ }
36
+ function completeFacts(target) {
37
+ const result = { ...target };
38
+ for (const field of target[stateKey]?.fields || []) result[field] = target[field];
39
+ return result;
40
+ }
41
+ function mapField(target, field, transform) {
42
+ const descriptor = Object.getOwnPropertyDescriptor(target, field) || Object.getOwnPropertyDescriptor(Object.getPrototypeOf(target), field);
43
+ if (!descriptor) return;
44
+ const read = once(() => transform(descriptor.get ? descriptor.get.call(target) : descriptor.value));
45
+ Object.defineProperty(target, field, { enumerable: true, configurable: true, get: read });
46
+ }
47
+
48
+ // src/cocos-v2.js
49
+ var noInputFacts = Object.freeze({
50
+ enabled: false,
51
+ clickable: false,
52
+ input_receiver: false,
53
+ input_capabilities: Object.freeze({
54
+ touch_down: false,
55
+ touch_up: false,
56
+ touch_move: false,
57
+ mouse_down: false,
58
+ mouse_up: false,
59
+ hover: false,
60
+ wheel: false
61
+ })
62
+ });
63
+ function effectiveInputListener(listener, cc) {
64
+ let manager = cc && cc.internal && cc.internal.eventManager;
65
+ if (!manager && cc) {
66
+ const descriptor = Object.getOwnPropertyDescriptor(cc, "eventManager");
67
+ manager = descriptor && descriptor.value;
68
+ }
69
+ return !!listener && !(manager && manager._isEnabled === false) && listener._paused !== true && listener._registered !== false && listener._isPaused !== true && listener._isRegistered !== false && !(typeof listener._isPaused === "function" && listener._isPaused() === true) && !(typeof listener._isRegistered === "function" && listener._isRegistered() === false) && listener._enabled !== false && listener._isEnabled !== false && !(typeof listener.isEnabled === "function" && listener.isEnabled() === false);
70
+ }
71
+ function cocosInputCapabilities(node2, cc, components) {
72
+ const controls = components.filter((c) => ["Button", "Toggle", "EditBox", "Slider"].some((name) => typeof cc[name] === "function" && c instanceof cc[name]));
73
+ const isBlock = (c) => typeof cc.BlockInputEvents === "function" && c instanceof cc.BlockInputEvents;
74
+ const isControl = (c) => controls.includes(c);
75
+ const enabled = (c) => c.enabled !== false && c.enabledInHierarchy !== false && c.interactable !== false;
76
+ const touch = effectiveInputListener(node2._touchListener, cc);
77
+ const mouse = effectiveInputListener(node2._mouseListener, cc);
78
+ const stores = [node2._capturingListeners, node2._bubblingListeners].filter(Boolean);
79
+ const known = typeof node2.hasEventListener === "function" || stores.length > 0;
80
+ function event(type) {
81
+ const present = typeof node2.hasEventListener === "function" ? node2.hasEventListener(type) : stores.some((store) => typeof store.hasEventListener === "function" ? store.hasEventListener(type) : (() => {
82
+ const list = store._callbackTable && store._callbackTable[type];
83
+ const infos = list && (list.callbackInfos || (Array.isArray(list) ? list : null));
84
+ return !!infos && infos.some((info) => info && (info.callback || typeof info === "function"));
85
+ })());
86
+ return !!present;
87
+ }
88
+ function business(type) {
89
+ let inspected = false, custom = false;
90
+ for (const store of stores) {
91
+ const list = store._callbackTable && store._callbackTable[type];
92
+ if (!list) continue;
93
+ const infos = list.callbackInfos || (Array.isArray(list) ? list : null);
94
+ if (!infos) continue;
95
+ inspected = true;
96
+ custom = custom || infos.some((info) => info && (info.callback || typeof info === "function") && !isBlock(info.target) && (!isControl(info.target) || enabled(info.target)));
97
+ }
98
+ if (inspected) return custom;
99
+ return event(type) && (!controls.length || controls.some(enabled)) && !(components.some(isBlock) && !controls.some(enabled));
100
+ }
101
+ const types = {
102
+ touch_down: ["touchstart"],
103
+ touch_up: ["touchend"],
104
+ touch_move: ["touchmove", "touchcancel"],
105
+ mouse_down: ["mousedown"],
106
+ mouse_up: ["mouseup"],
107
+ hover: ["mouseenter", "mouseleave", "mousemove"],
108
+ wheel: ["mousewheel"]
109
+ };
110
+ const capabilities = {};
111
+ let action = false;
112
+ for (const [key, events] of Object.entries(types)) {
113
+ const listening = key.startsWith("touch") ? touch : mouse;
114
+ capabilities[key] = listening && (known ? events.some(event) : key === "touch_down" || key === "touch_up" || key === "mouse_down" || key === "mouse_up");
115
+ if (key !== "hover" && key !== "wheel") action = action || capabilities[key] && (known ? events.some(business) : (!controls.length || controls.some(enabled)) && !components.some(isBlock));
116
+ }
117
+ return { touch, mouse, receives: touch || mouse, action, capabilities };
118
+ }
119
+ function mostDerivedComponent(components) {
120
+ let best = components[0], bestDepth = -1;
121
+ for (const component of components) {
122
+ let depth = 0;
123
+ for (let proto = Object.getPrototypeOf(component); proto; proto = Object.getPrototypeOf(proto)) depth += 1;
124
+ if (depth > bestDepth) {
125
+ best = component;
126
+ bestDepth = depth;
127
+ }
128
+ }
129
+ return best;
130
+ }
131
+ function cocosClassName(value, cc) {
132
+ if (cc.js && cc.js.getClassName) return cc.js.getClassName(value);
133
+ return value.__classname__ || value.constructor.name;
134
+ }
135
+ function cocosNodeType(node2, controls, cc) {
136
+ return cocosClassName(controls.length ? mostDerivedComponent(controls) : node2, cc);
137
+ }
138
+ function nodeText(components, cc) {
139
+ for (const c of components) {
140
+ for (const type of [cc.Label, cc.RichText, cc.EditBox]) {
141
+ if (typeof type === "function" && c instanceof type && typeof c.string === "string" && c.string) {
142
+ return c.string;
143
+ }
144
+ }
145
+ }
146
+ return "";
147
+ }
148
+ function nodeIcon(components, cc) {
149
+ if (typeof cc.Sprite !== "function") return "";
150
+ for (const c of components) {
151
+ if (!(c instanceof cc.Sprite)) continue;
152
+ const frame = c.spriteFrame;
153
+ if (frame) {
154
+ const value = String(frame.name || frame._name || frame._uuid || "");
155
+ if (value) return value;
156
+ }
157
+ }
158
+ return "";
159
+ }
160
+ function ownWorldBounds(node2, cc, matrix, point) {
161
+ if (!node2.getContentSize || !node2.getAnchorPoint || !node2.getWorldMatrix || !matrix || !cc.Vec2 || !cc.Vec2.transformMat4) return null;
162
+ const { width, height } = node2.getContentSize();
163
+ const anchor = node2.getAnchorPoint();
164
+ if (!anchor || ![width, height, anchor.x, anchor.y].every(Number.isFinite)) return null;
165
+ node2.getWorldMatrix(matrix);
166
+ const left = -anchor.x * width, bottom = -anchor.y * height;
167
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
168
+ for (let i = 0; i < 4; i++) {
169
+ point.x = left + i % 2 * width;
170
+ point.y = bottom + (i >> 1) * height;
171
+ cc.Vec2.transformMat4(point, point, matrix);
172
+ if (!Number.isFinite(point.x) || !Number.isFinite(point.y)) return null;
173
+ minX = Math.min(minX, point.x);
174
+ minY = Math.min(minY, point.y);
175
+ maxX = Math.max(maxX, point.x);
176
+ maxY = Math.max(maxY, point.y);
177
+ }
178
+ return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
179
+ }
180
+ function componentsOf(state) {
181
+ return state.components ??= state.node.getComponents ? state.node.getComponents(state.context.cc.Component) : [];
182
+ }
183
+ function controlsOf(state) {
184
+ const cc = state.context.cc;
185
+ return state.controls ??= componentsOf(state).filter((c) => [cc.Button, cc.Toggle, cc.EditBox, cc.Slider].some((type) => typeof type === "function" && c instanceof type));
186
+ }
187
+ var nodeFacts = defineFacts([
188
+ { fields: ["type", "components", "editable"], read(state) {
189
+ const cc = state.context.cc;
190
+ return {
191
+ type: cocosNodeType(state.node, controlsOf(state), cc),
192
+ components: componentsOf(state).map((c) => cocosClassName(c, cc)),
193
+ editable: controlsOf(state).some((c) => typeof cc.EditBox === "function" && c instanceof cc.EditBox)
194
+ };
195
+ } },
196
+ { fields: ["text"], read: (state) => ({ text: nodeText(componentsOf(state), state.context.cc) }) },
197
+ { fields: ["checked"], read(state) {
198
+ const cc = state.context.cc;
199
+ const toggle = componentsOf(state).find((c) => typeof cc.Toggle === "function" && c instanceof cc.Toggle);
200
+ return toggle && typeof toggle.isChecked === "boolean" ? { checked: toggle.isChecked } : {};
201
+ } },
202
+ { fields: ["icon"], read: (state) => ({ icon: nodeIcon(componentsOf(state), state.context.cc) }) },
203
+ { fields: ["enabled", "clickable", "input_capabilities", "input_receiver"], read(state) {
204
+ if (!effectiveInputListener(state.node._touchListener, state.context.cc) && !effectiveInputListener(state.node._mouseListener, state.context.cc)) return noInputFacts;
205
+ const input = cocosInputCapabilities(state.node, state.context.cc, componentsOf(state));
206
+ return {
207
+ enabled: input.action,
208
+ clickable: input.action,
209
+ input_capabilities: input.capabilities,
210
+ input_receiver: input.receives
211
+ };
212
+ } },
213
+ { fields: ["visible", "pos", "size", "bounds_quality", "confidence"], read(state) {
214
+ const { cc, calibrated, matrix, point, box, vp, sx, sy, canvas, innerWidth, innerHeight } = state.context;
215
+ const geometry = { visible: state.visible, bounds_quality: "unavailable", confidence: "low" };
216
+ const r = calibrated && ownWorldBounds(state.node, cc, matrix, point);
217
+ if (!r) return geometry;
218
+ const left = box.left + (r.x * sx + vp.x) / canvas.width * box.width;
219
+ const top = box.top + (1 - ((r.y + r.height) * sy + vp.y) / canvas.height) * box.height;
220
+ const width = r.width * sx / canvas.width * box.width, height = r.height * sy / canvas.height * box.height;
221
+ if ([left, top, width, height].every(Number.isFinite)) {
222
+ geometry.pos = [(left + width / 2) / innerWidth, (top + height / 2) / innerHeight];
223
+ geometry.size = [width / innerWidth, height / innerHeight];
224
+ geometry.bounds_quality = "world_aabb";
225
+ geometry.confidence = "medium";
226
+ geometry.visible = state.visible && width > 0 && height > 0 && left < innerWidth && top < innerHeight && left + width > 0 && top + height > 0;
227
+ }
228
+ return geometry;
229
+ } },
230
+ { fields: ["interactable", "automation_candidate", "candidate_reason"], read({ payload }) {
231
+ const interactable = payload.bounds_quality === "world_aabb" && payload.visible && payload.enabled;
232
+ return {
233
+ interactable,
234
+ automation_candidate: interactable,
235
+ candidate_reason: interactable ? "input_listener_candidate" : payload.input_receiver ? "input_receiver_not_action_or_not_visible" : "no_effective_input_listener"
236
+ };
237
+ } }
238
+ ]);
239
+ function createCocosV2Observer() {
240
+ const documents = /* @__PURE__ */ new WeakMap();
241
+ let nextId = 0;
242
+ const handles = /* @__PURE__ */ new WeakMap();
243
+ return function observeCocosV2(doc) {
244
+ const win = doc.defaultView;
245
+ const cc = win && win.cc;
246
+ const scene = cc && cc.director && cc.director.getScene();
247
+ const version = cc && (cc.ENGINE_VERSION || cc.version);
248
+ const canvas = doc.querySelector("#GameCanvas") || doc.querySelector("canvas");
249
+ if (!scene || !/^2\./.test(String(version)) || !cc.view || !canvas) return null;
250
+ let state = documents.get(doc);
251
+ if (!state || state.scene !== scene || state.runtime !== cc) {
252
+ state = { scene, runtime: cc, epoch: state ? state.epoch + 1 : 1 };
253
+ documents.set(doc, state);
254
+ }
255
+ const epoch = state.epoch;
256
+ const innerWidth = win.innerWidth, innerHeight = win.innerHeight;
257
+ const box = canvas.getBoundingClientRect();
258
+ const vp = cc.view.getViewportRect();
259
+ const sx = cc.view.getScaleX(), sy = cc.view.getScaleY();
260
+ const calibrated = [canvas.width, canvas.height, box.width, box.height, sx, sy, innerWidth, innerHeight].every((v) => Number.isFinite(v) && v > 0);
261
+ const matrix = typeof cc.Mat4 === "function" ? new cc.Mat4() : null;
262
+ const point = { x: 0, y: 0 };
263
+ const context = { cc, calibrated, matrix, point, box, vp, sx, sy, canvas, innerWidth, innerHeight };
264
+ function visit(node2, parentVisible) {
265
+ if (!handles.has(node2)) handles.set(node2, "cocos:" + ++nextId);
266
+ const active = node2 === scene || node2.activeInHierarchy !== false;
267
+ const visible2 = parentVisible && active && node2.opacity !== 0;
268
+ const state2 = { node: node2, context, visible: visible2 };
269
+ const payload = nodeFacts({
270
+ layer: "game",
271
+ name: String(node2.name || ""),
272
+ id: String(node2.automationId || node2.testId || node2.__automationId || ""),
273
+ active,
274
+ component_properties: {},
275
+ source: "injected_cocos_v2_hook",
276
+ _hybrid_target_id: handles.get(node2),
277
+ _hybrid_scene_epoch: epoch,
278
+ anchorPoint: [0.5, 0.5]
279
+ }, state2);
280
+ const snapshot = { name: payload.name, payload, children: (node2.children || []).map((child) => visit(child, visible2)) };
281
+ Object.defineProperty(snapshot, "__cocos_runtime_cocos_node", { value: node2, enumerable: false, configurable: true });
282
+ Object.defineProperty(snapshot, "__cocos_runtime_document", { value: doc });
283
+ Object.defineProperty(snapshot, "__cocos_runtime_components", { value: () => componentsOf(state2) });
284
+ return snapshot;
285
+ }
286
+ const tree = visit(scene, box.width > 0 && box.height > 0);
287
+ Object.defineProperty(tree, "__cocos_runtime_geometry", { value: { rect: box } });
288
+ return { tree, version: String(version) };
289
+ };
290
+ }
291
+
292
+ // src/inspector.js
293
+ var OVERLAY_ATTR = "data-cocos-runtime-overlay";
294
+ var Z_INDEX = 2147483647;
295
+ var RECT_STYLE = { background: "transparent", border: "1px solid transparent", boxShadow: "none" };
296
+ var RECT_HOVER_STYLE = {
297
+ background: "rgba(134,239,172,0.14)",
298
+ border: "1px solid rgba(134,239,172,0.92)",
299
+ boxShadow: "inset 0 0 0 1px rgba(255,255,255,0.14), 0 0 0 1px rgba(0,0,0,0.6)"
300
+ };
301
+ var RECT_SELECTED_STYLE = {
302
+ background: "rgba(134,239,172,0.22)",
303
+ border: "2px solid #86efac",
304
+ boxShadow: "0 0 0 1px rgba(0,0,0,0.72), 0 0 11px rgba(134,239,172,0.58), inset 0 0 0 1px rgba(255,255,255,0.24)"
305
+ };
306
+ var RECT_REVEAL_STYLE = {
307
+ background: "transparent",
308
+ border: "1px solid rgba(134,239,172,0.46)",
309
+ boxShadow: "inset 0 0 0 1px rgba(0,0,0,0.22)"
310
+ };
311
+ var CONTENT_COMPONENT = /^cc\.(Sprite|Label|RichText|Graphics|Mask|ProgressBar|ParticleSystem|Spine|DragonBones|Animation|Button|Toggle|EditBox|Slider|ScrollView|PageView|WebView|VideoPlayer|MovieClip)$/;
312
+ function hasContent(payload) {
313
+ return (payload.components || []).some((name) => CONTENT_COMPONENT.test(String(name)));
314
+ }
315
+ var ICONS = {
316
+ drag: '<svg width="10" height="14" viewBox="0 0 10 14"><g fill="#bbb"><circle cx="3" cy="2" r="1.2"/><circle cx="7" cy="2" r="1.2"/><circle cx="3" cy="7" r="1.2"/><circle cx="7" cy="7" r="1.2"/><circle cx="3" cy="12" r="1.2"/><circle cx="7" cy="12" r="1.2"/></g></svg>',
317
+ select: '<svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="#eee" stroke-width="1.4"><circle cx="7" cy="7" r="4.5"/><line x1="7" y1="0.5" x2="7" y2="4"/><line x1="7" y1="10" x2="7" y2="13.5"/><line x1="0.5" y1="7" x2="4" y2="7"/><line x1="10" y1="7" x2="13.5" y2="7"/></svg>',
318
+ refresh: '<svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="#eee" stroke-width="1.4"><path d="M12.5 7a5.5 5.5 0 1 1-1.6-3.9"/><polyline points="12.5 0.8 12.5 3.6 9.7 3.6"/></svg>',
319
+ reveal: '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#eee" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M2 12s3.5-6 10-6 10 6 10 6-3.5 6-10 6S2 12 2 12Z"/><circle cx="12" cy="12" r="3"/></svg>',
320
+ interactable: '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#eee" stroke-width="1.8"><rect x="3" y="3" width="8" height="8"/><rect x="13" y="3" width="8" height="8"/><rect x="3" y="13" width="8" height="8"/><path d="M14 17h7m-3.5-3.5v7"/></svg>'
321
+ };
322
+ function createInspector(observeCocos, getInteractable) {
323
+ let toolbar = null;
324
+ let overlay = null;
325
+ let active = false;
326
+ let selectedRect = null;
327
+ let selectButton = null;
328
+ let revealButton = null;
329
+ let revealAll = false;
330
+ let interactableButton = null;
331
+ let showInteractable = false;
332
+ let interactableNodes = [];
333
+ let hoveredRect = null;
334
+ let previousCursor = null;
335
+ const rectNodes = /* @__PURE__ */ new WeakMap();
336
+ const rectBounds = /* @__PURE__ */ new WeakMap();
337
+ const structuralRects = /* @__PURE__ */ new WeakSet();
338
+ const nodeElements = /* @__PURE__ */ new Map();
339
+ let visualRects = [];
340
+ let pointerDownSeenUntil = 0;
341
+ let mutedRects = /* @__PURE__ */ new Set();
342
+ let pickDepth = 0;
343
+ let lastPickPoint = null;
344
+ let effectiveDepth = 0;
345
+ let depthBadge = null;
346
+ let inputBlocker = null;
347
+ let programmaticHighlight = null;
348
+ function clearOverlay() {
349
+ if (overlay) {
350
+ overlay.remove();
351
+ overlay = null;
352
+ }
353
+ if (programmaticHighlight) {
354
+ programmaticHighlight.remove();
355
+ programmaticHighlight = null;
356
+ }
357
+ mutedRects = /* @__PURE__ */ new Set();
358
+ nodeElements.clear();
359
+ visualRects = [];
360
+ selectedRect = null;
361
+ hoveredRect = null;
362
+ }
363
+ function baseRectStyle(rect) {
364
+ const base = revealAll || showInteractable ? RECT_REVEAL_STYLE : RECT_STYLE;
365
+ return rect && structuralRects.has(rect) ? Object.assign({}, base, { borderStyle: "dotted" }) : base;
366
+ }
367
+ function setHoveredRect(next) {
368
+ if (hoveredRect === next) return;
369
+ if (hoveredRect && hoveredRect !== selectedRect) Object.assign(hoveredRect.style, baseRectStyle(hoveredRect));
370
+ hoveredRect = next && next !== selectedRect ? next : null;
371
+ if (hoveredRect) Object.assign(hoveredRect.style, RECT_HOVER_STYLE);
372
+ }
373
+ function clearHoveredRect() {
374
+ setHoveredRect(null);
375
+ }
376
+ function elementContains(root, target) {
377
+ for (let el = target; el; el = el.parentElement) {
378
+ if (el === root) return true;
379
+ }
380
+ return false;
381
+ }
382
+ function setMutedRects(list) {
383
+ const next = new Set(list);
384
+ mutedRects.forEach((el) => {
385
+ if (!next.has(el)) el.style.pointerEvents = structuralRects.has(el) ? "none" : "auto";
386
+ });
387
+ next.forEach((el) => {
388
+ if (!mutedRects.has(el)) el.style.pointerEvents = "none";
389
+ });
390
+ mutedRects = next;
391
+ }
392
+ function rectStackAt(clientX, clientY) {
393
+ setMutedRects([]);
394
+ if (!overlay || !Number.isFinite(clientX) || !Number.isFinite(clientY)) return [];
395
+ if (document.elementsFromPoint) {
396
+ return document.elementsFromPoint(clientX, clientY).filter((el) => el.getAttribute && el.getAttribute("data-cocos-runtime-rect") === "1" && rectBounds.has(el));
397
+ }
398
+ const stack = [];
399
+ for (let i = visualRects.length - 1; i >= 0; i -= 1) {
400
+ const rect = visualRects[i];
401
+ const box = rect && rectBounds.get(rect);
402
+ if (!box || rect.style.pointerEvents === "none") continue;
403
+ if (clientX >= box.left && clientX <= box.right && clientY >= box.top && clientY <= box.bottom) stack.push(rect);
404
+ }
405
+ return stack;
406
+ }
407
+ function resolveRectAt(clientX, clientY) {
408
+ const stack = rectStackAt(clientX, clientY);
409
+ if (!stack.length) {
410
+ effectiveDepth = 0;
411
+ syncDepthBadge();
412
+ return null;
413
+ }
414
+ const depth = Math.max(0, Math.min(pickDepth, stack.length - 1));
415
+ effectiveDepth = depth;
416
+ setMutedRects(stack.slice(0, depth));
417
+ syncDepthBadge();
418
+ return stack[depth];
419
+ }
420
+ function setPickDepth(delta, clientX, clientY) {
421
+ if (!overlay || !Number.isFinite(clientX) || !Number.isFinite(clientY)) return null;
422
+ const stack = rectStackAt(clientX, clientY);
423
+ if (!stack.length) {
424
+ pickDepth = 0;
425
+ setMutedRects([]);
426
+ syncDepthBadge();
427
+ return null;
428
+ }
429
+ const size = stack.length;
430
+ pickDepth = ((pickDepth + delta) % size + size) % size;
431
+ effectiveDepth = pickDepth;
432
+ setMutedRects(stack.slice(0, pickDepth));
433
+ syncDepthBadge();
434
+ return stack[pickDepth];
435
+ }
436
+ function isRepeatPick(clientX, clientY) {
437
+ if (!lastPickPoint) return false;
438
+ if (Date.now() - lastPickPoint.at > 2e3) return false;
439
+ return Math.hypot(clientX - lastPickPoint.x, clientY - lastPickPoint.y) <= 4;
440
+ }
441
+ function onHoverMove(event) {
442
+ if (!active) return;
443
+ if (elementContains(toolbar, event.target)) {
444
+ clearHoveredRect();
445
+ return;
446
+ }
447
+ const point = eventPoint(event);
448
+ setHoveredRect(resolveRectAt(point.x, point.y));
449
+ }
450
+ function onWheel(event) {
451
+ if (!active) return;
452
+ const point = eventPoint(event);
453
+ if (event.preventDefault) event.preventDefault();
454
+ if (event.stopPropagation) event.stopPropagation();
455
+ if (event.altKey && Number.isFinite(point.x) && Number.isFinite(point.y)) {
456
+ setHoveredRect(setPickDepth(event.deltaY > 0 ? 1 : -1, point.x, point.y));
457
+ }
458
+ }
459
+ function onHoverOut(event) {
460
+ if (!active || event.relatedTarget) return;
461
+ const point = eventPoint(event);
462
+ const outside = !Number.isFinite(point.x) || !Number.isFinite(point.y) || point.x <= 0 || point.y <= 0 || point.x >= window.innerWidth || point.y >= window.innerHeight;
463
+ if (outside) clearHoveredRect();
464
+ }
465
+ function onInspectPointerDown(event) {
466
+ if (event.type === "mousedown" && Date.now() < pointerDownSeenUntil) return;
467
+ if (event.type === "touchstart" && Date.now() < pointerDownSeenUntil) return;
468
+ if (event.type === "pointerdown" || event.type === "touchstart") pointerDownSeenUntil = Date.now() + 500;
469
+ if (!active || event.button !== void 0 && event.button !== 0) return;
470
+ if (elementContains(toolbar, event.target)) return;
471
+ if (event.preventDefault) event.preventDefault();
472
+ if (event.stopPropagation) event.stopPropagation();
473
+ const point = eventPoint(event);
474
+ let rect;
475
+ if (event.altKey || isRepeatPick(point.x, point.y)) {
476
+ rect = setPickDepth(1, point.x, point.y);
477
+ } else {
478
+ pickDepth = 0;
479
+ rect = resolveRectAt(point.x, point.y);
480
+ }
481
+ lastPickPoint = { x: point.x, y: point.y, at: Date.now() };
482
+ const node2 = rect ? rectNodes.get(rect) : null;
483
+ if (rect && node2) select2(rect, node2);
484
+ }
485
+ function select2(rect, node2) {
486
+ if (selectedRect) Object.assign(selectedRect.style, baseRectStyle(selectedRect));
487
+ selectedRect = rect;
488
+ Object.assign(rect.style, RECT_SELECTED_STYLE);
489
+ const p = node2.payload || {};
490
+ console.groupCollapsed("[\u4E5D\u5BAB\u6E38\u620F] inspect node: " + (p.type || "Node") + ' "' + (p.name || "") + '"');
491
+ console.dir(node2, { depth: 3, colors: true });
492
+ console.log("[\u4E5D\u5BAB\u6E38\u620F] overlay element", rect);
493
+ console.groupEnd();
494
+ }
495
+ function eventPoint(event) {
496
+ const touches = event.touches && event.touches.length ? event.touches : event.changedTouches;
497
+ if (touches && touches.length) return { x: touches[0].clientX, y: touches[0].clientY };
498
+ return { x: event.clientX, y: event.clientY };
499
+ }
500
+ function rectPickable(hasBounds, payload) {
501
+ return hasBounds && hasContent(payload);
502
+ }
503
+ function applyPickableState() {
504
+ if (!active) return;
505
+ visualRects.forEach((el) => {
506
+ if (el.getAttribute("data-cocos-runtime-pickable") !== "1") return;
507
+ if (el.getAttribute("data-cocos-runtime-visible") === "0") return;
508
+ el.style.pointerEvents = "auto";
509
+ el.style.cursor = "crosshair";
510
+ });
511
+ }
512
+ function rectFor(node2, depth, path, forcePickable = false) {
513
+ const p = node2.payload || {};
514
+ const hasBounds = !!(p.pos && p.size);
515
+ const pickable = forcePickable ? hasBounds : rectPickable(hasBounds, p);
516
+ const rect = document.createElement("div");
517
+ rect.setAttribute(OVERLAY_ATTR, "1");
518
+ rect.setAttribute("data-cocos-runtime-rect", "1");
519
+ rect.setAttribute("data-cocos-runtime-cocos-node", "1");
520
+ rect.setAttribute("data-cocos-runtime-path", path);
521
+ rect.setAttribute("data-cocos-runtime-node-name", String(p.name || "").slice(0, 200));
522
+ rect.setAttribute("data-cocos-runtime-node-type", String(p.type || "Node").slice(0, 200));
523
+ rect.setAttribute("data-cocos-runtime-node-id", String(p.id || "").slice(0, 200));
524
+ rect.setAttribute("data-cocos-runtime-visible", p.visible !== false ? "1" : "0");
525
+ rect.setAttribute("data-cocos-runtime-depth", String(depth));
526
+ rect.setAttribute("data-cocos-runtime-pickable", pickable ? "1" : "0");
527
+ if (!pickable) structuralRects.add(rect);
528
+ rect.__cocos_runtime_node = node2;
529
+ rect.__cocos_runtime_cocos_node = node2.__cocos_runtime_cocos_node || null;
530
+ Object.assign(rect.style, {
531
+ position: "fixed",
532
+ boxSizing: "border-box",
533
+ overflow: "visible",
534
+ transition: "background 80ms ease, border-color 80ms ease, box-shadow 80ms ease"
535
+ });
536
+ if (hasBounds) {
537
+ const width = p.size[0] * window.innerWidth, height = p.size[1] * window.innerHeight;
538
+ const left = p.pos[0] * window.innerWidth - width / 2;
539
+ const top = p.pos[1] * window.innerHeight - height / 2;
540
+ Object.assign(rect.style, {
541
+ cursor: pickable ? "crosshair" : "default",
542
+ pointerEvents: pickable ? "auto" : "none",
543
+ left: left + "px",
544
+ top: top + "px",
545
+ width: width + "px",
546
+ height: height + "px"
547
+ }, baseRectStyle(rect));
548
+ rectBounds.set(rect, { left, top, right: left + width, bottom: top + height });
549
+ if (!p.visible) Object.assign(rect.style, {
550
+ borderStyle: "dashed",
551
+ opacity: revealAll ? "0.65" : "0.5",
552
+ pointerEvents: "none"
553
+ });
554
+ } else {
555
+ Object.assign(rect.style, {
556
+ left: "0",
557
+ top: "0",
558
+ width: "0",
559
+ height: "0",
560
+ pointerEvents: "none",
561
+ border: "0",
562
+ background: "transparent",
563
+ boxShadow: "none"
564
+ });
565
+ }
566
+ rect.title = path || p.name || "";
567
+ rectNodes.set(rect, node2);
568
+ return rect;
569
+ }
570
+ function buildElement(node2, depth, parentPath) {
571
+ const name = String(node2.payload && node2.payload.name || "");
572
+ const path = parentPath ? parentPath + "/" + name : name;
573
+ const el = rectFor(node2, depth, path);
574
+ nodeElements.set(node2, el);
575
+ (node2.children || []).forEach((child) => el.appendChild(buildElement(child, depth + 1, path)));
576
+ return el;
577
+ }
578
+ function targetDocument() {
579
+ const frame = document.getElementById("wfMainContainer");
580
+ if (frame && frame.tagName === "IFRAME") {
581
+ try {
582
+ if (frame.contentDocument) return frame.contentDocument;
583
+ } catch {
584
+ console.warn("[\u4E5D\u5BAB\u6E38\u620F] inspect: \u8DE8\u57DF iframe \u65E0\u6CD5\u8BFB\u53D6\uFF0C\u56DE\u9000\u5230\u5F53\u524D\u9875\u9762");
585
+ }
586
+ }
587
+ return document;
588
+ }
589
+ function installInputBlocker() {
590
+ if (inputBlocker) return;
591
+ inputBlocker = document.createElement("div");
592
+ inputBlocker.setAttribute(OVERLAY_ATTR, "1");
593
+ inputBlocker.setAttribute("data-cocos-runtime-chrome", "1");
594
+ inputBlocker.setAttribute("data-cocos-runtime-input-blocker", "1");
595
+ Object.assign(inputBlocker.style, {
596
+ position: "fixed",
597
+ inset: "0",
598
+ boxSizing: "border-box",
599
+ zIndex: Z_INDEX - 2,
600
+ background: "transparent",
601
+ cursor: "crosshair"
602
+ });
603
+ document.documentElement.appendChild(inputBlocker);
604
+ }
605
+ function removeInputBlocker() {
606
+ if (!inputBlocker) return;
607
+ inputBlocker.remove();
608
+ inputBlocker = null;
609
+ }
610
+ function buildOverlay() {
611
+ let cocos;
612
+ if (showInteractable) {
613
+ const hidden = [toolbar, overlay, inputBlocker].filter(Boolean);
614
+ const display = hidden.map((el) => el.style.display);
615
+ try {
616
+ hidden.forEach((el) => {
617
+ el.style.display = "none";
618
+ });
619
+ interactableNodes = getInteractable();
620
+ } finally {
621
+ hidden.forEach((el, i) => {
622
+ el.style.display = display[i];
623
+ });
624
+ }
625
+ } else {
626
+ let materialize2 = function(node2) {
627
+ node2.payload = completeFacts(node2.payload);
628
+ node2.children.forEach(materialize2);
629
+ };
630
+ var materialize = materialize2;
631
+ cocos = observeCocos(targetDocument());
632
+ if (cocos) materialize2(cocos.tree);
633
+ }
634
+ clearOverlay();
635
+ if (!showInteractable && !cocos) {
636
+ console.warn("[\u4E5D\u5BAB\u6E38\u620F] inspect: \u672A\u68C0\u6D4B\u5230 Cocos Creator 2.x \u573A\u666F");
637
+ return false;
638
+ }
639
+ overlay = document.createElement("div");
640
+ overlay.setAttribute(OVERLAY_ATTR, "1");
641
+ Object.assign(overlay.style, {
642
+ position: "fixed",
643
+ inset: "0",
644
+ boxSizing: "border-box",
645
+ zIndex: Z_INDEX - 1,
646
+ pointerEvents: "none",
647
+ background: revealAll || showInteractable ? "rgba(0,0,0,0.22)" : "transparent",
648
+ transition: "background 120ms ease",
649
+ border: "2px solid rgba(134,239,172,0.62)",
650
+ boxShadow: "inset 0 0 0 1px rgba(0,0,0,0.55), inset 0 0 20px rgba(134,239,172,0.08)"
651
+ });
652
+ if (showInteractable) {
653
+ interactableNodes.forEach((node2, index) => {
654
+ const rect = rectFor(node2, 0, node2.payload.path || node2.name, true);
655
+ const badge = document.createElement("span");
656
+ badge.setAttribute(OVERLAY_ATTR, "1");
657
+ badge.textContent = String(index + 1);
658
+ Object.assign(badge.style, {
659
+ position: "absolute",
660
+ top: "0",
661
+ left: "0",
662
+ color: "#111",
663
+ background: "#86efac",
664
+ font: "11px/15px monospace",
665
+ padding: "0 3px",
666
+ pointerEvents: "none"
667
+ });
668
+ rect.appendChild(badge);
669
+ nodeElements.set(node2, rect);
670
+ overlay.appendChild(rect);
671
+ });
672
+ } else overlay.appendChild(buildElement(cocos.tree, 0, ""));
673
+ visualRects = [...nodeElements.values()].filter((el) => rectBounds.has(el));
674
+ applyPickableState();
675
+ document.documentElement.appendChild(overlay);
676
+ return true;
677
+ }
678
+ function onKeydown(event) {
679
+ if (event.key === "Escape") {
680
+ stop();
681
+ return;
682
+ }
683
+ if (event.preventDefault) event.preventDefault();
684
+ if (event.stopPropagation) event.stopPropagation();
685
+ }
686
+ function onResize() {
687
+ if (active) buildOverlay();
688
+ }
689
+ function syncSelectButton() {
690
+ if (selectButton) Object.assign(selectButton.style, active ? { background: "rgba(134,239,172,0.2)", boxShadow: "inset 0 0 0 1px rgba(134,239,172,0.95), 0 0 8px rgba(134,239,172,0.38)" } : { background: "transparent", boxShadow: "none" });
691
+ if (toolbar) toolbar.style.boxShadow = active ? "0 0 0 1px rgba(134,239,172,0.9), 0 0 14px rgba(134,239,172,0.3)" : "0 1px 6px rgba(0,0,0,0.4)";
692
+ }
693
+ function syncRevealButton() {
694
+ if (!revealButton) return;
695
+ const pressed = active && revealAll && !showInteractable;
696
+ Object.assign(revealButton.style, {
697
+ background: pressed ? "rgba(134,239,172,0.2)" : "transparent",
698
+ boxShadow: pressed ? "inset 0 0 0 1px rgba(134,239,172,0.95), 0 0 8px rgba(134,239,172,0.38)" : "none",
699
+ opacity: active ? "1" : "0.45",
700
+ cursor: active ? "pointer" : "not-allowed"
701
+ });
702
+ revealButton.title = pressed ? "\u9690\u85CF\u5168\u90E8\u77E9\u5F62\u6846\uFF1A\u6062\u590D\u521D\u59CB\u900F\u660E\u68C0\u67E5\u8499\u5C42" : "\u663E\u793A\u5168\u90E8\u77E9\u5F62\u6846\uFF1A\u538B\u6697\u9875\u9762\u5E76\u663E\u793A\u6240\u6709\u8BC6\u522B\u8FB9\u6846\uFF08\u865A\u7EBF\u6846\u662F\u7EAF\u5BB9\u5668\uFF0C\u4E0D\u6321\u9F20\u6807\uFF09";
703
+ }
704
+ function syncInteractableButton() {
705
+ if (!interactableButton) return;
706
+ const pressed = active && showInteractable;
707
+ Object.assign(interactableButton.style, {
708
+ background: pressed ? "rgba(134,239,172,0.2)" : "transparent",
709
+ boxShadow: pressed ? "inset 0 0 0 1px rgba(134,239,172,0.95), 0 0 8px rgba(134,239,172,0.38)" : "none",
710
+ opacity: active ? "1" : "0.45",
711
+ cursor: active ? "pointer" : "not-allowed"
712
+ });
713
+ interactableButton.title = pressed ? "\u9690\u85CF\u53EF\u4EA4\u4E92\u9879\uFF1A\u8FD4\u56DE\u573A\u666F\u6811" : "\u663E\u793A\u53EF\u4EA4\u4E92\u9879\uFF1A\u6846\u51FA\u5F53\u524D\u5019\u9009\uFF0C\u70B9\u51FB\u6846\u5728\u63A7\u5236\u53F0\u67E5\u770B\u8BE6\u60C5";
714
+ }
715
+ function syncDepthBadge() {
716
+ if (!depthBadge) return;
717
+ const on = active && effectiveDepth > 0;
718
+ const text = on ? "\u7A7F\u900F " + effectiveDepth : "";
719
+ if (depthBadge.textContent === text) return;
720
+ depthBadge.textContent = text;
721
+ Object.assign(depthBadge.style, {
722
+ display: on ? "block" : "none",
723
+ color: "rgba(134,239,172,0.95)",
724
+ font: "10px/16px monospace",
725
+ whiteSpace: "nowrap",
726
+ pointerEvents: "none"
727
+ });
728
+ }
729
+ function addInteractionListeners() {
730
+ window.addEventListener("pointermove", onHoverMove, true);
731
+ window.addEventListener("mousemove", onHoverMove, true);
732
+ window.addEventListener("pointerout", onHoverOut, true);
733
+ window.addEventListener("mouseout", onHoverOut, true);
734
+ window.addEventListener("pointerdown", onInspectPointerDown, true);
735
+ window.addEventListener("mousedown", onInspectPointerDown, true);
736
+ window.addEventListener("touchstart", onInspectPointerDown, true);
737
+ window.addEventListener("wheel", onWheel, { capture: true, passive: false });
738
+ }
739
+ function removeInteractionListeners() {
740
+ window.removeEventListener("pointermove", onHoverMove, true);
741
+ window.removeEventListener("mousemove", onHoverMove, true);
742
+ window.removeEventListener("pointerout", onHoverOut, true);
743
+ window.removeEventListener("mouseout", onHoverOut, true);
744
+ window.removeEventListener("pointerdown", onInspectPointerDown, true);
745
+ window.removeEventListener("mousedown", onInspectPointerDown, true);
746
+ window.removeEventListener("touchstart", onInspectPointerDown, true);
747
+ window.removeEventListener("wheel", onWheel, true);
748
+ }
749
+ function warnIfHoverUnavailable() {
750
+ try {
751
+ if (window.matchMedia && window.matchMedia("(hover: none)").matches) {
752
+ console.warn("[\u4E5D\u5BAB\u6E38\u620F] inspect: \u5F53\u524D\u9875\u9762\u5904\u5728\u89E6\u6478\u6A21\u62DF\u4E0B\uFF08DevTools \u8BBE\u5907\u6A21\u5F0F\u6216 Emulation.setTouchEmulationEnabled\uFF09\uFF0C\u7269\u7406\u9F20\u6807 hover \u4F1A\u53D8\u6210\u89E6\u6478\u4E8B\u4EF6\uFF0C\u77E9\u5F62\u6846\u65E0\u6CD5\u9AD8\u4EAE\uFF1B\u5173\u95ED\u8BBE\u5907\u6A21\u5F0F\uFF08Ctrl+Shift+M\uFF09\u5373\u53EF\u6062\u590D hover\u3002\u70B9\u51FB\u9009\u4E2D\u4E0D\u53D7\u5F71\u54CD\u3002");
753
+ }
754
+ } catch (_) {
755
+ }
756
+ }
757
+ function start() {
758
+ if (active) return true;
759
+ active = true;
760
+ installInputBlocker();
761
+ const hasCocosOverlay = buildOverlay();
762
+ previousCursor = document.documentElement.style.cursor;
763
+ document.documentElement.style.cursor = "crosshair";
764
+ window.addEventListener("keydown", onKeydown, true);
765
+ window.addEventListener("resize", onResize);
766
+ addInteractionListeners();
767
+ if (hasCocosOverlay) warnIfHoverUnavailable();
768
+ syncSelectButton();
769
+ syncRevealButton();
770
+ syncInteractableButton();
771
+ syncDepthBadge();
772
+ return active;
773
+ }
774
+ function stop() {
775
+ if (!active) return;
776
+ active = false;
777
+ clearOverlay();
778
+ removeInputBlocker();
779
+ revealAll = false;
780
+ showInteractable = false;
781
+ interactableNodes = [];
782
+ pickDepth = 0;
783
+ effectiveDepth = 0;
784
+ if (previousCursor !== null) {
785
+ document.documentElement.style.cursor = previousCursor;
786
+ previousCursor = null;
787
+ }
788
+ window.removeEventListener("keydown", onKeydown, true);
789
+ window.removeEventListener("resize", onResize);
790
+ removeInteractionListeners();
791
+ syncSelectButton();
792
+ syncRevealButton();
793
+ syncInteractableButton();
794
+ syncDepthBadge();
795
+ }
796
+ function iconButton(svg, title) {
797
+ const button = document.createElement("div");
798
+ button.innerHTML = svg;
799
+ button.title = title;
800
+ button.setAttribute("data-cocos-runtime-no-drag", "1");
801
+ Object.assign(button.style, {
802
+ width: "20px",
803
+ height: "20px",
804
+ display: "flex",
805
+ alignItems: "center",
806
+ justifyContent: "center",
807
+ borderRadius: "4px",
808
+ cursor: "pointer",
809
+ background: "transparent"
810
+ });
811
+ button.addEventListener("mouseenter", () => {
812
+ if (button === selectButton) {
813
+ if (!active) button.style.background = "rgba(255,255,255,0.15)";
814
+ return;
815
+ }
816
+ if (button === revealButton) {
817
+ if (active && (!revealAll || showInteractable)) button.style.background = "rgba(255,255,255,0.15)";
818
+ return;
819
+ }
820
+ if (button === interactableButton) {
821
+ if (active && !showInteractable) button.style.background = "rgba(255,255,255,0.15)";
822
+ return;
823
+ }
824
+ button.style.background = "rgba(255,255,255,0.15)";
825
+ });
826
+ button.addEventListener("mouseleave", () => {
827
+ if (button === selectButton) syncSelectButton();
828
+ else if (button === revealButton) syncRevealButton();
829
+ else if (button === interactableButton) syncInteractableButton();
830
+ else button.style.background = "transparent";
831
+ });
832
+ return button;
833
+ }
834
+ function isToolbarButton(target, root) {
835
+ for (let el = target; el && el !== root; el = el.parentElement) {
836
+ if (el.getAttribute && el.getAttribute("data-cocos-runtime-no-drag") === "1") return true;
837
+ }
838
+ return false;
839
+ }
840
+ function makeDraggable(root) {
841
+ let pointerSeenUntil = 0;
842
+ let suppressClickUntil = 0;
843
+ root.addEventListener("click", (event) => {
844
+ if (Date.now() >= suppressClickUntil) return;
845
+ suppressClickUntil = 0;
846
+ if (event.preventDefault) event.preventDefault();
847
+ if (event.stopPropagation) event.stopPropagation();
848
+ }, true);
849
+ function onDown(event) {
850
+ if (event.type === "mousedown" && Date.now() < pointerSeenUntil) return;
851
+ if (event.type === "touchstart" && Date.now() < pointerSeenUntil) return;
852
+ if (event.type === "pointerdown" || event.type === "touchstart") pointerSeenUntil = Date.now() + 500;
853
+ if (event.button !== void 0 && event.button !== 0) return;
854
+ const fromButton = isToolbarButton(event.target, root);
855
+ if (!fromButton) {
856
+ event.preventDefault();
857
+ event.stopPropagation();
858
+ }
859
+ const rect = root.getBoundingClientRect();
860
+ const start2 = eventPoint(event);
861
+ const startX = start2.x, startY = start2.y;
862
+ const dx = startX - rect.left, dy = startY - rect.top;
863
+ const maxX = Math.max(0, window.innerWidth - rect.width);
864
+ const maxY = Math.max(0, window.innerHeight - rect.height);
865
+ let dragging = false;
866
+ root.style.cursor = "grabbing";
867
+ function beginDrag() {
868
+ dragging = true;
869
+ root.style.right = "auto";
870
+ root.style.left = Math.min(Math.max(0, rect.left), maxX) + "px";
871
+ root.style.top = Math.min(Math.max(0, rect.top), maxY) + "px";
872
+ if (event.type === "pointerdown" && root.setPointerCapture && event.pointerId !== void 0) {
873
+ try {
874
+ root.setPointerCapture(event.pointerId);
875
+ } catch (_) {
876
+ }
877
+ }
878
+ }
879
+ if (!fromButton) beginDrag();
880
+ function onMove(move) {
881
+ const point = eventPoint(move);
882
+ if (!dragging && Math.hypot(point.x - startX, point.y - startY) < 4) return;
883
+ if (!dragging) beginDrag();
884
+ if (move.preventDefault) move.preventDefault();
885
+ if (move.stopPropagation) move.stopPropagation();
886
+ const x = Math.min(Math.max(0, point.x - dx), maxX);
887
+ const y = Math.min(Math.max(0, point.y - dy), maxY);
888
+ root.style.left = x + "px";
889
+ root.style.top = y + "px";
890
+ }
891
+ function onUp() {
892
+ root.style.cursor = "move";
893
+ if (dragging && fromButton) {
894
+ suppressClickUntil = Date.now() + 300;
895
+ }
896
+ window.removeEventListener("pointermove", onMove, true);
897
+ window.removeEventListener("mousemove", onMove, true);
898
+ window.removeEventListener("touchmove", onMove, true);
899
+ window.removeEventListener("pointerup", onUp, true);
900
+ window.removeEventListener("mouseup", onUp, true);
901
+ window.removeEventListener("touchend", onUp, true);
902
+ window.removeEventListener("touchcancel", onUp, true);
903
+ window.removeEventListener("pointercancel", onUp, true);
904
+ }
905
+ window.addEventListener("pointermove", onMove, true);
906
+ window.addEventListener("mousemove", onMove, true);
907
+ window.addEventListener("touchmove", onMove, true);
908
+ window.addEventListener("pointerup", onUp, true);
909
+ window.addEventListener("mouseup", onUp, true);
910
+ window.addEventListener("touchend", onUp, true);
911
+ window.addEventListener("touchcancel", onUp, true);
912
+ window.addEventListener("pointercancel", onUp, true);
913
+ }
914
+ root.addEventListener("pointerdown", onDown, true);
915
+ root.addEventListener("mousedown", onDown, true);
916
+ root.addEventListener("touchstart", onDown, true);
917
+ }
918
+ function mountToolbar() {
919
+ if (toolbar && toolbar.isConnected !== false) return toolbar;
920
+ toolbar = null;
921
+ const parent = document.documentElement || document.body;
922
+ if (!parent) return null;
923
+ const root = document.createElement("div");
924
+ root.setAttribute(OVERLAY_ATTR, "1");
925
+ root.setAttribute("data-cocos-runtime-chrome", "1");
926
+ Object.assign(root.style, {
927
+ position: "fixed",
928
+ top: "8px",
929
+ right: "8px",
930
+ zIndex: Z_INDEX,
931
+ cursor: "move",
932
+ touchAction: "none",
933
+ WebkitTapHighlightColor: "transparent",
934
+ display: "flex",
935
+ alignItems: "center",
936
+ gap: "2px",
937
+ padding: "3px 4px",
938
+ borderRadius: "6px",
939
+ background: "rgba(30,30,30,0.88)",
940
+ boxShadow: "0 1px 6px rgba(0,0,0,0.4)",
941
+ fontFamily: "sans-serif",
942
+ userSelect: "none"
943
+ });
944
+ const grip = document.createElement("div");
945
+ grip.innerHTML = ICONS.drag;
946
+ grip.title = "\u62D6\u62FD\u79FB\u52A8\u5DE5\u5177\u6761";
947
+ Object.assign(grip.style, { cursor: "move", display: "flex", alignItems: "center", padding: "0 2px" });
948
+ makeDraggable(root);
949
+ selectButton = iconButton(ICONS.select, "\u9009\u62E9\u8282\u70B9\uFF1A\u70B9\u51FB\u6846\u9009\u5E76\u6253\u5370\u5B8C\u6574\u4FE1\u606F\uFF1B\u540C\u4E00\u70B9\u8FDE\u7EED\u70B9\u51FB\u6216 Alt + \u70B9\u51FB\u9010\u5C42\u7A7F\u900F\u5230\u4E0B\u5C42\u8282\u70B9\uFF0CAlt + \u6EDA\u8F6E\u8FDE\u7EED\u8C03\u8282\u7A7F\u900F\u6DF1\u5EA6\uFF08Esc \u9000\u51FA\uFF09");
950
+ selectButton.addEventListener("click", () => active ? stop() : start());
951
+ revealButton = iconButton(ICONS.reveal, "\u663E\u793A\u5168\u90E8\u77E9\u5F62\u6846\uFF1A\u538B\u6697\u9875\u9762\u5E76\u663E\u793A\u6240\u6709\u8BC6\u522B\u8FB9\u6846\uFF08\u865A\u7EBF\u6846\u662F\u7EAF\u5BB9\u5668\uFF0C\u4E0D\u6321\u9F20\u6807\uFF09");
952
+ revealButton.addEventListener("click", () => {
953
+ if (!active) return;
954
+ if (showInteractable) {
955
+ showInteractable = false;
956
+ revealAll = true;
957
+ } else revealAll = !revealAll;
958
+ buildOverlay();
959
+ syncRevealButton();
960
+ syncInteractableButton();
961
+ });
962
+ interactableButton = iconButton(ICONS.interactable, "\u663E\u793A\u53EF\u4EA4\u4E92\u9879\uFF1A\u6846\u51FA\u5F53\u524D\u5019\u9009\uFF0C\u70B9\u51FB\u6846\u5728\u63A7\u5236\u53F0\u67E5\u770B\u8BE6\u60C5");
963
+ interactableButton.addEventListener("click", () => {
964
+ if (!active) return;
965
+ showInteractable = !showInteractable;
966
+ try {
967
+ buildOverlay();
968
+ } catch (error) {
969
+ showInteractable = false;
970
+ console.error("[\u4E5D\u5BAB\u6E38\u620F] \u65E0\u6CD5\u8BFB\u53D6\u53EF\u4EA4\u4E92\u9879", error);
971
+ syncInteractableButton();
972
+ return;
973
+ }
974
+ if (showInteractable) {
975
+ console.groupCollapsed("[\u4E5D\u5BAB\u6E38\u620F] dumpInteractable: " + interactableNodes.length + " \u9879");
976
+ console.dir(interactableNodes, { depth: 3, colors: true });
977
+ console.groupEnd();
978
+ }
979
+ syncRevealButton();
980
+ syncInteractableButton();
981
+ });
982
+ const refreshButton = iconButton(ICONS.refresh, "\u5237\u65B0\uFF1A\u6309\u5F53\u524D\u573A\u666F\u91CD\u5EFA\u8499\u5C42");
983
+ refreshButton.addEventListener("click", () => {
984
+ if (active) buildOverlay();
985
+ });
986
+ root.appendChild(grip);
987
+ root.appendChild(selectButton);
988
+ root.appendChild(revealButton);
989
+ root.appendChild(interactableButton);
990
+ root.appendChild(refreshButton);
991
+ depthBadge = document.createElement("div");
992
+ depthBadge.setAttribute(OVERLAY_ATTR, "1");
993
+ depthBadge.style.display = "none";
994
+ root.appendChild(depthBadge);
995
+ parent.appendChild(root);
996
+ toolbar = root;
997
+ syncRevealButton();
998
+ syncInteractableButton();
999
+ return toolbar;
1000
+ }
1001
+ return {
1002
+ mountToolbar,
1003
+ hideToolbar() {
1004
+ stop();
1005
+ if (toolbar) toolbar.remove();
1006
+ toolbar = null;
1007
+ },
1008
+ isActive: () => active
1009
+ };
1010
+ }
1011
+
1012
+ // src/dom.js
1013
+ function editable(el) {
1014
+ return !el.disabled && !el.readOnly && !(el.matches && el.matches(":disabled")) && el.getAttribute("aria-disabled") !== "true" && !(el.closest && el.closest("[inert]")) && (el.isContentEditable || el.tagName === "TEXTAREA" || el.tagName === "INPUT" && ["text", "search", "email", "url", "tel", "password", "number"].includes(el.type));
1015
+ }
1016
+ var interactive = /* @__PURE__ */ new Set(["A", "BUTTON", "INPUT", "TEXTAREA", "SELECT", "SUMMARY"]);
1017
+ function visible(el) {
1018
+ const getComputedStyle = el.ownerDocument.defaultView.getComputedStyle.bind(el.ownerDocument.defaultView);
1019
+ for (let parent = el.parentElement; parent; parent = parent.parentElement) {
1020
+ const style = getComputedStyle(parent);
1021
+ if (style.display === "none" || style.visibility === "hidden" || style.visibility === "collapse" || style.opacity === "0" || parent.hidden) return false;
1022
+ }
1023
+ const r = el.getBoundingClientRect();
1024
+ const s = getComputedStyle(el);
1025
+ return r.width > 0 && r.height > 0 && !el.hidden && s.display !== "none" && !["hidden", "collapse"].includes(s.visibility) && s.opacity !== "0";
1026
+ }
1027
+ function node(el) {
1028
+ const owner = el.ownerDocument.defaultView;
1029
+ const innerWidth = owner.innerWidth, innerHeight = owner.innerHeight;
1030
+ function frameFacts() {
1031
+ if (el.tagName !== "IFRAME") return {};
1032
+ let doc;
1033
+ try {
1034
+ doc = el.contentDocument;
1035
+ } catch (_) {
1036
+ }
1037
+ return { frame_exists: true, frame_accessible: !!doc, frame_ready: !!doc && doc.readyState !== "loading" };
1038
+ }
1039
+ const r = el.getBoundingClientRect();
1040
+ const text = (["INPUT", "TEXTAREA"].includes(el.tagName) ? String(el.value || "") : (el.getAttribute("aria-label") || (el.tagName !== "HTML" ? el.innerText : "") || "").trim()).slice(0, 500);
1041
+ const editableRoot = el.isContentEditable && !(el.parentElement && el.parentElement.isContentEditable);
1042
+ const clickable = interactive.has(el.tagName) || editableRoot || typeof el.onclick === "function" || el.getAttribute("role") === "button";
1043
+ const inViewport = r.left < innerWidth && r.top < innerHeight && r.left + r.width > 0 && r.top + r.height > 0;
1044
+ const shown = visible(el) && inViewport;
1045
+ const testId = el.getAttribute("data-testid");
1046
+ const name = el.id || testId || el.tagName.toLowerCase();
1047
+ const enabled = !el.disabled && !(el.matches && el.matches(":disabled")) && el.getAttribute("aria-disabled") !== "true" && !(el.closest && el.closest("[inert]"));
1048
+ const inputType = el.tagName === "INPUT" ? String(el.type || "text") : "";
1049
+ const label = (el.getAttribute("aria-label") || Array.from(el.labels || []).map((label2) => label2.innerText || "").join(" ")).trim().slice(0, 500);
1050
+ const result = { name, payload: {
1051
+ ...frameFacts(),
1052
+ name,
1053
+ anchorPoint: [0.5, 0.5],
1054
+ editable: editable(el),
1055
+ layer: "web",
1056
+ id: el.id || testId || "",
1057
+ type: el.getAttribute("role") || el.tagName,
1058
+ tag: el.tagName,
1059
+ input_type: inputType,
1060
+ html_name: el.getAttribute("name") || "",
1061
+ role: el.getAttribute("role") || "",
1062
+ label,
1063
+ placeholder: el.getAttribute("placeholder") || "",
1064
+ readonly: !!el.readOnly,
1065
+ ...["checkbox", "radio"].includes(inputType) ? { checked: !!el.checked } : ["true", "false"].includes(el.getAttribute("aria-checked")) ? { checked: el.getAttribute("aria-checked") === "true" } : {},
1066
+ text,
1067
+ in_viewport: inViewport,
1068
+ visible: shown,
1069
+ enabled,
1070
+ clickable,
1071
+ interactable: clickable && shown && enabled,
1072
+ automation_candidate: !!(clickable || testId) && shown && enabled,
1073
+ candidate_reason: testId ? "test_id" : clickable ? "semantic_dom" : "structural_anchor",
1074
+ pos: [(r.left + r.width / 2) / innerWidth, (r.top + r.height / 2) / innerHeight],
1075
+ size: [r.width / innerWidth, r.height / innerHeight],
1076
+ source: "dom_runtime",
1077
+ confidence: "high"
1078
+ }, children: [] };
1079
+ Object.defineProperty(result, "__cocos_runtime_element", { value: el });
1080
+ Object.defineProperty(result, "__cocos_runtime_document", { value: el.ownerDocument });
1081
+ return result;
1082
+ }
1083
+ function dumpDocument(doc, observeCocos, frame = "main") {
1084
+ const root = node(doc.documentElement);
1085
+ const win = doc.defaultView;
1086
+ const frames = Array.from(doc.querySelectorAll ? doc.querySelectorAll("iframe") : []);
1087
+ root.payload.viewport = { width: win.innerWidth, height: win.innerHeight, device_scale_factor: win.devicePixelRatio };
1088
+ function appendChildren(parentEl, parentNode) {
1089
+ Array.from(parentEl.children).forEach(function(el) {
1090
+ if (el.hasAttribute && el.hasAttribute("data-cocos-runtime-overlay")) return;
1091
+ if (["HEAD", "SCRIPT", "STYLE", "LINK", "META", "TITLE"].includes(el.tagName) || el.id === "__vconsole") return;
1092
+ const child = node(el);
1093
+ appendChildren(el, child);
1094
+ parentNode.children.push(child);
1095
+ if (el.tagName !== "IFRAME" || !child.payload.frame_accessible) return;
1096
+ const innerDoc = el.contentDocument;
1097
+ if (!innerDoc || !innerDoc.documentElement) return;
1098
+ let key = el.id ? "id=" + el.id : el.getAttribute("name") ? "name=" + el.getAttribute("name") : "index=" + frames.indexOf(el);
1099
+ if (frames.filter((other) => el.id ? other.id === el.id : el.getAttribute("name") && other.getAttribute("name") === el.getAttribute("name")).length > 1) key += "&index=" + frames.indexOf(el);
1100
+ const tree = dumpDocument(innerDoc, observeCocos, frame + "/" + encodeURIComponent(key));
1101
+ const rect = el.getBoundingClientRect();
1102
+ const sx = el.offsetWidth ? rect.width / el.offsetWidth : 1;
1103
+ const sy = el.offsetHeight ? rect.height / el.offsetHeight : 1;
1104
+ const outer = doc.defaultView, inner = innerDoc.defaultView;
1105
+ function rebase(n) {
1106
+ const p = n.payload;
1107
+ mapField(p, "pos", (pos) => pos && [(rect.left + el.clientLeft * sx + pos[0] * inner.innerWidth * sx) / outer.innerWidth, (rect.top + el.clientTop * sy + pos[1] * inner.innerHeight * sy) / outer.innerHeight]);
1108
+ mapField(p, "size", (size) => size && [size[0] * inner.innerWidth * sx / outer.innerWidth, size[1] * inner.innerHeight * sy / outer.innerHeight]);
1109
+ mapField(p, "visible", (visible2) => child.payload.visible && visible2);
1110
+ mapField(p, "interactable", (interactable) => p.visible && interactable);
1111
+ mapField(p, "automation_candidate", (candidate) => p.visible && candidate);
1112
+ n.children.forEach(rebase);
1113
+ }
1114
+ rebase(tree);
1115
+ child.children.push(tree);
1116
+ });
1117
+ }
1118
+ appendChildren(doc.documentElement, root);
1119
+ const cocos = observeCocos && observeCocos(doc);
1120
+ if (cocos) {
1121
+ root.children.push(cocos.tree);
1122
+ root.payload._hybrid_scene_epoch = cocos.scene_epoch;
1123
+ root.payload.cocos_version = cocos.version;
1124
+ }
1125
+ function mark(n) {
1126
+ if (n.payload.frame === void 0) n.payload.frame = frame;
1127
+ n.children.forEach(mark);
1128
+ }
1129
+ mark(root);
1130
+ return root;
1131
+ }
1132
+
1133
+ // src/snapshot.js
1134
+ function captureScene(observeCocos) {
1135
+ const tree = dumpDocument(document, observeCocos);
1136
+ const flat = [], byLive = /* @__PURE__ */ new Map(), byNode = /* @__PURE__ */ new Map(), byID = /* @__PURE__ */ new Map(), byPath = /* @__PURE__ */ new Map();
1137
+ const documents = /* @__PURE__ */ new Map();
1138
+ function walk(node2, path, parent = null, depth = 0) {
1139
+ const doc = node2.__cocos_runtime_document;
1140
+ if (!documents.has(doc)) documents.set(doc, { document: doc, tree: null });
1141
+ if (node2.payload.layer === "game" && (!parent || parent.payload.layer !== "game")) {
1142
+ path = node2.name;
1143
+ documents.get(doc).tree = node2;
1144
+ documents.get(doc).geometry = node2.__cocos_runtime_geometry;
1145
+ }
1146
+ const item = { node: node2, path, parent, doc, depth, end: 0 };
1147
+ flat.push(item);
1148
+ byNode.set(node2, item);
1149
+ byLive.set(node2.__cocos_runtime_cocos_node || node2.__cocos_runtime_element, item);
1150
+ for (const [index, key] of [[byID, node2.payload.id], [byPath, path]]) {
1151
+ if (!index.has(key)) index.set(key, []);
1152
+ index.get(key).push(item);
1153
+ }
1154
+ const siblings = /* @__PURE__ */ new Map();
1155
+ for (const child of node2.children) {
1156
+ const layer = child.payload.layer;
1157
+ if (!siblings.has(layer)) siblings.set(layer, /* @__PURE__ */ new Map());
1158
+ const names = siblings.get(layer);
1159
+ if (!names.has(child.name)) names.set(child.name, { total: 0, index: 0 });
1160
+ names.get(child.name).total++;
1161
+ }
1162
+ for (const child of node2.children) {
1163
+ const group = siblings.get(child.payload.layer).get(child.name);
1164
+ const segment = group.total > 1 ? child.name + "[" + ++group.index + "]" : child.name;
1165
+ walk(child, path + "/" + segment, node2, depth + 1);
1166
+ }
1167
+ item.end = flat.length;
1168
+ }
1169
+ walk(tree, tree.name);
1170
+ return { tree, flat, byLive, byNode, byID, byPath, documents, selectors: /* @__PURE__ */ new Map() };
1171
+ }
1172
+ function bindInputOwners(snap) {
1173
+ if (snap.inputOwnersBound) return;
1174
+ snap.inputOwnersBound = true;
1175
+ if (!snap.flat.some((item) => item.node.payload.layer === "web" && ["INPUT", "TEXTAREA"].includes(item.node.payload.tag))) return;
1176
+ for (const item of snap.flat) {
1177
+ const node2 = item.node, cc = item.doc.defaultView.cc;
1178
+ if (!node2.__cocos_runtime_cocos_node || typeof cc.EditBox !== "function") continue;
1179
+ const edit = node2.__cocos_runtime_components().find((component) => component instanceof cc.EditBox);
1180
+ const input = edit && edit._impl && snap.byLive.get(edit._impl._elem);
1181
+ if (input) input.node.payload.input_owner = { layer: "game", frame: node2.payload.frame, path: item.path };
1182
+ }
1183
+ }
1184
+
1185
+ // src/selectors.js
1186
+ function isStableTextValue(value) {
1187
+ const text = String(value || "").trim();
1188
+ return !!text && !(/\d/.test(text) && !/\p{L}/u.test(text));
1189
+ }
1190
+ var queryFields = /* @__PURE__ */ new Set(["layer", "frame", "id", "name", "type", "text", "icon", "path", "component", "ancestor", "child_icon", "child_text", "parent_icon", "tag", "input_type", "html_name", "role", "label", "placeholder"]);
1191
+ var booleanFields = /* @__PURE__ */ new Set(["visible", "enabled", "active", "clickable", "interactable", "editable", "readonly", "checked"]);
1192
+ var pocoAttributes = [
1193
+ "layer",
1194
+ "frame",
1195
+ "id",
1196
+ "name",
1197
+ "type",
1198
+ "text",
1199
+ "icon",
1200
+ "path",
1201
+ "tag",
1202
+ "input_type",
1203
+ "html_name",
1204
+ "role",
1205
+ "label",
1206
+ "placeholder",
1207
+ "visible",
1208
+ "enabled",
1209
+ "active",
1210
+ "clickable",
1211
+ "interactable",
1212
+ "editable",
1213
+ "readonly",
1214
+ "checked",
1215
+ "pos",
1216
+ "size",
1217
+ "anchorPoint",
1218
+ "components"
1219
+ ];
1220
+ var structural = /* @__PURE__ */ new Set(["layer", "frame", "id", "name", "path", "ancestor", "tag"]);
1221
+ var fail = (code) => {
1222
+ throw new Error(code);
1223
+ };
1224
+ function childMatches(node2, field, value) {
1225
+ return !!node2 && node2.children.some((child) => child.payload[field] === value && child.payload.visible);
1226
+ }
1227
+ function matcher(query) {
1228
+ const keys = Object.keys(query).sort((a, b) => Number(structural.has(b)) - Number(structural.has(a)));
1229
+ return (item) => {
1230
+ const p = item.node.payload;
1231
+ for (const key of keys) {
1232
+ if (key === "component") {
1233
+ if (!(p.components || []).includes(query[key])) return false;
1234
+ } else if (key === "ancestor") {
1235
+ if (!item.path.split("/").slice(0, -1).includes(query[key])) return false;
1236
+ } else if (key === "child_icon" || key === "child_text") {
1237
+ if (!childMatches(item.node, key.slice(6), query[key])) return false;
1238
+ } else if (key === "parent_icon") {
1239
+ if (!childMatches(item.parent, "icon", query[key])) return false;
1240
+ } else if ((key === "path" ? item.path : p[key]) !== query[key]) return false;
1241
+ }
1242
+ return true;
1243
+ };
1244
+ }
1245
+ function pool(snap, query) {
1246
+ return query.id ? snap.byID.get(query.id) || [] : query.path ? snap.byPath.get(query.path) || [] : snap.flat;
1247
+ }
1248
+ function select(snap, query = {}) {
1249
+ for (const key of Object.keys(query)) if (!queryFields.has(key)) fail("QUERY_FIELD_UNSUPPORTED");
1250
+ return pool(snap, query).filter(matcher(query));
1251
+ }
1252
+ function pocoAttributesOf(item, fields = pocoAttributes) {
1253
+ const result = {};
1254
+ for (const key of fields) {
1255
+ const value = key === "path" ? item.path : item.node.payload[key];
1256
+ if (value !== void 0) result[key] = value;
1257
+ }
1258
+ return result;
1259
+ }
1260
+ function selectPoco(snap, query) {
1261
+ if (!query || typeof query !== "object" || Array.isArray(query)) fail("INVALID_QUERY");
1262
+ for (const [key, value] of Object.entries(query)) {
1263
+ if (queryFields.has(key) ? typeof value !== "string" : !booleanFields.has(key) || typeof value !== "boolean") fail("INVALID_QUERY");
1264
+ if (key === "layer" && value !== "game" && value !== "web") fail("INVALID_QUERY");
1265
+ }
1266
+ const matches = matcher(query);
1267
+ return pool(snap, query).filter((item) => matches(item) && item.node.payload.visible === true);
1268
+ }
1269
+ function selectorFor(item, snap) {
1270
+ if (snap.selectors.has(item)) return snap.selectors.get(item);
1271
+ const p = item.node.payload, scope = { layer: p.layer, frame: p.frame };
1272
+ const candidates = p.id ? [{ ...scope, id: p.id }] : [];
1273
+ if (p.layer === "web") {
1274
+ for (const field of ["html_name", "label", "placeholder"]) {
1275
+ if (p[field]) candidates.push({ ...scope, tag: p.tag, [field]: p[field] });
1276
+ }
1277
+ if (p.input_type) candidates.push({ ...scope, tag: p.tag, input_type: p.input_type });
1278
+ if (!p.editable && isStableTextValue(p.text)) candidates.push({ ...scope, type: p.type, text: p.text });
1279
+ }
1280
+ candidates.push({ ...scope, path: item.path });
1281
+ let selector = candidates.find((query) => select(snap, query).length === 1);
1282
+ if (!selector) for (const child of item.node.children) {
1283
+ if (!child.payload.visible) continue;
1284
+ const related = [];
1285
+ if (child.payload.icon) related.push({ ...scope, path: item.path, child_icon: child.payload.icon });
1286
+ if (!child.payload.editable && isStableTextValue(child.payload.text)) related.push({ ...scope, path: item.path, child_text: child.payload.text });
1287
+ selector = related.find((query) => select(snap, query).length === 1);
1288
+ if (selector) break;
1289
+ }
1290
+ const value = { selector: selector || { ...scope, path: item.path }, selector_unique: !!selector };
1291
+ snap.selectors.set(item, value);
1292
+ return value;
1293
+ }
1294
+ function describeItem(item, snap) {
1295
+ const p = item.node.payload;
1296
+ return {
1297
+ layer: p.layer,
1298
+ frame: p.frame,
1299
+ name: p.name,
1300
+ id: p.id,
1301
+ type: p.type,
1302
+ text: p.text,
1303
+ icon: p.icon || "",
1304
+ tag: p.tag || "",
1305
+ input_type: p.input_type || "",
1306
+ html_name: p.html_name || "",
1307
+ role: p.role || "",
1308
+ label: p.label || "",
1309
+ placeholder: p.placeholder || "",
1310
+ editable: !!p.editable,
1311
+ ...typeof p.checked === "boolean" ? { checked: p.checked } : {},
1312
+ path: item.path,
1313
+ visible: p.visible,
1314
+ enabled: p.enabled,
1315
+ interactive: !!p.clickable,
1316
+ components: p.components || [],
1317
+ pos: p.pos,
1318
+ size: p.size,
1319
+ bounds_quality: p.bounds_quality,
1320
+ ...selectorFor(item, snap)
1321
+ };
1322
+ }
1323
+ function validateTarget(target) {
1324
+ if (!target || typeof target !== "object" || Array.isArray(target) || !Object.keys(target).length || Object.entries(target).some(([key, value]) => !queryFields.has(key) || typeof value !== "string" || !value.trim() || key === "layer" && !["game", "web"].includes(value))) fail("INVALID_TARGET");
1325
+ }
1326
+ function scoped(snap, target) {
1327
+ if (target === void 0) return snap.flat;
1328
+ validateTarget(target);
1329
+ const roots = select(snap, target);
1330
+ if (roots.length !== 1) fail("TARGET_NOT_UNIQUE: " + roots.length);
1331
+ const root = roots[0];
1332
+ return snap.flat.slice(snap.flat.indexOf(root), root.end);
1333
+ }
1334
+
1335
+ // src/input.js
1336
+ function cocosViewPoint(win, cc, nx, ny, rect) {
1337
+ const view = cc && cc.view;
1338
+ if (!view || typeof view._convertMouseToLocationInView !== "function") return null;
1339
+ const point = { x: nx * (win.innerWidth || 1), y: ny * (win.innerHeight || 1) };
1340
+ try {
1341
+ view._convertMouseToLocationInView(point, rect);
1342
+ } catch (_) {
1343
+ return null;
1344
+ }
1345
+ if (!Number.isFinite(point.x) || !Number.isFinite(point.y)) return null;
1346
+ return cc.v2 ? cc.v2(point.x, point.y) : point;
1347
+ }
1348
+ function cocosHitTest(node2, viewPoint, listener = null) {
1349
+ if (!node2 || !viewPoint || typeof node2._hitTest !== "function") return null;
1350
+ listener = listener || (effectiveInputListener(node2._touchListener) ? node2._touchListener : node2._mouseListener) || null;
1351
+ try {
1352
+ return !!node2._hitTest(viewPoint, listener);
1353
+ } catch (_) {
1354
+ return null;
1355
+ }
1356
+ }
1357
+ function capturesScrollGesture(node2, hit, cc, distance, point, componentsOf2) {
1358
+ if (!(distance > 7)) return false;
1359
+ if (!node2 || !hit || typeof cc.ScrollView !== "function") return false;
1360
+ if (!effectiveInputListener(hit._touchListener, cc) || cocosHitTest(hit, point, hit._touchListener) !== true) return false;
1361
+ const scroll = componentsOf2(node2).find((component) => component instanceof cc.ScrollView && component.enabled !== false && component.enabledInHierarchy !== false && component.content && component.cancelInnerEvents === true);
1362
+ if (!scroll || !effectiveInputListener(node2._touchListener, cc)) return false;
1363
+ const table = node2._capturingListeners && node2._capturingListeners._callbackTable;
1364
+ const captures = (type, callback) => table && table[type] && Array.isArray(table[type].callbackInfos) && table[type].callbackInfos.some((info) => info.target === scroll && info.callback === callback);
1365
+ if (!captures("touchstart", scroll._onTouchBegan) || !captures("touchmove", scroll._onTouchMoved)) return false;
1366
+ for (let current = hit; current && current !== node2; current = current.parent) {
1367
+ if (typeof cc.ViewGroup === "function" && componentsOf2(current).some((component) => component instanceof cc.ViewGroup)) return false;
1368
+ if (current.parent === node2) return true;
1369
+ }
1370
+ return false;
1371
+ }
1372
+ function createCocosInputIndex(tree, cc) {
1373
+ const ordered = [];
1374
+ function visit(node2, active = true) {
1375
+ const live = node2.__cocos_runtime_cocos_node;
1376
+ active = active && (node2.payload || {}).active !== false && !(live && typeof cc.isValid === "function" && !cc.isValid(live, true));
1377
+ if (!active) return;
1378
+ (node2.children || []).map((child, index) => ({ child, index })).sort((a, b) => ((b.child.__cocos_runtime_cocos_node || {})._localZOrder || 0) - ((a.child.__cocos_runtime_cocos_node || {})._localZOrder || 0) || b.index - a.index).forEach((entry) => visit(entry.child, active));
1379
+ if (live && (effectiveInputListener(live._touchListener, cc) || effectiveInputListener(live._mouseListener, cc))) ordered.push(node2);
1380
+ }
1381
+ visit(tree);
1382
+ return ordered;
1383
+ }
1384
+ function resolveCocosInputAt(cc, nx, ny, viewPoint, index) {
1385
+ for (const node2 of index) {
1386
+ const live = node2.__cocos_runtime_cocos_node, payload = node2.payload || {};
1387
+ const listener = effectiveInputListener(live._touchListener, cc) ? live._touchListener : effectiveInputListener(live._mouseListener, cc) ? live._mouseListener : null;
1388
+ if (!listener) continue;
1389
+ const hit = cocosHitTest(live, viewPoint, listener);
1390
+ if (hit === true || hit === null && payload.pos && payload.size && Math.abs(nx - payload.pos[0]) <= payload.size[0] / 2 && Math.abs(ny - payload.pos[1]) <= payload.size[1] / 2) return node2;
1391
+ }
1392
+ return null;
1393
+ }
1394
+
1395
+ // src/input-points.js
1396
+ var fail2 = (code) => {
1397
+ throw new Error(code);
1398
+ };
1399
+ function localPoint(doc, x, y, info, verify = true) {
1400
+ if (!info.frames) {
1401
+ info.frames = [];
1402
+ for (let win = doc.defaultView; win !== window; win = win.parent) {
1403
+ const frame = win.frameElement;
1404
+ if (!frame) fail2("FRAME_INACCESSIBLE");
1405
+ const box = frame.getBoundingClientRect();
1406
+ const sx = box.width / frame.offsetWidth, sy = box.height / frame.offsetHeight;
1407
+ if (!(sx > 0 && sy > 0)) fail2("BOUNDS_UNAVAILABLE");
1408
+ info.frames.unshift({ frame, box, sx, sy });
1409
+ }
1410
+ }
1411
+ let current = document;
1412
+ for (const { frame, box, sx, sy } of info.frames) {
1413
+ if (verify && current.elementFromPoint(x, y) !== frame) fail2("TARGET_OCCLUDED");
1414
+ x = (x - box.left) / sx - frame.clientLeft;
1415
+ y = (y - box.top) / sy - frame.clientTop;
1416
+ current = frame.contentDocument;
1417
+ }
1418
+ return { x, y };
1419
+ }
1420
+ function inputPoint(item, snap, focus, gesture) {
1421
+ const p = item.node.payload, live = item.node.__cocos_runtime_cocos_node;
1422
+ if (!p.visible || !p.clickable) fail2("TARGET_NOT_INTERACTIVE");
1423
+ if (p.layer === "web" && !p.enabled) fail2("TARGET_DISABLED");
1424
+ const doc = item.doc, win = doc.defaultView, cc = win.cc;
1425
+ const info = snap.documents.get(doc);
1426
+ if (p.layer === "game" && !p.enabled) fail2("TARGET_DISABLED");
1427
+ if (!p.pos || !p.size) fail2("BOUNDS_UNAVAILABLE");
1428
+ const pointForFocus = focus && [
1429
+ p.pos[0] + p.size[0] * (focus[0] - 0.5),
1430
+ p.pos[1] + p.size[1] * (focus[1] - 0.5)
1431
+ ];
1432
+ if (p.layer === "web") {
1433
+ const [nx, ny] = pointForFocus || p.pos;
1434
+ if (nx < 0 || nx >= 1 || ny < 0 || ny >= 1) fail2("BOUNDS_UNAVAILABLE");
1435
+ const local = localPoint(doc, nx * window.innerWidth, ny * window.innerHeight, info);
1436
+ const element = doc.elementFromPoint(local.x, local.y);
1437
+ const target = item.node.__cocos_runtime_element;
1438
+ if (!element || !(target === element || target.contains(element))) fail2("TARGET_OCCLUDED");
1439
+ return { x: nx * window.innerWidth, y: ny * window.innerHeight };
1440
+ }
1441
+ const [cx, cy] = p.pos, [width, height] = p.size;
1442
+ const left = Math.max(0, cx - width / 2), right = Math.min(1, cx + width / 2);
1443
+ const top = Math.max(0, cy - height / 2), bottom = Math.min(1, cy + height / 2);
1444
+ if (!(right > left && bottom > top)) fail2("BOUNDS_UNAVAILABLE");
1445
+ const points = focus ? [pointForFocus] : [[cx, cy]];
1446
+ if (!focus) for (const y of [1 / 6, 1 / 2, 5 / 6]) for (const x of [1 / 6, 1 / 2, 5 / 6])
1447
+ points.push([left + (right - left) * x, top + (bottom - top) * y]);
1448
+ if (!info.inputIndex) info.inputIndex = createCocosInputIndex(info.tree, cc);
1449
+ let verified = false;
1450
+ for (const [nx, ny] of points) {
1451
+ if (nx < 0 || nx >= 1 || ny < 0 || ny >= 1) continue;
1452
+ let local;
1453
+ try {
1454
+ local = localPoint(doc, nx * window.innerWidth, ny * window.innerHeight, info);
1455
+ } catch (error) {
1456
+ if (error.message === "TARGET_OCCLUDED") continue;
1457
+ throw error;
1458
+ }
1459
+ const lx = local.x / win.innerWidth, ly = local.y / win.innerHeight;
1460
+ const point = cocosViewPoint(win, cc, lx, ly, info.geometry.rect);
1461
+ if (cocosHitTest(live, point) !== true) continue;
1462
+ verified = true;
1463
+ const element = doc.elementFromPoint(local.x, local.y);
1464
+ if (!element || element.tagName !== "CANVAS") continue;
1465
+ const hit = resolveCocosInputAt(cc, lx, ly, point, info.inputIndex);
1466
+ const endLocal = gesture && localPoint(
1467
+ doc,
1468
+ (nx + gesture[0]) * window.innerWidth,
1469
+ (ny + gesture[1]) * window.innerHeight,
1470
+ info,
1471
+ false
1472
+ );
1473
+ const end = endLocal && cocosViewPoint(win, cc, endLocal.x / win.innerWidth, endLocal.y / win.innerHeight, info.geometry.rect);
1474
+ if (hit && (hit.__cocos_runtime_cocos_node === live || end && capturesScrollGesture(
1475
+ live,
1476
+ hit.__cocos_runtime_cocos_node,
1477
+ cc,
1478
+ Math.hypot(end.x - point.x, end.y - point.y),
1479
+ point,
1480
+ (node2) => snap.byLive.get(node2).node.__cocos_runtime_components()
1481
+ )))
1482
+ return { x: nx * window.innerWidth, y: ny * window.innerHeight };
1483
+ }
1484
+ fail2(verified ? "TARGET_OCCLUDED" : "HIT_TEST_UNVERIFIED");
1485
+ }
1486
+
1487
+ // src/candidates.js
1488
+ function collectCandidates(snap, entries, offset = 0, limit = Infinity) {
1489
+ const children = [];
1490
+ let total = 0;
1491
+ function webLabel(node2) {
1492
+ const p = node2.payload;
1493
+ for (const [value, source] of [[p.label, "semantic_label"], [p.text, "self_text"], [p.placeholder, "placeholder"]]) {
1494
+ if (typeof value === "string" && value.trim()) return { label: value.trim(), label_source: source };
1495
+ }
1496
+ return { label: "", label_source: "" };
1497
+ }
1498
+ const textCache = /* @__PURE__ */ new Map();
1499
+ function descendantTexts(node2) {
1500
+ if (textCache.has(node2)) return textCache.get(node2);
1501
+ const p = node2.payload;
1502
+ const texts = [];
1503
+ if (p.visible && !p.input_receiver && !p.automation_candidate) {
1504
+ const text = typeof p.text === "string" ? p.text.trim() : "";
1505
+ if (text) texts.push(text);
1506
+ for (const child of node2.children) texts.push(...descendantTexts(child));
1507
+ }
1508
+ textCache.set(node2, texts);
1509
+ return texts;
1510
+ }
1511
+ function labelFor(node2, live) {
1512
+ const explicit = live.automationLabel;
1513
+ if (typeof explicit === "string" && explicit.trim()) return { label: explicit.trim(), label_source: "explicit" };
1514
+ const self = typeof node2.payload.text === "string" ? node2.payload.text.trim() : "";
1515
+ if (self) return { label: self, label_source: "self_text" };
1516
+ const texts = /* @__PURE__ */ new Set();
1517
+ for (const child of node2.children) for (const text of descendantTexts(child)) texts.add(text);
1518
+ const label = Array.from(texts).join(" ");
1519
+ return { label, label_source: label ? "descendant_text" : "" };
1520
+ }
1521
+ for (const item of entries) {
1522
+ const live = item.node.__cocos_runtime_cocos_node;
1523
+ const p = item.node.payload, element = item.node.__cocos_runtime_element;
1524
+ const cc = item.doc.defaultView.cc;
1525
+ if (live && typeof cc.isValid === "function" && !cc.isValid(live, true)) continue;
1526
+ if (!p.clickable || !p.automation_candidate || p.input_owner) continue;
1527
+ let internal = false;
1528
+ for (let el = element; el; el = el.parentElement) {
1529
+ if (el.getAttribute("data-cocos-runtime-chrome") === "1" || el.getAttribute("data-cocos-runtime-overlay") !== null) internal = true;
1530
+ }
1531
+ if (internal) continue;
1532
+ if (element && p.tag === "A" && !element.getAttribute("href") && typeof element.onclick !== "function" && !["button", "link"].includes(p.role) && item.doc.defaultView.getComputedStyle(element).cursor !== "pointer") continue;
1533
+ let point;
1534
+ try {
1535
+ point = inputPoint(item, snap, void 0, [0, 0.1]);
1536
+ } catch (error) {
1537
+ if (![
1538
+ "TARGET_NOT_INTERACTIVE",
1539
+ "TARGET_DISABLED",
1540
+ "BOUNDS_UNAVAILABLE",
1541
+ "FRAME_INACCESSIBLE",
1542
+ "TARGET_OCCLUDED",
1543
+ "HIT_TEST_UNVERIFIED"
1544
+ ].includes(error.message)) throw error;
1545
+ continue;
1546
+ }
1547
+ const index = total++;
1548
+ if (index < offset || index >= offset + limit) continue;
1549
+ const payload = {
1550
+ ...completeFacts(p),
1551
+ path: item.path,
1552
+ ...selectorFor(item, snap),
1553
+ ...live ? labelFor(item.node, live) : webLabel(item.node)
1554
+ };
1555
+ if (live && (p.pos[0] < 0 || p.pos[0] > 1 || p.pos[1] < 0 || p.pos[1] > 1)) {
1556
+ const left = Math.max(0, p.pos[0] - p.size[0] / 2), right = Math.min(1, p.pos[0] + p.size[0] / 2);
1557
+ const top = Math.max(0, p.pos[1] - p.size[1] / 2), bottom = Math.min(1, p.pos[1] + p.size[1] / 2);
1558
+ payload.pos = [(left + right) / 2, (top + bottom) / 2];
1559
+ payload.size = [right - left, bottom - top];
1560
+ }
1561
+ if (live && (point.x !== payload.pos[0] * window.innerWidth || point.y !== payload.pos[1] * window.innerHeight))
1562
+ payload.input_pos = [point.x / window.innerWidth, point.y / window.innerHeight];
1563
+ const candidate = { name: item.node.name, payload, children: [] };
1564
+ Object.defineProperty(candidate, "__source", { value: item.node });
1565
+ children.push(candidate);
1566
+ }
1567
+ return { items: children, total };
1568
+ }
1569
+
1570
+ // src/observation.js
1571
+ function createObservation(observeCocos) {
1572
+ const identities = /* @__PURE__ */ new WeakMap();
1573
+ let nextIdentity = 0;
1574
+ function identity(value) {
1575
+ if (!value || typeof value !== "object") return JSON.stringify([typeof value, value]);
1576
+ if (!identities.has(value)) identities.set(value, String(++nextIdentity));
1577
+ return identities.get(value);
1578
+ }
1579
+ const fail3 = (code) => {
1580
+ throw new Error(code);
1581
+ };
1582
+ const snapshot = () => captureScene(observeCocos);
1583
+ function validateOptions(options, allowed) {
1584
+ if (!options || typeof options !== "object" || Array.isArray(options) || Object.keys(options).some((key) => !allowed.includes(key))) fail3("INVALID_OPTIONS");
1585
+ for (const [key, max] of [["limit", 500], ["offset", Number.MAX_SAFE_INTEGER], ["depth", 100]]) {
1586
+ if (options[key] !== void 0 && (!Number.isSafeInteger(options[key]) || options[key] < (key === "limit" ? 1 : 0) || options[key] > max)) fail3("INVALID_OPTIONS");
1587
+ }
1588
+ }
1589
+ function describe(options = {}, currentSnapshot) {
1590
+ validateOptions(options, ["target", "depth", "fields", "search", "offset", "limit", "evidence"]);
1591
+ if (options.search !== void 0 && (typeof options.search !== "string" || !options.search.trim())) fail3("INVALID_OPTIONS");
1592
+ const snap = currentSnapshot || snapshot();
1593
+ let items = scoped(snap, options.target);
1594
+ const depth = options.depth === void 0 ? 2 : options.depth;
1595
+ const rootDepth = options.target ? items[0].depth : 0;
1596
+ const fields = options.fields || ["name", "type", "text", "icon", "active", "visible", "enabled", "editable", "components"];
1597
+ const allowed = /* @__PURE__ */ new Set([...pocoAttributes, "selector", "selector_unique"]);
1598
+ if (!Array.isArray(fields) || !fields.length || fields.some((field) => !allowed.has(field))) fail3("QUERY_FIELD_UNSUPPORTED");
1599
+ const depthLimited = items.some((item) => item.depth - rootDepth > depth);
1600
+ items = items.filter((item) => item.depth - rootDepth <= depth);
1601
+ if (options.search) items = items.filter((item) => {
1602
+ const attrs = pocoAttributesOf(item, ["name", "text", "icon"]);
1603
+ return [attrs.name, attrs.text, attrs.icon, item.path].some((value) => typeof value === "string" && value.includes(options.search));
1604
+ });
1605
+ const offset = options.offset ?? 0, limit = options.limit ?? 100;
1606
+ const selected = items.slice(offset, offset + limit);
1607
+ return {
1608
+ total: items.length,
1609
+ offset,
1610
+ truncated: offset + limit < items.length,
1611
+ depthLimited,
1612
+ ...options.evidence ? { evidence: selected.map((item) => ({ ...pocoAttributesOf(item), ...selectorFor(item, snap) })) } : {},
1613
+ items: selected.map((item) => {
1614
+ const attrs = pocoAttributesOf(item, fields);
1615
+ if (fields.some((field) => field === "selector" || field === "selector_unique")) Object.assign(attrs, selectorFor(item, snap));
1616
+ return {
1617
+ path: item.path,
1618
+ frame: item.node.payload.frame,
1619
+ ...Object.fromEntries(fields.filter((field) => attrs[field] !== void 0).map((field) => [field, attrs[field]]))
1620
+ };
1621
+ })
1622
+ };
1623
+ }
1624
+ function all(options = {}, snap = snapshot()) {
1625
+ bindInputOwners(snap);
1626
+ const limit = Number.isFinite(options.limit) ? Math.min(1e4, Math.max(1, Math.floor(options.limit))) : 5e3;
1627
+ let count = 0, truncated = false;
1628
+ function copy(node2) {
1629
+ if (count >= limit) {
1630
+ truncated = true;
1631
+ return null;
1632
+ }
1633
+ count++;
1634
+ const p = completeFacts(node2.payload);
1635
+ return { name: node2.name, payload: p, children: node2.children.map(copy).filter(Boolean) };
1636
+ }
1637
+ return { tree: copy(snap.tree), truncated };
1638
+ }
1639
+ function interactable(options = {}, currentSnapshot) {
1640
+ validateOptions(options, ["scope", "compact", "offset", "limit", "evidence"]);
1641
+ if (options.compact !== void 0 && typeof options.compact !== "boolean") fail3("INVALID_OPTIONS");
1642
+ const snap = currentSnapshot || snapshot();
1643
+ bindInputOwners(snap);
1644
+ const offset = Number.isFinite(options.offset) ? Math.max(0, Math.floor(options.offset)) : 0;
1645
+ const limit = Number.isFinite(options.limit) ? Math.min(500, Math.max(1, Math.floor(options.limit))) : 100;
1646
+ const candidates = collectCandidates(snap, scoped(snap, options.scope), offset, limit);
1647
+ const evidence = [];
1648
+ const items = candidates.items.map((candidate) => {
1649
+ const item = snap.byNode.get(candidate.__source);
1650
+ const description = describeItem(item, snap);
1651
+ const result = {
1652
+ ...description,
1653
+ label: candidate.payload.label || description.label,
1654
+ label_source: candidate.payload.label_source || "",
1655
+ pos: candidate.payload.pos,
1656
+ size: candidate.payload.size
1657
+ };
1658
+ evidence.push({ ...result, anchorPoint: [0.5, 0.5] });
1659
+ if (!options.compact) return result;
1660
+ return {
1661
+ name: result.name,
1662
+ label: result.label.slice(0, 240),
1663
+ label_truncated: result.label.length > 240,
1664
+ type: result.type,
1665
+ icon: result.icon,
1666
+ selector: result.selector,
1667
+ selector_unique: result.selector_unique,
1668
+ capabilities: candidate.__source.payload.input_capabilities || {},
1669
+ editable: result.editable
1670
+ };
1671
+ });
1672
+ return {
1673
+ total: candidates.total,
1674
+ offset,
1675
+ truncated: offset + limit < candidates.total,
1676
+ items,
1677
+ ...options.evidence ? { evidence } : {}
1678
+ };
1679
+ }
1680
+ function prepareTap(target) {
1681
+ validateTarget(target);
1682
+ const snap = snapshot();
1683
+ const items = select(snap, target);
1684
+ if (items.length !== 1) fail3("TARGET_NOT_UNIQUE: " + items.length);
1685
+ return { point: inputPoint(items[0], snap) };
1686
+ }
1687
+ function pocoQuery(query) {
1688
+ const items = selectPoco(snapshot(), query);
1689
+ return queryResult(items);
1690
+ }
1691
+ function queryResult(items) {
1692
+ return { items: items.slice(0, 1e4).map((item) => pocoAttributesOf(item)), total: items.length, truncated: items.length > 1e4 };
1693
+ }
1694
+ function uniquePoco(snap, query) {
1695
+ const items = selectPoco(snap, query);
1696
+ if (!items.length) fail3("TARGET_NOT_FOUND");
1697
+ if (items.length !== 1) fail3("TARGET_NOT_UNIQUE: " + items.length);
1698
+ return items[0];
1699
+ }
1700
+ function validateFocus(focus) {
1701
+ if (focus !== void 0 && (!Array.isArray(focus) || focus.length !== 2 || focus.some((value) => !Number.isFinite(value) || value < 0 || value > 1))) fail3("INVALID_FOCUS");
1702
+ }
1703
+ function preparePoco(query, focus, requireEditable, gesture, expectedPoint) {
1704
+ if (gesture !== void 0 && (!Array.isArray(gesture) || gesture.length !== 2 || gesture.some((value) => !Number.isFinite(value)))) fail3("INVALID_GESTURE");
1705
+ validateFocus(focus);
1706
+ const snap = snapshot(), item = uniquePoco(snap, query);
1707
+ if (requireEditable && !item.node.payload.editable) fail3("TARGET_NOT_EDITABLE");
1708
+ const point = inputPoint(item, snap, focus, gesture);
1709
+ if (expectedPoint && (Math.abs(point.x / window.innerWidth - expectedPoint[0]) > 1e-3 || Math.abs(point.y / window.innerHeight - expectedPoint[1]) > 1e-3)) fail3("TARGET_MOVED");
1710
+ return { point };
1711
+ }
1712
+ function prepareScroll(query, start, end) {
1713
+ validateFocus(start);
1714
+ validateFocus(end);
1715
+ if (!start || !end) fail3("INVALID_FOCUS");
1716
+ const snap = snapshot(), item = uniquePoco(snap, query), p = item.node.payload;
1717
+ if (!p.pos || !p.size) fail3("BOUNDS_UNAVAILABLE");
1718
+ const destination = p.pos.map((value, axis) => value + p.size[axis] * (end[axis] - 0.5));
1719
+ const vector = p.size.map((value, axis) => value * (end[axis] - start[axis]));
1720
+ return { point: inputPoint(item, snap, start, vector), destination };
1721
+ }
1722
+ function checkQueries(requests, readinessBlocked = false) {
1723
+ if (!Array.isArray(requests) || !requests.length || requests.some((request) => !request || typeof request !== "object" || Array.isArray(request) || Object.keys(request).some((key) => !["selector", "ready"].includes(key)) || request.ready !== void 0 && typeof request.ready !== "boolean")) fail3("INVALID_OPTIONS");
1724
+ const snap = snapshot();
1725
+ return requests.map((request) => {
1726
+ const items = selectPoco(snap, request.selector), query = queryResult(items);
1727
+ if (!request.ready) return { query };
1728
+ if (readinessBlocked) return { query, readinessError: "INSPECT_ACTIVE" };
1729
+ if (items.length > 1) return { query, readinessError: "TARGET_NOT_UNIQUE: " + items.length };
1730
+ let ready = false;
1731
+ if (items.length) try {
1732
+ inputPoint(items[0], snap);
1733
+ ready = true;
1734
+ } catch (error) {
1735
+ if (!["TARGET_DISABLED", "TARGET_NOT_INTERACTIVE", "TARGET_OCCLUDED", "BOUNDS_UNAVAILABLE"].includes(error.message))
1736
+ return { query, readinessError: error.message };
1737
+ }
1738
+ return { query, ready };
1739
+ });
1740
+ }
1741
+ function resolvePoint(point) {
1742
+ if (!Array.isArray(point) || point.length !== 2 || point.some((value) => !Number.isFinite(value) || value < 0 || value >= 1)) fail3("INVALID_POINT");
1743
+ const snap = snapshot(), items = [];
1744
+ for (const item of snap.flat) {
1745
+ const p = item.node.payload;
1746
+ if (!p.visible || !p.interactable || !p.pos || !p.size || !(p.size[0] > 0 && p.size[1] > 0)) continue;
1747
+ const focus = [(point[0] - p.pos[0]) / p.size[0] + 0.5, (point[1] - p.pos[1]) / p.size[1] + 0.5];
1748
+ if (focus.some((value) => value < 0 || value > 1)) continue;
1749
+ try {
1750
+ inputPoint(item, snap, focus);
1751
+ items.push(item);
1752
+ } catch (error) {
1753
+ if (![
1754
+ "TARGET_NOT_INTERACTIVE",
1755
+ "TARGET_DISABLED",
1756
+ "BOUNDS_UNAVAILABLE",
1757
+ "FRAME_INACCESSIBLE",
1758
+ "TARGET_OCCLUDED",
1759
+ "HIT_TEST_UNVERIFIED"
1760
+ ].includes(error.message)) throw error;
1761
+ }
1762
+ }
1763
+ if (items.length !== 1) fail3("TARGET_NOT_UNIQUE: " + items.length);
1764
+ return { item: items[0], snap };
1765
+ }
1766
+ function bindPoint(point) {
1767
+ const { item, snap } = resolvePoint(point), p = item.node.payload, selection = selectorFor(item, snap);
1768
+ if (!selection.selector_unique) fail3("TARGET_NOT_UNIQUE");
1769
+ const focus = [(point[0] - p.pos[0]) / p.size[0] + 0.5, (point[1] - p.pos[1]) / p.size[1] + 0.5];
1770
+ return { ...selection, focus, editable: !!p.editable, layer: p.layer, components: p.components || [], point: { x: point[0] * window.innerWidth, y: point[1] * window.innerHeight } };
1771
+ }
1772
+ function preparePoint(point) {
1773
+ resolvePoint(point);
1774
+ return { point: { x: point[0] * window.innerWidth, y: point[1] * window.innerHeight } };
1775
+ }
1776
+ function read(target, reader) {
1777
+ const snap = snapshot();
1778
+ const structure = {}, states = {};
1779
+ for (const key of Object.keys(target || {})) {
1780
+ if (booleanFields.has(key)) states[key] = target[key];
1781
+ else structure[key] = target[key];
1782
+ }
1783
+ const items = select(snap, structure).filter((item2) => item2.node.payload.active !== false && Object.keys(states).every((key) => item2.node.payload[key] === states[key]));
1784
+ if (!items.length) fail3("TARGET_NOT_FOUND");
1785
+ if (items.length !== 1) fail3("TARGET_NOT_UNIQUE: " + items.length);
1786
+ const item = items[0];
1787
+ let candidates;
1788
+ return reader({
1789
+ node: item.node.__cocos_runtime_cocos_node,
1790
+ element: item.node.__cocos_runtime_element,
1791
+ cc: item.doc.defaultView.cc,
1792
+ identity,
1793
+ describe(node2) {
1794
+ const entry = snap.byLive.get(node2);
1795
+ return entry ? describeItem(entry, snap) : null;
1796
+ },
1797
+ candidates() {
1798
+ bindInputOwners(snap);
1799
+ if (!candidates) candidates = collectCandidates(snap, snap.flat).items.map((candidate) => describeItem(snap.byNode.get(candidate.__source), snap));
1800
+ return candidates;
1801
+ }
1802
+ });
1803
+ }
1804
+ function capture(options) {
1805
+ const snap = snapshot();
1806
+ return { candidates: interactable(options.interactable, snap), description: describe(options.describe, snap) };
1807
+ }
1808
+ function captureSnapshot() {
1809
+ const snap = snapshot();
1810
+ return { observation: all({ limit: 1e4 }, snap), candidates: interactable({ limit: 500 }, snap) };
1811
+ }
1812
+ function dumpInteractable() {
1813
+ const snap = snapshot();
1814
+ bindInputOwners(snap);
1815
+ return collectCandidates(snap, snap.flat).items;
1816
+ }
1817
+ return { all, interactable, describe, capture, captureSnapshot, checkQueries, prepareTap, pocoQuery, preparePoco, prepareScroll, preparePoint, bindPoint, read, dumpInteractable, rawTree: () => snapshot().tree };
1818
+ }
1819
+
1820
+ // src/fingerprint.js
1821
+ function fingerprint(tree) {
1822
+ let incomplete = document.readyState === "loading";
1823
+ const visit = (node2, parentActive = true) => {
1824
+ const p = node2.payload;
1825
+ const active = parentActive && p.active !== false;
1826
+ if (p.frame_exists && (!p.frame_accessible || !p.frame_ready)) incomplete = true;
1827
+ const doc = node2.__cocos_runtime_document;
1828
+ if (p.layer === "web" && node2.__cocos_runtime_element === doc.documentElement && doc.defaultView.cc && !p.cocos_version) incomplete = true;
1829
+ const el = node2.__cocos_runtime_element;
1830
+ let visible2 = true;
1831
+ if (el) {
1832
+ for (let current = el; current; current = current.parentElement) {
1833
+ const style = current.ownerDocument.defaultView.getComputedStyle(current);
1834
+ if (current.hidden || style.display === "none" || ["hidden", "collapse"].includes(style.visibility)) {
1835
+ visible2 = false;
1836
+ break;
1837
+ }
1838
+ }
1839
+ }
1840
+ return [
1841
+ p.layer,
1842
+ p.frame,
1843
+ p.id,
1844
+ p.name,
1845
+ p.type,
1846
+ active,
1847
+ visible2,
1848
+ !!p.enabled,
1849
+ !!p.clickable,
1850
+ !!p.input_receiver,
1851
+ node2.children.map((child) => visit(child, active))
1852
+ ];
1853
+ };
1854
+ const input = JSON.stringify(visit(tree));
1855
+ let a = 2166136261, b = 2246822507;
1856
+ for (let i = 0; i < input.length; i++) {
1857
+ a = Math.imul(a ^ input.charCodeAt(i), 16777619);
1858
+ b = Math.imul(b ^ input.charCodeAt(i), 3266489909);
1859
+ }
1860
+ const value = (a >>> 0).toString(16).padStart(8, "0") + (b >>> 0).toString(16).padStart(8, "0");
1861
+ return { value, algorithm: "structural-v1", status: "ok", scope: "accessible-page", incomplete };
1862
+ }
1863
+
1864
+ // src/index.js
1865
+ var PROTOCOL_VERSION = 14;
1866
+ var RUNTIME_REVISION = 0;
1867
+ var existing = window.__cocos_runtime;
1868
+ if (!existing || existing.protocolVersion !== PROTOCOL_VERSION || existing.runtimeRevision !== RUNTIME_REVISION) {
1869
+ if (existing && existing.inspect && existing.inspect.isActive()) throw new Error("RUNTIME_IN_USE");
1870
+ if (document.querySelectorAll) document.querySelectorAll("[" + OVERLAY_ATTR + "]").forEach((el) => el.remove());
1871
+ const observeCocos = createCocosV2Observer();
1872
+ const observation = createObservation(observeCocos);
1873
+ const inspector = createInspector(observeCocos, observation.dumpInteractable);
1874
+ const instanceId = "cocos-runtime-" + Date.now().toString(36) + "-" + Math.random().toString(36).slice(2);
1875
+ let toolbarRequested = !window.__cocos_runtime_automation_only;
1876
+ window.__cocos_runtime = {
1877
+ protocolVersion: PROTOCOL_VERSION,
1878
+ runtimeRevision: RUNTIME_REVISION,
1879
+ instanceId,
1880
+ observe: {
1881
+ all: observation.all,
1882
+ interactable: observation.interactable,
1883
+ describe: observation.describe,
1884
+ capture: observation.capture,
1885
+ snapshot: observation.captureSnapshot,
1886
+ check(requests) {
1887
+ return observation.checkQueries(requests, inspector.isActive());
1888
+ }
1889
+ },
1890
+ query: observation.pocoQuery,
1891
+ read(expectedInstance, target, reader) {
1892
+ if (expectedInstance !== instanceId) throw new Error("COCOS_RUNTIME_CHANGED");
1893
+ return observation.read(target, reader);
1894
+ },
1895
+ fingerprint() {
1896
+ return fingerprint(observation.rawTree());
1897
+ },
1898
+ prepareTap(target) {
1899
+ if (inspector.isActive()) throw new Error("INSPECT_ACTIVE");
1900
+ return observation.prepareTap(target);
1901
+ },
1902
+ preparePoco(target, focus, requireEditable, gesture, expectedPoint) {
1903
+ if (inspector.isActive()) throw new Error("INSPECT_ACTIVE");
1904
+ return observation.preparePoco(target, focus, requireEditable, gesture, expectedPoint);
1905
+ },
1906
+ prepareScroll(target, start, end) {
1907
+ if (inspector.isActive()) throw new Error("INSPECT_ACTIVE");
1908
+ return observation.prepareScroll(target, start, end);
1909
+ },
1910
+ preparePoint(point) {
1911
+ if (inspector.isActive()) throw new Error("INSPECT_ACTIVE");
1912
+ return observation.preparePoint(point);
1913
+ },
1914
+ bindPoint(point) {
1915
+ if (inspector.isActive()) throw new Error("INSPECT_ACTIVE");
1916
+ return observation.bindPoint(point);
1917
+ },
1918
+ inspect: {
1919
+ showToolbar() {
1920
+ toolbarRequested = true;
1921
+ if (!inspector.mountToolbar()) throw new Error("INSPECT_TOOLBAR_UNAVAILABLE");
1922
+ },
1923
+ hideToolbar() {
1924
+ toolbarRequested = false;
1925
+ inspector.hideToolbar();
1926
+ },
1927
+ isActive: inspector.isActive
1928
+ }
1929
+ };
1930
+ if (toolbarRequested) {
1931
+ const mount = () => {
1932
+ if (toolbarRequested) try {
1933
+ inspector.mountToolbar();
1934
+ } catch (_) {
1935
+ }
1936
+ };
1937
+ mount();
1938
+ if (document.readyState === "loading" && document.addEventListener) document.addEventListener("DOMContentLoaded", mount, { once: true });
1939
+ }
1940
+ }
1941
+ })();
1942
+ //# sourceURL=cocos-sdk.js