onejs-core 0.3.34 → 0.3.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dom/dom.js CHANGED
@@ -2,7 +2,16 @@ import { DomStyleWrapper } from "./dom-style";
2
2
  export class DomWrapper {
3
3
  get _dom() { return this.#dom; }
4
4
  get ve() { return this.#dom.ve; }
5
- get childNodes() { return this.#dom.childNodes.map((child) => new DomWrapper(child)); }
5
+ get childNodes() {
6
+ if (this.#cachedChildNodes)
7
+ return this.#cachedChildNodes;
8
+ this.#cachedChildNodes = new Array(this.#dom.childNodes.Length);
9
+ var i = this.#dom.childNodes.Length;
10
+ while (i--) {
11
+ this.#cachedChildNodes[i] = new DomWrapper(this.#dom.childNodes.get_Item(i));
12
+ }
13
+ return this.#cachedChildNodes;
14
+ }
6
15
  get firstChild() {
7
16
  return this.#dom.firstChild ? new DomWrapper(this.#dom.firstChild) : null;
8
17
  }
@@ -26,24 +35,29 @@ export class DomWrapper {
26
35
  set classname(value) { this.#dom.classname = value; }
27
36
  #dom;
28
37
  #domStyleWrapper;
38
+ #cachedChildNodes = null;
29
39
  constructor(dom) {
30
40
  this.#dom = dom;
31
41
  this.#domStyleWrapper = new DomStyleWrapper(dom.style);
32
42
  }
33
43
  appendChild(child) {
34
44
  this.#dom.appendChild(child.#dom);
45
+ this.#cachedChildNodes = null;
35
46
  }
36
47
  removeChild(child) {
37
48
  this.#dom.removeChild(child.#dom);
49
+ this.#cachedChildNodes = null;
38
50
  }
39
51
  insertBefore(a, b) {
40
52
  this.#dom.insertBefore(a?._dom, b?._dom);
53
+ this.#cachedChildNodes = null;
41
54
  }
42
55
  contains(child) {
43
56
  return this.#dom.contains(child._dom);
44
57
  }
45
58
  clearChildren() {
46
59
  this.#dom.clearChildren();
60
+ this.#cachedChildNodes = null;
47
61
  }
48
62
  focus() {
49
63
  this.#dom.focus();
package/dom/dom.ts CHANGED
@@ -4,7 +4,15 @@ import { DomStyleWrapper } from "./dom-style"
4
4
  export class DomWrapper {
5
5
  public get _dom(): CS.OneJS.Dom.Dom { return this.#dom }
6
6
  public get ve(): CS.UnityEngine.UIElements.VisualElement { return this.#dom.ve }
7
- public get childNodes(): DomWrapper[] { return (this.#dom.childNodes as any as CS.OneJS.Dom.Dom[]).map((child) => new DomWrapper(child)) }
7
+ public get childNodes(): DomWrapper[] {
8
+ if (this.#cachedChildNodes) return this.#cachedChildNodes
9
+ this.#cachedChildNodes = new Array(this.#dom.childNodes.Length) as DomWrapper[];
10
+ var i = this.#dom.childNodes.Length;
11
+ while (i--) {
12
+ this.#cachedChildNodes[i] = new DomWrapper(this.#dom.childNodes.get_Item(i));
13
+ }
14
+ return this.#cachedChildNodes
15
+ }
8
16
  public get firstChild(): DomWrapper | null {
9
17
  return this.#dom.firstChild ? new DomWrapper(this.#dom.firstChild) : null;
10
18
  }
@@ -32,6 +40,8 @@ export class DomWrapper {
32
40
  #dom: CS.OneJS.Dom.Dom
33
41
  #domStyleWrapper: DomStyleWrapper
34
42
 
43
+ #cachedChildNodes: DomWrapper[] = null
44
+
35
45
  constructor(dom: CS.OneJS.Dom.Dom) {
36
46
  this.#dom = dom
37
47
  this.#domStyleWrapper = new DomStyleWrapper(dom.style)
@@ -39,14 +49,17 @@ export class DomWrapper {
39
49
 
40
50
  appendChild(child: DomWrapper) {
41
51
  this.#dom.appendChild(child.#dom)
52
+ this.#cachedChildNodes = null
42
53
  }
43
54
 
44
55
  removeChild(child: DomWrapper) {
45
56
  this.#dom.removeChild(child.#dom)
57
+ this.#cachedChildNodes = null
46
58
  }
47
59
 
48
60
  insertBefore(a: DomWrapper, b: DomWrapper) {
49
61
  this.#dom.insertBefore(a?._dom, b?._dom)
62
+ this.#cachedChildNodes = null
50
63
  }
51
64
 
52
65
  contains(child: DomWrapper) {
@@ -55,6 +68,7 @@ export class DomWrapper {
55
68
 
56
69
  clearChildren() {
57
70
  this.#dom.clearChildren()
71
+ this.#cachedChildNodes = null
58
72
  }
59
73
 
60
74
  focus() {
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": "0.3.34",
4
+ "version": "0.3.36",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./typings.d.ts",
7
7
  "dependencies": {