onejs-core 2.0.18 → 2.0.20

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.
@@ -395,6 +395,7 @@ declare namespace CS {
395
395
  public SetTransitionProperty ($value: System.Collections.Generic.List$1<UnityEngine.UIElements.StylePropertyName>) : void
396
396
  public SetTransitionTimingFunction ($value: System.Collections.Generic.List$1<UnityEngine.UIElements.EasingFunction>) : void
397
397
  public SetTranslate ($value: UnityEngine.UIElements.Translate) : void
398
+ public SetTranslate (a: number, b: number) : void
398
399
  public SetUnityBackgroundImageTintColor ($value: UnityEngine.Color) : void
399
400
  public SetUnityBackgroundScaleMode ($value: UnityEngine.ScaleMode) : void
400
401
  public SetUnityFont ($value: UnityEngine.Font) : void
@@ -26,6 +26,7 @@ declare global {
26
26
  }
27
27
 
28
28
  const document: DocumentWrapper
29
+ const onejsDocument: DocumentWrapper
29
30
  const setTimeout: (callback: () => void, delay?: number) => number
30
31
  const clearTimeout: (id: number) => void
31
32
  const setInterval: (callback: () => void, delay?: number) => number
@@ -17,5 +17,7 @@ export declare class DocumentWrapper {
17
17
  createTextNode(text: string): DomWrapper;
18
18
  getElementById(id: string): DomWrapper;
19
19
  querySelectorAll(selector: string): DomWrapper[];
20
+ elementFromPoint(x: number, y: number): DomWrapper | null;
21
+ elementsFromPoint(x: number, y: number): DomWrapper[];
20
22
  }
21
23
  export {};
@@ -1,3 +1,4 @@
1
+ import { Vector2 } from "UnityEngine";
1
2
  import { DomWrapper } from "./dom";
2
3
  export class DocumentWrapper {
3
4
  get _doc() { return this.#doc; }
@@ -38,4 +39,39 @@ export class DocumentWrapper {
38
39
  }
39
40
  return res;
40
41
  }
42
+ elementFromPoint(x, y) {
43
+ const root = this.body;
44
+ if (!root)
45
+ return null;
46
+ const hitTest = (node) => {
47
+ if (!node.ve.worldBound.Contains(new Vector2(x, y)))
48
+ return null;
49
+ // later siblings are painted on top → scan from back to front
50
+ for (let i = node.childNodes.length - 1; i >= 0; i--) {
51
+ const hit = hitTest(node.childNodes[i]);
52
+ if (hit)
53
+ return hit;
54
+ }
55
+ return node;
56
+ };
57
+ return hitTest(root);
58
+ }
59
+ elementsFromPoint(x, y) {
60
+ const root = this.body;
61
+ if (!root)
62
+ return [];
63
+ const hits = [];
64
+ const collect = (node) => {
65
+ if (!node.ve.worldBound.Contains(new Vector2(x, y)))
66
+ return;
67
+ // visit children first, from front to back (last child is top‑most)
68
+ for (let i = node.childNodes.length - 1; i >= 0; i--) {
69
+ collect(node.childNodes[i]);
70
+ }
71
+ // add the current node itself
72
+ hits.push(node);
73
+ };
74
+ collect(root);
75
+ return hits; // ordered front‑to‑back (top‑most first)
76
+ }
41
77
  }
package/dist/index.js CHANGED
@@ -33,9 +33,12 @@ export function h(type, props, ...children) {
33
33
  return element;
34
34
  }
35
35
  export { emo } from "./styling/index";
36
- // @ts-ignore
37
- if (typeof ___document != "undefined") {
36
+ if (typeof globalThis.___document != "undefined") {
38
37
  // @ts-ignore
39
- globalThis.document = new DocumentWrapper(___document);
38
+ globalThis.onejsDocument = new DocumentWrapper(globalThis.___document);
39
+ if (!globalThis.ONEJS_WEBGL) {
40
+ // @ts-ignore
41
+ globalThis.document = globalThis.onejsDocument;
42
+ }
40
43
  }
41
44
  // puer.$extension(CS.UnityEngine.UIElements.VisualElement, CS.UnityEngine.UIElements.VisualElementExtensions)
@@ -1,5 +1,5 @@
1
1
  type float4 = CS.Unity.Mathematics.float4;
2
- declare var kCSSColorTable: {
2
+ declare const kCSSColorTable: {
3
3
  transparent: number[];
4
4
  aliceblue: number[];
5
5
  antiquewhite: number[];
@@ -27,7 +27,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27
27
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28
28
  IN THE SOFTWARE.
29
29
  */
30
- var kCSSColorTable = {
30
+ const kCSSColorTable = {
31
31
  "transparent": [0, 0, 0, 0], "aliceblue": [240, 248, 255, 1],
32
32
  "antiquewhite": [250, 235, 215, 1], "aqua": [0, 255, 255, 1],
33
33
  "aquamarine": [127, 255, 212, 1], "azure": [240, 255, 255, 1],
package/dom/document.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Vector2 } from "UnityEngine"
1
2
  import { DomWrapper } from "./dom"
2
3
 
3
4
  interface ElementCreationOptions {
@@ -7,8 +8,8 @@ interface ElementCreationOptions {
7
8
  export class DocumentWrapper {
8
9
  public get _doc(): CS.OneJS.Dom.Document { return this.#doc }
9
10
 
10
- #doc: CS.OneJS.Dom.Document;
11
- #body: DomWrapper | null;
11
+ #doc: CS.OneJS.Dom.Document
12
+ #body: DomWrapper | null
12
13
 
13
14
  /**
14
15
  * The body/root element of the document. Will be null for Editor documents.
@@ -51,6 +52,46 @@ export class DocumentWrapper {
51
52
  for (let i = 0; i < doms.Length; i++) {
52
53
  res.push(new DomWrapper(doms.get_Item(i)))
53
54
  }
54
- return res;
55
+ return res
56
+ }
57
+
58
+ elementFromPoint(x: number, y: number): DomWrapper | null {
59
+ const root = this.body
60
+ if (!root) return null
61
+
62
+ const hitTest = (node: DomWrapper): DomWrapper | null => {
63
+ if (!node.ve.worldBound.Contains(new Vector2(x, y))) return null
64
+
65
+ // later siblings are painted on top → scan from back to front
66
+ for (let i = node.childNodes.length - 1; i >= 0; i--) {
67
+ const hit = hitTest(node.childNodes[i])
68
+ if (hit) return hit
69
+ }
70
+ return node
71
+ }
72
+
73
+ return hitTest(root)
74
+ }
75
+
76
+ elementsFromPoint(x: number, y: number): DomWrapper[] {
77
+ const root = this.body
78
+ if (!root) return []
79
+
80
+ const hits: DomWrapper[] = []
81
+
82
+ const collect = (node: DomWrapper): void => {
83
+ if (!node.ve.worldBound.Contains(new Vector2(x, y))) return
84
+
85
+ // visit children first, from front to back (last child is top‑most)
86
+ for (let i = node.childNodes.length - 1; i >= 0; i--) {
87
+ collect(node.childNodes[i])
88
+ }
89
+
90
+ // add the current node itself
91
+ hits.push(node)
92
+ }
93
+
94
+ collect(root)
95
+ return hits // ordered front‑to‑back (top‑most first)
55
96
  }
56
97
  }
package/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference path="./definitions/index.d.ts" />
2
- import { DocumentWrapper } from "./dom/document";
3
- import { DomWrapper } from "./dom/dom";
2
+ import { DocumentWrapper } from "./dom/document"
3
+ import { DomWrapper } from "./dom/dom"
4
4
 
5
5
  /**
6
6
  * OneJS's own h function. Use this to quickly create elements in jsx-like syntax
@@ -10,29 +10,29 @@ import { DomWrapper } from "./dom/dom";
10
10
  * @returns
11
11
  */
12
12
  export function h(type: any, props: any, ...children: any[]): any {
13
- const element = typeof type === "string" ? document.createElement(type) : type;
13
+ const element = typeof type === "string" ? document.createElement(type) : type
14
14
 
15
15
  // Assign properties to the element
16
16
  for (const [key, value] of Object.entries(props || {})) {
17
17
  if (key.startsWith("on") && typeof value === "function") {
18
- element.addEventListener(key.substring(2).toLowerCase(), value);
18
+ element.addEventListener(key.substring(2).toLowerCase(), value)
19
19
  } else if (key === "style" && typeof value === "object") {
20
- Object.assign(element.style, value);
20
+ Object.assign(element.style, value)
21
21
  } else {
22
- element.setAttribute(key, value);
22
+ element.setAttribute(key, value)
23
23
  }
24
24
  }
25
25
 
26
26
  // Append children
27
27
  for (const child of children) {
28
28
  if (typeof child === "string") {
29
- element.appendChild(document.createTextNode(child));
29
+ element.appendChild(document.createTextNode(child))
30
30
  } else {
31
- element.appendChild(child);
31
+ element.appendChild(child)
32
32
  }
33
33
  }
34
34
 
35
- return element;
35
+ return element
36
36
  }
37
37
 
38
38
  export { emo } from "./styling/index"
@@ -46,10 +46,13 @@ declare global {
46
46
  const toJsArray: <T>(csArr: CS.System.Array) => T[]
47
47
  }
48
48
 
49
- // @ts-ignore
50
- if (typeof ___document != "undefined") {
49
+ if (typeof globalThis.___document != "undefined") {
51
50
  // @ts-ignore
52
- globalThis.document = new DocumentWrapper(___document)
51
+ globalThis.onejsDocument = new DocumentWrapper(globalThis.___document)
52
+ if (!globalThis.ONEJS_WEBGL) {
53
+ // @ts-ignore
54
+ globalThis.document = globalThis.onejsDocument
55
+ }
53
56
  }
54
57
 
55
58
  // puer.$extension(CS.UnityEngine.UIElements.VisualElement, CS.UnityEngine.UIElements.VisualElementExtensions)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "onejs-core",
3
3
  "description": "The JS part of OneJS, a UI framework and Scripting Engine for Unity.",
4
- "version": "2.0.18",
4
+ "version": "2.0.20",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/Singtaa/onejs-core"
@@ -13,9 +13,9 @@ const projectDir = path.resolve(process.cwd(), '..')
13
13
  const manifestPath = path.join(projectDir, 'Packages', 'manifest.json')
14
14
 
15
15
  const backends = [
16
- { name: "QuickJS", tgzUrl: "https://github.com/Tencent/puerts/releases/download/Unity_v2.2.1/PuerTS_Quickjs_2.2.1.tgz" },
17
- { name: "V8", tgzUrl: "https://github.com/Tencent/puerts/releases/download/Unity_v2.2.1/PuerTS_V8_2.2.1.tgz" },
18
- { name: "NodeJS", tgzUrl: "https://github.com/Tencent/puerts/releases/download/Unity_v2.2.1/PuerTS_Nodejs_2.2.1.tgz" }
16
+ { name: "QuickJS", tgzUrl: "https://github.com/Tencent/puerts/releases/download/Unity_v2.2.2/PuerTS_Quickjs_2.2.2.tgz" },
17
+ { name: "V8", tgzUrl: "https://github.com/Tencent/puerts/releases/download/Unity_v2.2.2/PuerTS_V8_2.2.2.tgz" },
18
+ { name: "NodeJS", tgzUrl: "https://github.com/Tencent/puerts/releases/download/Unity_v2.2.2/PuerTS_Nodejs_2.2.2.tgz" }
19
19
  ]
20
20
 
21
21
  const args = process.argv.slice(2)
@@ -64,7 +64,7 @@ async function Process(backend, outputDir) {
64
64
  }
65
65
  await extractTgz(downloadedPath, outputDir)
66
66
 
67
- // Safe keep asmdef files
67
+ // Safe keep asmdef files, et al.
68
68
  const onejsDir = await getOneJSUnityDir()
69
69
  const a = path.join(onejsDir, 'Puerts/Editor/com.tencent.puerts.core.Editor.asmdef')
70
70
  const b = path.join(upmDir, 'Editor/com.tencent.puerts.core.Editor.asmdef')
@@ -72,6 +72,9 @@ async function Process(backend, outputDir) {
72
72
  const d = path.join(upmDir, 'Runtime/com.tencent.puerts.core.asmdef')
73
73
  await fse.copy(a, b)
74
74
  await fse.copy(c, d)
75
+ const e = path.join(onejsDir, 'Puerts/Runtime/Src/Default/JsEnv.cs')
76
+ const f = path.join(upmDir, 'Runtime/Src/Default/JsEnv.cs')
77
+ await fse.copy(e, f)
75
78
 
76
79
  // Replace OneJS/Puerts with the new one
77
80
  const puertsDir = path.join(onejsDir, "Puerts")
@@ -31,7 +31,7 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
31
31
  IN THE SOFTWARE.
32
32
  */
33
33
 
34
- var kCSSColorTable = {
34
+ const kCSSColorTable = {
35
35
  "transparent": [0, 0, 0, 0], "aliceblue": [240, 248, 255, 1],
36
36
  "antiquewhite": [250, 235, 215, 1], "aqua": [0, 255, 255, 1],
37
37
  "aquamarine": [127, 255, 212, 1], "azure": [240, 255, 255, 1],