onejs-core 1.0.29 → 1.0.32

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.
@@ -155,8 +155,8 @@ declare namespace CS {
155
155
  class WebApi extends System.Object
156
156
  {
157
157
  protected [__keep_incompatibility]: never;
158
- public getText ($uri: string, $callback: System.Action$1<string>) : UnityEngine.Coroutine
159
- public getImage ($url: string, $callback: System.Action$1<UnityEngine.Texture2D>) : UnityEngine.Coroutine
158
+ public getText ($uri: string, $callback: System.Action$1<string>, $headersJson?: string) : UnityEngine.Coroutine
159
+ public getImage ($url: string, $callback: System.Action$1<UnityEngine.Texture2D>, $headersJson?: string, $forceRefresh?: boolean) : UnityEngine.Coroutine
160
160
  public constructor ()
161
161
  }
162
162
  class Runner extends UnityEngine.MonoBehaviour
@@ -478,6 +478,9 @@ declare namespace CS {
478
478
  public static FindTypesInNamespace ($namespaceName: string) : System.Collections.Generic.List$1<System.Type>
479
479
  public constructor ()
480
480
  }
481
+ class TypeUtil {
482
+ public static GetType(obj: any): System.Type; // More reliable to use this than `obj.GetType()` for puerts blittable types
483
+ }
481
484
  class FloatConvUtil extends System.Object
482
485
  {
483
486
  protected [__keep_incompatibility]: never;
@@ -66,6 +66,9 @@ type TransitionStartEvent = CS.UnityEngine.UIElements.TransitionStartEvent;
66
66
  type ValidateCommandEvent = CS.UnityEngine.UIElements.ValidateCommandEvent;
67
67
  type VectorImage = CS.UnityEngine.UIElements.VectorImage;
68
68
  type WheelEvent = CS.UnityEngine.UIElements.WheelEvent;
69
+ type ContextualMenuPopulateEvent = CS.UnityEngine.UIElements.ContextualMenuPopulateEvent;
70
+
71
+ type TwoPaneSplitViewOrientation = CS.UnityEngine.UIElements.TwoPaneSplitViewOrientation;
69
72
 
70
73
  declare global {
71
74
  export namespace JSX {
@@ -129,7 +132,7 @@ declare global {
129
132
  onMouseLeaveWindow?: (e: MouseLeaveWindowEvent) => void
130
133
  onMouseOver?: (e: MouseOverEvent) => void
131
134
  onMouseOut?: (e: MouseOutEvent) => void
132
- // onContextualMenuPopulate?: (e: ContextualMenuPopulateEvent) => void
135
+ onContextualMenuPopulate?: (e: ContextualMenuPopulateEvent) => void
133
136
  onNavigationMove?: (e: NavigationMoveEvent) => void
134
137
  // onNavigationTab?: (e: NavigationTabEvent) => void
135
138
  onNavigationCancel?: (e: NavigationCancelEvent) => void
@@ -315,6 +318,7 @@ declare global {
315
318
  "high-limit"?: number
316
319
  "min-value"?: number
317
320
  "max-value"?: number
321
+ value?: Vector2
318
322
  }
319
323
 
320
324
  interface EnumField extends BaseField<number> {
@@ -465,6 +469,12 @@ declare global {
465
469
  value?: string
466
470
  }
467
471
 
472
+ interface TwoPaneSplitView extends VisualElement {
473
+ fixedPaneIndex?: number
474
+ fixedPaneInitialDimension?: number
475
+ orientation?: TwoPaneSplitViewOrientation
476
+ }
477
+
468
478
  /**
469
479
  * OneJS Elements
470
480
  */
@@ -530,6 +540,8 @@ declare global {
530
540
  popupwindow: PopupWindow
531
541
  dropdownfield: DropdownField
532
542
 
543
+ "twopane-splitview": TwoPaneSplitView
544
+
533
545
  // /* OneJS Custom */
534
546
  img: Img
535
547
  gradientrect: GradientRect
@@ -1,5 +1,4 @@
1
1
 
2
-
3
2
  declare namespace CS.UnityEngine {
4
3
  interface GameObject {
5
4
  GetComp<T>(type: { new(): T }): T
@@ -10,4 +9,34 @@ declare namespace CS.UnityEngine {
10
9
  GetComp<T>(type: { new(): T }): T
11
10
  AddComp<T>(type: { new(): T }): T
12
11
  }
12
+ }
13
+
14
+ type CSArray = CS.System.Array
15
+
16
+ declare namespace CS.System {
17
+ interface Array {
18
+ get<T>(index: number): T
19
+ set<T>(index: number, value: T): void
20
+ toJsArray<T>(): T[]
21
+ at<T>(index: number): T
22
+ forEach<T>(callbackfn: (value: T, index: number, array: CSArray) => void): void
23
+ map<T, U>(type: { new(...args: any[]): U }, callbackfn: (value: T, index: number, array: CSArray) => U): CSArray
24
+ filter<T>(callbackfn: (value: T, index: number, array: CSArray) => boolean): CSArray
25
+ reduce<T>(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: CSArray) => T): T
26
+ reduceRight<T>(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: CSArray) => T): T
27
+ find<T>(predicate: (value: T, index: number, array: CSArray) => boolean): T
28
+ findIndex<T>(predicate: (value: T, index: number, array: CSArray) => boolean): number
29
+ indexOf<T>(searchElement: T, fromIndex?: number): number
30
+ lastIndexOf<T>(searchElement: T, fromIndex?: number): number
31
+ some<T>(callbackfn: (value: T, index: number, array: CSArray) => boolean): boolean
32
+ every<T>(callbackfn: (value: T, index: number, array: CSArray) => boolean): boolean
33
+ slice<T>(start?: number, end?: number): CSArray
34
+ concat<T>(...items: CSArray[]): T[]
35
+ join(separator?: string): string
36
+ sort<T>(compareFn?: (a: T, b: T) => number): CSArray
37
+ reverse(): CSArray
38
+ includes<T>(searchElement: T, fromIndex?: number): boolean
39
+ fill<T>(value: T, start?: number, end?: number): CSArray
40
+ copyWithin<T>(target: number, start: number, end?: number): CSArray
41
+ }
13
42
  }
@@ -0,0 +1,3 @@
1
+ export declare function newArray<T>(type: {
2
+ new (): T;
3
+ }, count: any): CS.System.Array;
@@ -0,0 +1,3 @@
1
+ export function newArray(type, count) {
2
+ return CS.System.Array.CreateInstance(puer.$typeof(type), count);
3
+ }
package/dist/index.d.ts CHANGED
@@ -18,4 +18,8 @@ declare global {
18
18
  nodeType: number;
19
19
  ve: CS.UnityEngine.UIElements.VisualElement;
20
20
  }
21
+ const newCsArray: <T>(type: {
22
+ new (...args: any[]): T;
23
+ }, count: number) => CS.System.Array;
24
+ const toJsArray: <T>(csArr: CS.System.Array) => T[];
21
25
  }
package/dist/index.js CHANGED
@@ -38,3 +38,4 @@ if (typeof ___document != "undefined") {
38
38
  // @ts-ignore
39
39
  globalThis.document = new DocumentWrapper(___document);
40
40
  }
41
+ // puer.$extension(CS.UnityEngine.UIElements.VisualElement, CS.UnityEngine.UIElements.VisualElementExtensions)
@@ -0,0 +1,86 @@
1
+ /// <reference path="../../definitions/modules.d.ts" />
2
+ import { Matrix4x4, Quaternion, Vector2, Vector2Int, Vector3, Vector3Int, Vector4, Color } from "UnityEngine";
3
+ type CSArray = CS.System.Array;
4
+ export declare function vec2(x: number, y: number): Vector2;
5
+ export declare function vec2i(x: number, y: number): Vector2Int;
6
+ export declare function vec3(x: number, y: number, z: number): Vector3;
7
+ export declare function vec3i(x: number, y: number, z: number): Vector3Int;
8
+ export declare function vec4(x: number, y: number, z: number, w: number): Vector4;
9
+ export declare function quat(): Quaternion;
10
+ export declare function quat(x: number, y: number, z: number, w: number): Quaternion;
11
+ export declare function euler(x: number, y: number, z: number): Quaternion;
12
+ export declare function mat4x4(): Matrix4x4;
13
+ export declare function mat4x4(a: Vector4, b: Vector4, c: Vector4, d: Vector4): Matrix4x4;
14
+ export declare function mat4x4(a: number[][]): Matrix4x4;
15
+ export declare function trs(translation: Vector3, rotation: Quaternion, scale: Vector3): Matrix4x4;
16
+ export declare function floatArray(...items: number[]): CSArray;
17
+ export declare function vec2Array(...items: number[][]): CSArray;
18
+ export declare function vec2iArray(...items: number[][]): CSArray;
19
+ export declare function vec3Array(...items: number[][]): CSArray;
20
+ export declare function vec3iArray(...items: number[][]): CSArray;
21
+ export declare function vec4Array(...items: number[][]): CSArray;
22
+ export declare function add(a: Vector2, b: Vector2): Vector2;
23
+ export declare function add(a: Vector3, b: Vector3): Vector3;
24
+ export declare function add(a: Vector2Int, b: Vector2Int): Vector2Int;
25
+ export declare function add(a: Vector3Int, b: Vector3Int): Vector3Int;
26
+ export declare function add(a: Vector4, b: Vector4): Vector4;
27
+ export declare function sub(a: Vector2, b: Vector2): Vector2;
28
+ export declare function sub(a: Vector3, b: Vector3): Vector3;
29
+ export declare function sub(a: Vector2Int, b: Vector2Int): Vector2Int;
30
+ export declare function sub(a: Vector3Int, b: Vector3Int): Vector3Int;
31
+ export declare function sub(a: Vector4, b: Vector4): Vector4;
32
+ export declare function neg(a: Vector2): Vector2;
33
+ export declare function neg(a: Vector3): Vector3;
34
+ export declare function neg(a: Vector2Int): Vector2Int;
35
+ export declare function neg(a: Vector3Int): Vector3Int;
36
+ export declare function neg(a: Vector4): Vector4;
37
+ export declare function mul(a: Vector2, b: number): Vector2;
38
+ export declare function mul(a: number, b: Vector2): Vector3;
39
+ export declare function mul(a: Vector3, b: number): Vector3;
40
+ export declare function mul(a: number, b: Vector3): Vector3;
41
+ export declare function mul(a: Vector2Int, b: number): Vector2Int;
42
+ export declare function mul(a: number, b: Vector2Int): Vector2Int;
43
+ export declare function mul(a: Vector3Int, b: number): Vector3Int;
44
+ export declare function mul(a: number, b: Vector3Int): Vector3Int;
45
+ export declare function mul(a: Vector4, b: number): Vector4;
46
+ export declare function mul(a: number, b: Vector4): Vector4;
47
+ export declare function mul(a: Quaternion, b: Quaternion): Quaternion;
48
+ export declare function mul(a: Quaternion, b: Vector3): Vector3;
49
+ export declare function mul(a: Matrix4x4, b: Matrix4x4): Matrix4x4;
50
+ export declare function mul(a: Matrix4x4, b: Vector4): Vector4;
51
+ export declare function div(a: Vector2, b: number): Vector2;
52
+ export declare function div(a: Vector3, b: number): Vector3;
53
+ export declare function div(a: Vector2Int, b: number): Vector2Int;
54
+ export declare function div(a: Vector3Int, b: number): Vector3Int;
55
+ export declare function eq(a: Vector2, b: Vector2): boolean;
56
+ export declare function eq(a: Vector3, b: Vector3): boolean;
57
+ export declare function eq(a: Vector2Int, b: Vector2Int): boolean;
58
+ export declare function eq(a: Vector3Int, b: Vector3Int): boolean;
59
+ export declare function eq(a: Quaternion, b: Quaternion): boolean;
60
+ export declare function dot(a: Vector2, b: Vector2): number;
61
+ export declare function dot(a: Vector3, b: Vector3): number;
62
+ export declare function dot(a: Vector4, b: Vector4): number;
63
+ export declare function dot(a: Quaternion, b: Quaternion): number;
64
+ export declare function clamp(a: Vector2, min: Vector2, max: Vector2): Vector2;
65
+ export declare function clamp(a: Vector3, min: Vector3, max: Vector3): Vector3;
66
+ export declare function clamp(a: Vector2Int, min: Vector2Int, max: Vector2Int): Vector2Int;
67
+ export declare function clamp(a: Vector3Int, min: Vector3Int, max: Vector3Int): Vector3Int;
68
+ export declare function clamp(a: Vector4, min: Vector4, max: Vector4): Vector4;
69
+ export declare function clamp01(a: Vector2): Vector2;
70
+ export declare function clamp01(a: Vector3): Vector3;
71
+ export declare function clamp01(a: Vector4): Vector4;
72
+ export declare function distance(a: Vector2, b: Vector2): number;
73
+ export declare function distance(a: Vector3, b: Vector3): number;
74
+ export declare function distance(a: Vector2Int, b: Vector2Int): number;
75
+ export declare function distance(a: Vector3Int, b: Vector3Int): number;
76
+ export declare function distance(a: Vector4, b: Vector4): number;
77
+ export declare function normalize(a: Vector2): Vector2;
78
+ export declare function normalize(a: Vector3): Vector3;
79
+ export declare function normalize(a: Vector4): Vector4;
80
+ export declare function lerp(a: number, b: number, t: number): number;
81
+ export declare function lerp(a: Vector2, b: Vector2, t: number): Vector2;
82
+ export declare function lerp(a: Vector3, b: Vector3, t: number): Vector3;
83
+ export declare function lerp(a: Vector4, b: Vector4, t: number): Vector4;
84
+ export declare function lerp(a: Quaternion, b: Quaternion, t: number): Quaternion;
85
+ export declare function lerp(a: Color, b: Color, t: number): Color;
86
+ export {};
@@ -0,0 +1,361 @@
1
+ import { Matrix4x4, Quaternion, Vector2, Vector2Int, Vector3, Vector3Int, Vector4, Color } from "UnityEngine";
2
+ const getType = CS.OneJS.Utils.TypeUtil.GetType;
3
+ const { $typeof } = puer;
4
+ // MARK: - Vectors
5
+ export function vec2(x, y) {
6
+ return new Vector2(x, y);
7
+ }
8
+ export function vec2i(x, y) {
9
+ return new Vector2Int(x, y);
10
+ }
11
+ export function vec3(x, y, z) {
12
+ return new Vector3(x, y, z);
13
+ }
14
+ export function vec3i(x, y, z) {
15
+ return new Vector3Int(x, y, z);
16
+ }
17
+ export function vec4(x, y, z, w) {
18
+ return new Vector4(x, y, z, w);
19
+ }
20
+ export function quat(x, y, z, w) {
21
+ if (x === undefined && y === undefined && z === undefined && w === undefined) {
22
+ return Quaternion.identity;
23
+ }
24
+ if (x !== undefined && y !== undefined && z !== undefined && w !== undefined) {
25
+ return new Quaternion(x, y, z, w);
26
+ }
27
+ throw new Error("Invalid arguments: either no arguments or exactly four numbers.");
28
+ }
29
+ export function euler(x, y, z) {
30
+ return Quaternion.Euler(x, y, z);
31
+ }
32
+ export function mat4x4(a, b, c, d) {
33
+ if (a === undefined && b === undefined && c === undefined && d === undefined) {
34
+ return Matrix4x4.identity;
35
+ }
36
+ if (a instanceof Vector4 && b instanceof Vector4 && c instanceof Vector4 && d instanceof Vector4) {
37
+ return new Matrix4x4(a, b, c, d);
38
+ }
39
+ if (Array.isArray(a) && a.length === 4 && a.every(v => Array.isArray(v) && v.length === 4)) {
40
+ return new Matrix4x4(vec4(a[0][0], a[0][1], a[0][2], a[0][3]), vec4(a[1][0], a[1][1], a[1][2], a[1][3]), vec4(a[2][0], a[2][1], a[2][2], a[2][3]), vec4(a[3][0], a[3][1], a[3][2], a[3][3]));
41
+ }
42
+ throw new Error("Invalid arguments: either no arguments, four Vector4s or a 4x4 array of numbers.");
43
+ }
44
+ export function trs(translation, rotation, scale) {
45
+ return Matrix4x4.TRS(translation, rotation, scale);
46
+ }
47
+ // MARK: - Arrays
48
+ export function floatArray(...items) {
49
+ const result = newCsArray(CS.System.Single, items.length);
50
+ for (let i = 0; i < items.length; i++) {
51
+ result.set(i, items[i]);
52
+ }
53
+ return result;
54
+ }
55
+ export function vec2Array(...items) {
56
+ const result = newCsArray(Vector2, items.length);
57
+ for (let i = 0; i < items.length; i++) {
58
+ result.set(i, vec2(items[i][0], items[i][1]));
59
+ }
60
+ return result;
61
+ }
62
+ export function vec2iArray(...items) {
63
+ const result = newCsArray(Vector2Int, items.length);
64
+ for (let i = 0; i < items.length; i++) {
65
+ result.set(i, vec2i(items[i][0], items[i][1]));
66
+ }
67
+ return result;
68
+ }
69
+ export function vec3Array(...items) {
70
+ const result = newCsArray(Vector3, items.length);
71
+ for (let i = 0; i < items.length; i++) {
72
+ result.set(i, vec3(items[i][0], items[i][1], items[i][2]));
73
+ }
74
+ return result;
75
+ }
76
+ export function vec3iArray(...items) {
77
+ const result = newCsArray(Vector3Int, items.length);
78
+ for (let i = 0; i < items.length; i++) {
79
+ result.set(i, vec3i(items[i][0], items[i][1], items[i][2]));
80
+ }
81
+ return result;
82
+ }
83
+ export function vec4Array(...items) {
84
+ const result = newCsArray(Vector4, items.length);
85
+ for (let i = 0; i < items.length; i++) {
86
+ result.set(i, vec4(items[i][0], items[i][1], items[i][2], items[i][3]));
87
+ }
88
+ return result;
89
+ }
90
+ export function add(a, b) {
91
+ function isBothOfType(type) {
92
+ return getType(a) == $typeof(type) && getType(b) == $typeof(type);
93
+ }
94
+ if (isBothOfType(Vector2)) {
95
+ return Vector2.op_Addition(a, b);
96
+ }
97
+ else if (isBothOfType(Vector2Int)) {
98
+ return Vector2Int.op_Addition(a, b);
99
+ }
100
+ else if (isBothOfType(Vector3)) {
101
+ return Vector3.op_Addition(a, b);
102
+ }
103
+ else if (isBothOfType(Vector3Int)) {
104
+ return Vector3Int.op_Addition(a, b);
105
+ }
106
+ else if (isBothOfType(Vector4)) {
107
+ return Vector4.op_Addition(a, b);
108
+ }
109
+ throw new Error("Unsupported types for add operation");
110
+ }
111
+ export function sub(a, b) {
112
+ function isBothOfType(type) {
113
+ return getType(a) == $typeof(type) && getType(b) == $typeof(type);
114
+ }
115
+ if (isBothOfType(Vector2)) {
116
+ return Vector2.op_Subtraction(a, b);
117
+ }
118
+ else if (isBothOfType(Vector2Int)) {
119
+ return Vector2Int.op_Subtraction(a, b);
120
+ }
121
+ else if (isBothOfType(Vector3)) {
122
+ return Vector3.op_Subtraction(a, b);
123
+ }
124
+ else if (isBothOfType(Vector3Int)) {
125
+ return Vector3Int.op_Subtraction(a, b);
126
+ }
127
+ else if (isBothOfType(Vector4)) {
128
+ return Vector4.op_Subtraction(a, b);
129
+ }
130
+ throw new Error("Unsupported types for sub operation");
131
+ }
132
+ export function neg(a) {
133
+ if (getType(a) == $typeof(Vector2)) {
134
+ return Vector2.op_UnaryNegation(a);
135
+ }
136
+ else if (getType(a) == $typeof(Vector2Int)) {
137
+ return Vector2Int.op_UnaryNegation(a);
138
+ }
139
+ else if (getType(a) == $typeof(Vector3)) {
140
+ return Vector3.op_UnaryNegation(a);
141
+ }
142
+ else if (getType(a) == $typeof(Vector3Int)) {
143
+ return Vector3Int.op_UnaryNegation(a);
144
+ }
145
+ else if (getType(a) == $typeof(Vector4)) {
146
+ return Vector4.op_UnaryNegation(a);
147
+ }
148
+ throw new Error("Unsupported types for neg operation");
149
+ }
150
+ export function mul(a, b) {
151
+ if (isOfType(a, Quaternion) && isOfType(b, Quaternion)) {
152
+ return Quaternion.op_Multiply(a, b);
153
+ }
154
+ if (isOfType(a, Quaternion) && isOfType(b, Vector3)) {
155
+ return Quaternion.op_Multiply(a, b);
156
+ }
157
+ if (isOfType(a, Matrix4x4) && isOfType(b, Matrix4x4)) {
158
+ return Matrix4x4.op_Multiply(a, b);
159
+ }
160
+ if (isOfType(a, Matrix4x4) && isOfType(b, Vector4)) {
161
+ return Matrix4x4.op_Multiply(a, b);
162
+ }
163
+ if (typeof b === 'number') {
164
+ if (getType(a) == $typeof(Vector2)) {
165
+ return Vector2.op_Multiply(a, b);
166
+ }
167
+ else if (getType(a) == $typeof(Vector2Int)) {
168
+ return Vector2Int.op_Multiply(a, b);
169
+ }
170
+ else if (getType(a) == $typeof(Vector3)) {
171
+ return Vector3.op_Multiply(a, b);
172
+ }
173
+ else if (getType(a) == $typeof(Vector3Int)) {
174
+ return Vector3Int.op_Multiply(a, b);
175
+ }
176
+ else if (getType(a) == $typeof(Vector4)) {
177
+ return Vector4.op_Multiply(a, b);
178
+ }
179
+ }
180
+ else if (typeof a === 'number') {
181
+ if (getType(b) == $typeof(Vector2)) {
182
+ return Vector2.op_Multiply(b, a);
183
+ }
184
+ else if (getType(b) == $typeof(Vector2Int)) {
185
+ return Vector2Int.op_Multiply(b, a);
186
+ }
187
+ else if (getType(b) == $typeof(Vector3)) {
188
+ return Vector3.op_Multiply(b, a);
189
+ }
190
+ else if (getType(b) == $typeof(Vector3Int)) {
191
+ return Vector3Int.op_Multiply(b, a);
192
+ }
193
+ else if (getType(b) == $typeof(Vector4)) {
194
+ return Vector4.op_Multiply(b, a);
195
+ }
196
+ }
197
+ throw new Error("Unsupported types for mul operation");
198
+ }
199
+ export function div(a, b) {
200
+ if (typeof b === 'number') {
201
+ if (getType(a) == $typeof(Vector2)) {
202
+ return Vector2.op_Division(a, b);
203
+ }
204
+ else if (getType(a) == $typeof(Vector2Int)) {
205
+ return Vector2Int.op_Division(a, b);
206
+ }
207
+ else if (getType(a) == $typeof(Vector3)) {
208
+ return Vector3.op_Division(a, b);
209
+ }
210
+ else if (getType(a) == $typeof(Vector3Int)) {
211
+ return Vector3Int.op_Division(a, b);
212
+ }
213
+ }
214
+ throw new Error("Unsupported types for div operation");
215
+ }
216
+ export function eq(a, b) {
217
+ function isBothOfType(type) {
218
+ return getType(a) == $typeof(type) && getType(b) == $typeof(type);
219
+ }
220
+ if (isBothOfType(Vector2)) {
221
+ return Vector2.op_Equality(a, b);
222
+ }
223
+ else if (isBothOfType(Vector2Int)) {
224
+ return Vector2Int.op_Equality(a, b);
225
+ }
226
+ else if (isBothOfType(Vector3)) {
227
+ return Vector3.op_Equality(a, b);
228
+ }
229
+ else if (isBothOfType(Vector3Int)) {
230
+ return Vector3Int.op_Equality(a, b);
231
+ }
232
+ else if (isBothOfType(Quaternion)) {
233
+ return Quaternion.op_Equality(a, b);
234
+ }
235
+ throw new Error("Unsupported types for eq operation");
236
+ }
237
+ export function dot(a, b) {
238
+ function isBothOfType(type) {
239
+ return isOfType(a, type) && isOfType(b, type);
240
+ }
241
+ if (isBothOfType(Vector2)) {
242
+ return Vector2.Dot(a, b);
243
+ }
244
+ else if (isBothOfType(Vector3)) {
245
+ return Vector3.Dot(a, b);
246
+ }
247
+ else if (isBothOfType(Vector4)) {
248
+ return Vector4.Dot(a, b);
249
+ }
250
+ else if (isBothOfType(Quaternion)) {
251
+ return Quaternion.Dot(a, b);
252
+ }
253
+ throw new Error("Unsupported types for dot operation");
254
+ }
255
+ export function clamp(a, min, max) {
256
+ function isAllOfType(type) {
257
+ return isOfType(a, type) && isOfType(min, type) && isOfType(max, type);
258
+ }
259
+ if (isAllOfType(Vector2)) {
260
+ return vec2(Math.min(Math.max(a.x, min.x), max.x), Math.min(Math.max(a.y, min.y), max.y));
261
+ }
262
+ else if (isAllOfType(Vector3)) {
263
+ return vec3(Math.min(Math.max(a.x, min.x), max.x), Math.min(Math.max(a.y, min.y), max.y), Math.min(Math.max(a.z, min.z), max.z));
264
+ }
265
+ else if (isAllOfType(Vector2Int)) {
266
+ return vec2i(Math.min(Math.max(a.x, min.x), max.x), Math.min(Math.max(a.y, min.y), max.y));
267
+ }
268
+ else if (isAllOfType(Vector3Int)) {
269
+ return vec3i(Math.min(Math.max(a.x, min.x), max.x), Math.min(Math.max(a.y, min.y), max.y), Math.min(Math.max(a.z, min.z), max.z));
270
+ }
271
+ else if (isAllOfType(Vector4)) {
272
+ return vec4(Math.min(Math.max(a.x, min.x), max.x), Math.min(Math.max(a.y, min.y), max.y), Math.min(Math.max(a.z, min.z), max.z), Math.min(Math.max(a.w, min.w), max.w));
273
+ }
274
+ throw new Error("Unsupported types for clamp operation");
275
+ }
276
+ export function clamp01(a) {
277
+ if (isOfType(a, Vector2)) {
278
+ return vec2(Math.min(Math.max(a.x, 0), 1), Math.min(Math.max(a.y, 0), 1));
279
+ }
280
+ else if (isOfType(a, Vector3)) {
281
+ return vec3(Math.min(Math.max(a.x, 0), 1), Math.min(Math.max(a.y, 0), 1), Math.min(Math.max(a.z, 0), 1));
282
+ }
283
+ else if (isOfType(a, Vector4)) {
284
+ return vec4(Math.min(Math.max(a.x, 0), 1), Math.min(Math.max(a.y, 0), 1), Math.min(Math.max(a.z, 0), 1), Math.min(Math.max(a.w, 0), 1));
285
+ }
286
+ throw new Error("Unsupported types for clamp01 operation");
287
+ }
288
+ export function distance(a, b) {
289
+ function isBothOfType(type) {
290
+ return isOfType(a, type) && isOfType(b, type);
291
+ }
292
+ if (isBothOfType(Vector2)) {
293
+ return Vector2.Distance(a, b);
294
+ }
295
+ else if (isBothOfType(Vector3)) {
296
+ return Vector3.Distance(a, b);
297
+ }
298
+ else if (isBothOfType(Vector2Int)) {
299
+ const dx = a.x - b.x;
300
+ const dy = a.y - b.y;
301
+ return Math.sqrt(dx * dx + dy * dy);
302
+ }
303
+ else if (isBothOfType(Vector3Int)) {
304
+ const dx = a.x - b.x;
305
+ const dy = a.y - b.y;
306
+ const dz = a.z - b.z;
307
+ return Math.sqrt(dx * dx + dy * dy + dz * dz);
308
+ }
309
+ else if (isBothOfType(Vector4)) {
310
+ const dx = a.x - b.x;
311
+ const dy = a.y - b.y;
312
+ const dz = a.z - b.z;
313
+ const dw = a.w - b.w;
314
+ return Math.sqrt(dx * dx + dy * dy + dz * dz + dw * dw);
315
+ }
316
+ throw new Error("Unsupported types for distance operation");
317
+ }
318
+ export function normalize(a) {
319
+ if (isOfType(a, Vector2)) {
320
+ const magnitude = Math.sqrt(a.x * a.x + a.y * a.y);
321
+ if (magnitude < 1e-6) {
322
+ return vec2(0, 0);
323
+ }
324
+ return vec2(a.x / magnitude, a.y / magnitude);
325
+ }
326
+ else if (isOfType(a, Vector3)) {
327
+ return Vector3.Normalize(a);
328
+ }
329
+ else if (isOfType(a, Vector4)) {
330
+ return Vector4.Normalize(a);
331
+ }
332
+ throw new Error("Unsupported types for normalize operation");
333
+ }
334
+ export function lerp(a, b, t) {
335
+ function isBothOfType(type) {
336
+ return isOfType(a, type) && isOfType(b, type);
337
+ }
338
+ if (typeof a === 'number' && typeof b === 'number') {
339
+ return a + (b - a) * t;
340
+ }
341
+ else if (isBothOfType(Vector2)) {
342
+ return Vector2.Lerp(a, b, t);
343
+ }
344
+ else if (isBothOfType(Vector3)) {
345
+ return Vector3.Lerp(a, b, t);
346
+ }
347
+ else if (isBothOfType(Vector4)) {
348
+ return vec4(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t, a.z + (b.z - a.z) * t, a.w + (b.w - a.w) * t);
349
+ }
350
+ else if (isBothOfType(Quaternion)) {
351
+ return Quaternion.Lerp(a, b, t);
352
+ }
353
+ else if (isBothOfType(Color)) {
354
+ return Color.Lerp(a, b, t);
355
+ }
356
+ throw new Error("Unsupported types for lerp operation");
357
+ }
358
+ // MARK: - Utilities
359
+ function isOfType(obj, type) {
360
+ return getType(obj) == $typeof(type);
361
+ }
package/index.ts CHANGED
@@ -44,10 +44,14 @@ declare global {
44
44
  nodeType: number
45
45
  ve: CS.UnityEngine.UIElements.VisualElement
46
46
  }
47
+ const newCsArray: <T>(type: { new(...args: any[]): T }, count: number) => CS.System.Array
48
+ const toJsArray: <T>(csArr: CS.System.Array) => T[]
47
49
  }
48
50
 
49
51
  // @ts-ignore
50
52
  if (typeof ___document != "undefined") {
51
53
  // @ts-ignore
52
54
  globalThis.document = new DocumentWrapper(___document)
53
- }
55
+ }
56
+
57
+ // puer.$extension(CS.UnityEngine.UIElements.VisualElement, CS.UnityEngine.UIElements.VisualElementExtensions)