onejs-core 0.3.39 → 0.3.41

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.
@@ -235,6 +235,7 @@ declare namespace CS {
235
235
  public focus () : void
236
236
  public First ($predicate: System.Func$2<OneJS.Dom.Dom, boolean>) : OneJS.Dom.Dom
237
237
  public ProcessClassStr ($classStr: string, $dom: OneJS.Dom.Dom) : string
238
+ public constructor ($ve: UnityEngine.UIElements.VisualElement)
238
239
  public constructor ($ve: UnityEngine.UIElements.VisualElement, $document: OneJS.Dom.Document)
239
240
  }
240
241
  class ElementCreationOptions extends System.Object
@@ -1,3 +1,5 @@
1
+ import { DocumentWrapper } from "../dom/document"
2
+
1
3
  declare global {
2
4
 
3
5
  // interface ElementCreationOptions {
@@ -23,7 +25,7 @@ declare global {
23
25
  style: CS.OneJS.Dom.DomStyle
24
26
  }
25
27
 
26
- const document: Document
28
+ const document: DocumentWrapper
27
29
  const setTimeout: (callback: () => void, delay?: number) => number
28
30
  const clearTimeout: (id: number) => void
29
31
  const setInterval: (callback: () => void, delay?: number) => number
@@ -338,6 +338,9 @@ declare global {
338
338
  "is-password-field"?: boolean
339
339
  "mask-char"?: string
340
340
  "is-read-only"?: boolean
341
+ "select-all-on-focus"?: boolean
342
+ "select-all-on-mouse-up"?: boolean
343
+ "vertical-scroller-visibility"?: ScrollerVisibility
341
344
  }
342
345
 
343
346
  interface TextField extends TextInputBaseField<string> {
@@ -4,6 +4,7 @@ interface ElementCreationOptions {
4
4
  }
5
5
  export declare class DocumentWrapper {
6
6
  #private;
7
+ get _doc(): CS.OneJS.Dom.Document;
7
8
  get body(): DomWrapper;
8
9
  constructor(doc: CS.OneJS.Dom.Document);
9
10
  addRuntimeUSS(uss: string): void;
@@ -1,11 +1,13 @@
1
1
  import { DomWrapper } from "./dom";
2
2
  export class DocumentWrapper {
3
+ get _doc() { return this.#doc; }
3
4
  #doc;
4
5
  #body;
5
6
  get body() { return this.#body; }
6
7
  constructor(doc) {
7
8
  this.#doc = doc;
8
- this.#body = new DomWrapper(doc.body);
9
+ if (doc.body)
10
+ this.#body = new DomWrapper(doc.body);
9
11
  }
10
12
  addRuntimeUSS(uss) {
11
13
  this.#doc.addRuntimeUSS(uss);
@@ -4,4 +4,5 @@ export declare class DomStyleWrapper implements CS.OneJS.Dom.DomStyle {
4
4
  setProperty(name: string, value: any): void;
5
5
  }
6
6
  export interface DomStyleWrapper extends CS.OneJS.Dom.DomStyle {
7
+ [key: string | symbol]: any;
7
8
  }
package/dist/dom/dom.d.ts CHANGED
@@ -2,7 +2,6 @@
2
2
  import { EventBase } from "UnityEngine/UIElements";
3
3
  import { DomStyleWrapper } from "./dom-style";
4
4
  export declare class DomWrapper {
5
- #private;
6
5
  get _dom(): CS.OneJS.Dom.Dom;
7
6
  get ve(): CS.UnityEngine.UIElements.VisualElement;
8
7
  get childNodes(): DomWrapper[];
@@ -21,6 +20,13 @@ export declare class DomWrapper {
21
20
  set data(value: any);
22
21
  get classname(): string;
23
22
  set classname(value: string);
23
+ /**
24
+ * Not using private fields because of issues with the `#private;` line
25
+ * generated by tsc
26
+ */
27
+ dom: CS.OneJS.Dom.Dom;
28
+ domStyleWrapper: DomStyleWrapper;
29
+ cachedChildNodes: DomWrapper[] | null;
24
30
  constructor(dom: CS.OneJS.Dom.Dom);
25
31
  appendChild(child: DomWrapper): void;
26
32
  removeChild(child: DomWrapper): void;
package/dist/dom/dom.js CHANGED
@@ -1,79 +1,83 @@
1
1
  import { DomStyleWrapper } from "./dom-style";
2
2
  export class DomWrapper {
3
- get _dom() { return this.#dom; }
4
- get ve() { return this.#dom.ve; }
3
+ get _dom() { return this.dom; }
4
+ get ve() { return this.dom.ve; }
5
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;
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
10
  while (i--) {
11
- this.#cachedChildNodes[i] = new DomWrapper(this.#dom.childNodes.get_Item(i));
11
+ this.cachedChildNodes[i] = new DomWrapper(this.dom.childNodes.get_Item(i));
12
12
  }
13
- return this.#cachedChildNodes;
13
+ return this.cachedChildNodes;
14
14
  }
15
15
  get firstChild() {
16
- return this.#dom.firstChild ? new DomWrapper(this.#dom.firstChild) : null;
16
+ return this.dom.firstChild ? new DomWrapper(this.dom.firstChild) : null;
17
17
  }
18
18
  get parentNode() {
19
- return this.#dom.parentNode ? new DomWrapper(this.#dom.parentNode) : null;
19
+ return this.dom.parentNode ? new DomWrapper(this.dom.parentNode) : null;
20
20
  }
21
21
  get nextSibling() {
22
- return this.#dom.nextSibling ? new DomWrapper(this.#dom.nextSibling) : null;
22
+ return this.dom.nextSibling ? new DomWrapper(this.dom.nextSibling) : null;
23
23
  }
24
- get nodeType() { return this.#dom.nodeType; }
25
- get style() { return this.#domStyleWrapper; }
26
- get Id() { return this.#dom.Id; }
27
- set Id(value) { this.#dom.Id = value; }
28
- get key() { return this.#dom.key; }
29
- set key(value) { this.#dom.key = value; }
30
- get value() { return this.#dom.value; }
31
- get checked() { return this.#dom.checked; }
32
- get data() { return this.#dom.data; }
33
- set data(value) { this.#dom.data = value; }
34
- get classname() { return this.#dom.classname; }
35
- set classname(value) { this.#dom.classname = value; }
36
- #dom;
37
- #domStyleWrapper;
38
- #cachedChildNodes = null;
24
+ get nodeType() { return this.dom.nodeType; }
25
+ get style() { return this.domStyleWrapper; }
26
+ get Id() { return this.dom.Id; }
27
+ set Id(value) { this.dom.Id = value; }
28
+ get key() { return this.dom.key; }
29
+ set key(value) { this.dom.key = value; }
30
+ get value() { return this.dom.value; }
31
+ get checked() { return this.dom.checked; }
32
+ get data() { return this.dom.data; }
33
+ set data(value) { this.dom.data = value; }
34
+ get classname() { return this.dom.classname; }
35
+ set classname(value) { this.dom.classname = value; }
36
+ /**
37
+ * Not using private fields because of issues with the `#private;` line
38
+ * generated by tsc
39
+ */
40
+ dom;
41
+ domStyleWrapper;
42
+ cachedChildNodes = null;
39
43
  constructor(dom) {
40
- this.#dom = dom;
41
- this.#domStyleWrapper = new DomStyleWrapper(dom.style);
44
+ this.dom = dom;
45
+ this.domStyleWrapper = new DomStyleWrapper(dom.style);
42
46
  }
43
47
  appendChild(child) {
44
- this.#dom.appendChild(child.#dom);
45
- this.#cachedChildNodes = null;
48
+ this.dom.appendChild(child.dom);
49
+ this.cachedChildNodes = null;
46
50
  }
47
51
  removeChild(child) {
48
- this.#dom.removeChild(child.#dom);
49
- this.#cachedChildNodes = null;
52
+ this.dom.removeChild(child.dom);
53
+ this.cachedChildNodes = null;
50
54
  }
51
55
  insertBefore(a, b) {
52
- this.#dom.insertBefore(a?._dom, b?._dom);
53
- this.#cachedChildNodes = null;
56
+ this.dom.insertBefore(a?._dom, b?._dom);
57
+ this.cachedChildNodes = null;
54
58
  }
55
59
  contains(child) {
56
- return this.#dom.contains(child._dom);
60
+ return this.dom.contains(child._dom);
57
61
  }
58
62
  clearChildren() {
59
- this.#dom.clearChildren();
60
- this.#cachedChildNodes = null;
63
+ this.dom.clearChildren();
64
+ this.cachedChildNodes = null;
61
65
  }
62
66
  focus() {
63
- this.#dom.focus();
67
+ this.dom.focus();
64
68
  }
65
69
  addEventListener(type, listener, useCapture) {
66
70
  // @ts-ignore
67
- this.#dom.addEventListener(type, listener.bind(this), useCapture);
71
+ this.dom.addEventListener(type, listener.bind(this), useCapture ? true : false);
68
72
  }
69
73
  removeEventListener(type, listener, useCapture) {
70
74
  // @ts-ignore
71
- this.#dom.removeEventListener(type, listener.bind(this), useCapture);
75
+ this.dom.removeEventListener(type, listener.bind(this), useCapture ? true : false);
72
76
  }
73
77
  setAttribute(name, value) {
74
- this.#dom.setAttribute(name, value);
78
+ this.dom.setAttribute(name, value);
75
79
  }
76
80
  removeAttribute(name) {
77
- this.#dom.removeAttribute(name);
81
+ this.dom.removeAttribute(name);
78
82
  }
79
83
  }
package/dist/index.js CHANGED
@@ -33,4 +33,7 @@ export function h(type, props, ...children) {
33
33
  }
34
34
  export { emo } from "./styling/index";
35
35
  // @ts-ignore
36
- globalThis.document = new DocumentWrapper(___document);
36
+ if (typeof ___document != "undefined") {
37
+ // @ts-ignore
38
+ globalThis.document = new DocumentWrapper(___document);
39
+ }
package/dom/document.ts CHANGED
@@ -5,6 +5,8 @@ interface ElementCreationOptions {
5
5
  }
6
6
 
7
7
  export class DocumentWrapper {
8
+ public get _doc(): CS.OneJS.Dom.Document { return this.#doc }
9
+
8
10
  #doc: CS.OneJS.Dom.Document;
9
11
  #body: DomWrapper;
10
12
 
@@ -12,7 +14,8 @@ export class DocumentWrapper {
12
14
 
13
15
  constructor(doc: CS.OneJS.Dom.Document) {
14
16
  this.#doc = doc
15
- this.#body = new DomWrapper(doc.body)
17
+ if (doc.body)
18
+ this.#body = new DomWrapper(doc.body)
16
19
  }
17
20
 
18
21
  addRuntimeUSS(uss: string): void {
@@ -41,7 +44,7 @@ export class DocumentWrapper {
41
44
 
42
45
  querySelectorAll(selector: string): DomWrapper[] {
43
46
  let doms = this.#doc.querySelectorAll(selector)
44
- let res = []
47
+ let res = [] as any[]
45
48
  for (let i = 0; i < doms.Length; i++) {
46
49
  res.push(new DomWrapper(doms.get_Item(i)))
47
50
  }
package/dom/dom-style.ts CHANGED
@@ -22,4 +22,6 @@ export class DomStyleWrapper implements CS.OneJS.Dom.DomStyle {
22
22
  }
23
23
  }
24
24
 
25
- export interface DomStyleWrapper extends CS.OneJS.Dom.DomStyle { }
25
+ export interface DomStyleWrapper extends CS.OneJS.Dom.DomStyle {
26
+ [key: string | symbol]: any;
27
+ }
package/dom/dom.ts CHANGED
@@ -2,94 +2,98 @@ import { EventBase } from "UnityEngine/UIElements";
2
2
  import { DomStyleWrapper } from "./dom-style"
3
3
 
4
4
  export class DomWrapper {
5
- public get _dom(): CS.OneJS.Dom.Dom { return this.#dom }
6
- public get ve(): CS.UnityEngine.UIElements.VisualElement { return this.#dom.ve }
5
+ public get _dom(): CS.OneJS.Dom.Dom { return this.dom }
6
+ public get ve(): CS.UnityEngine.UIElements.VisualElement { return this.dom.ve }
7
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;
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
11
  while (i--) {
12
- this.#cachedChildNodes[i] = new DomWrapper(this.#dom.childNodes.get_Item(i));
12
+ this.cachedChildNodes[i] = new DomWrapper(this.dom.childNodes.get_Item(i));
13
13
  }
14
- return this.#cachedChildNodes
14
+ return this.cachedChildNodes
15
15
  }
16
16
  public get firstChild(): DomWrapper | null {
17
- return this.#dom.firstChild ? new DomWrapper(this.#dom.firstChild) : null;
17
+ return this.dom.firstChild ? new DomWrapper(this.dom.firstChild) : null;
18
18
  }
19
19
  public get parentNode(): DomWrapper | null {
20
- return this.#dom.parentNode ? new DomWrapper(this.#dom.parentNode) : null;
20
+ return this.dom.parentNode ? new DomWrapper(this.dom.parentNode) : null;
21
21
  }
22
22
  public get nextSibling(): DomWrapper | null {
23
- return this.#dom.nextSibling ? new DomWrapper(this.#dom.nextSibling) : null;
23
+ return this.dom.nextSibling ? new DomWrapper(this.dom.nextSibling) : null;
24
24
  }
25
25
 
26
- public get nodeType(): number { return this.#dom.nodeType }
27
- public get style(): DomStyleWrapper { return this.#domStyleWrapper }
28
- public get Id(): string { return this.#dom.Id }
29
- public set Id(value: string) { this.#dom.Id = value }
30
- public get key(): string { return this.#dom.key }
31
- public set key(value: string) { this.#dom.key = value }
32
- public get value(): any { return this.#dom.value }
33
- public get checked(): boolean { return this.#dom.checked }
34
- public get data(): any { return this.#dom.data }
35
- public set data(value: any) { this.#dom.data = value }
36
-
37
- public get classname(): string { return this.#dom.classname }
38
- public set classname(value: string) { this.#dom.classname = value }
39
-
40
- #dom: CS.OneJS.Dom.Dom
41
- #domStyleWrapper: DomStyleWrapper
42
-
43
- #cachedChildNodes: DomWrapper[] = null
26
+ public get nodeType(): number { return this.dom.nodeType }
27
+ public get style(): DomStyleWrapper { return this.domStyleWrapper }
28
+ public get Id(): string { return this.dom.Id }
29
+ public set Id(value: string) { this.dom.Id = value }
30
+ public get key(): string { return this.dom.key }
31
+ public set key(value: string) { this.dom.key = value }
32
+ public get value(): any { return this.dom.value }
33
+ public get checked(): boolean { return this.dom.checked }
34
+ public get data(): any { return this.dom.data }
35
+ public set data(value: any) { this.dom.data = value }
36
+
37
+ public get classname(): string { return this.dom.classname }
38
+ public set classname(value: string) { this.dom.classname = value }
39
+
40
+ /**
41
+ * Not using private fields because of issues with the `#private;` line
42
+ * generated by tsc
43
+ */
44
+ dom: CS.OneJS.Dom.Dom
45
+ domStyleWrapper: DomStyleWrapper
46
+
47
+ cachedChildNodes: DomWrapper[] | null = null
44
48
 
45
49
  constructor(dom: CS.OneJS.Dom.Dom) {
46
- this.#dom = dom
47
- this.#domStyleWrapper = new DomStyleWrapper(dom.style)
50
+ this.dom = dom
51
+ this.domStyleWrapper = new DomStyleWrapper(dom.style)
48
52
  }
49
53
 
50
54
  appendChild(child: DomWrapper) {
51
- this.#dom.appendChild(child.#dom)
52
- this.#cachedChildNodes = null
55
+ this.dom.appendChild(child.dom)
56
+ this.cachedChildNodes = null
53
57
  }
54
58
 
55
59
  removeChild(child: DomWrapper) {
56
- this.#dom.removeChild(child.#dom)
57
- this.#cachedChildNodes = null
60
+ this.dom.removeChild(child.dom)
61
+ this.cachedChildNodes = null
58
62
  }
59
63
 
60
64
  insertBefore(a: DomWrapper, b: DomWrapper) {
61
- this.#dom.insertBefore(a?._dom, b?._dom)
62
- this.#cachedChildNodes = null
65
+ this.dom.insertBefore(a?._dom, b?._dom)
66
+ this.cachedChildNodes = null
63
67
  }
64
68
 
65
69
  contains(child: DomWrapper) {
66
- return this.#dom.contains(child._dom)
70
+ return this.dom.contains(child._dom)
67
71
  }
68
72
 
69
73
  clearChildren() {
70
- this.#dom.clearChildren()
71
- this.#cachedChildNodes = null
74
+ this.dom.clearChildren()
75
+ this.cachedChildNodes = null
72
76
  }
73
77
 
74
78
  focus() {
75
- this.#dom.focus()
79
+ this.dom.focus()
76
80
  }
77
81
 
78
82
  addEventListener(type: string, listener: (event: EventBase) => void, useCapture?: boolean) {
79
83
  // @ts-ignore
80
- this.#dom.addEventListener(type, listener.bind(this), useCapture)
84
+ this.dom.addEventListener(type, listener.bind(this), useCapture ? true : false)
81
85
  }
82
86
 
83
87
  removeEventListener(type: string, listener: (event: EventBase) => void, useCapture?: boolean) {
84
88
  // @ts-ignore
85
- this.#dom.removeEventListener(type, listener.bind(this), useCapture)
89
+ this.dom.removeEventListener(type, listener.bind(this), useCapture ? true : false)
86
90
  }
87
91
 
88
92
  setAttribute(name: string, value: any) {
89
- this.#dom.setAttribute(name, value)
93
+ this.dom.setAttribute(name, value)
90
94
  }
91
95
 
92
96
  removeAttribute(name: string) {
93
- this.#dom.removeAttribute(name)
97
+ this.dom.removeAttribute(name)
94
98
  }
95
99
  }
package/index.ts CHANGED
@@ -37,7 +37,7 @@ export function h(type: any, props: any, ...children: any[]): any {
37
37
  export { emo } from "./styling/index"
38
38
 
39
39
  declare global {
40
- interface Document extends DocumentWrapper {}
40
+ interface Document extends DocumentWrapper { }
41
41
  interface Element extends DomWrapper {
42
42
  classname: string
43
43
  nodeType: number
@@ -46,4 +46,7 @@ declare global {
46
46
  }
47
47
 
48
48
  // @ts-ignore
49
- globalThis.document = new DocumentWrapper(___document)
49
+ if (typeof ___document != "undefined") {
50
+ // @ts-ignore
51
+ globalThis.document = new DocumentWrapper(___document)
52
+ }
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.39",
4
+ "version": "0.3.41",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./typings.d.ts",
7
7
  "dependencies": {
@@ -2,42 +2,41 @@ import * as fs from "fs";
2
2
  import * as path from "path";
3
3
 
4
4
  export const importTransformPlugin = {
5
- name: "onejs-import-transform",
6
- setup(build) {
7
- // First pass: Mark C# imports as external
8
- build.onResolve({ filter: /^(Unity\/|UnityEngine|OneJS)/ }, (args) => {
9
- return { path: args.path, external: true };
10
- });
5
+ name: "onejs-import-transform",
6
+ setup(build) {
7
+ // First pass: Mark imports from modules starting with a capital letter as external
8
+ build.onResolve({ filter: /^[A-Z]/ }, (args) => {
9
+ return { path: args.path, external: true };
10
+ });
11
11
 
12
- // Second pass: Transform all JS and TSX files
13
- build.onLoad({ filter: /\.(js|jsx|ts|tsx)$/ }, async (args) => {
14
- let contents = await fs.promises.readFile(args.path, "utf8");
12
+ // Second pass: Transform all JS and TSX files
13
+ build.onLoad({ filter: /\.(js|jsx|ts|tsx)$/ }, async (args) => {
14
+ let contents = await fs.promises.readFile(args.path, "utf8");
15
15
 
16
- // Transform Unity imports
17
- contents = contents.replace(
18
- /import\s+(?:{([^}]+)})?\s*from\s*["'](Unity\/[^"']*|UnityEngine[^"']*|OneJS[^"']*)["'];?/g,
19
- (match, imports, moduleName) => {
20
- moduleName = moduleName.replace(/\//g, ".");
21
- if (imports) {
22
- const importItems = imports.split(",").map((item) => item.trim());
23
- return `const { ${importItems.join(", ")} } = CS.${moduleName};`;
24
- } else {
25
- const namespaceName = moduleName.split(".").pop();
26
- return `const ${namespaceName} = CS.${moduleName};`;
27
- }
28
- }
29
- );
16
+ // Transform imports from modules starting with a capital letter
17
+ contents = contents.replace(
18
+ /import\s+(?:{([^}]+)})?\s*from\s*["']([A-Z][^"']*)["'];?/g,
19
+ (match, imports, moduleName) => {
20
+ moduleName = moduleName.replace(/\//g, ".");
21
+ if (imports) {
22
+ const importItems = imports.split(",").map((item) => item.trim());
23
+ return `const { ${importItems.join(", ")} } = CS.${moduleName};`;
24
+ } else {
25
+ const namespaceName = moduleName.split(".").pop();
26
+ return `const ${namespaceName} = CS.${moduleName};`;
27
+ }
28
+ }
29
+ );
30
30
 
31
- // Transform any remaining require statements for Unity modules
32
- contents = contents.replace(
33
- /__require\(["'](Unity\/[^"']*|UnityEngine[^"']*|OneJS[^"']*)["']\)/g,
34
- (match, moduleName) => {
35
- return `CS.${moduleName.replace(/\//g, ".")}`;
36
- }
37
- );
31
+ // Transform any remaining require statements for such modules
32
+ contents = contents.replace(
33
+ /__require\(["']([A-Z][^"']*)["']\)/g,
34
+ (match, moduleName) => {
35
+ return `CS.${moduleName.replace(/\//g, ".")}`;
36
+ }
37
+ );
38
38
 
39
- return { contents, loader: path.extname(args.path).slice(1) };
40
- });
41
- },
39
+ return { contents, loader: path.extname(args.path).slice(1) };
40
+ });
41
+ },
42
42
  };
43
-