onejs-core 1.0.37 → 2.0.2
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/README.md +100 -2
- package/bin/oj.js +3 -0
- package/definitions/Assemblies/OneJS.Runtime.d.ts +2 -2
- package/dist/dom/dom.d.ts +23 -3
- package/dist/dom/dom.js +74 -5
- package/dist/index.d.ts +0 -3
- package/dom/dom.ts +84 -5
- package/index.ts +1 -3
- package/math/README.md +2 -2
- package/package.json +26 -23
- package/scripts/postcss/optional-import-plugin.cjs +26 -0
- package/scripts/postcss/tailwind-logging-plugin.cjs +12 -0
- package/scripts/switch.cjs +20 -10
- package/.github/workflows/jsr.yml +0 -19
- /package/scripts/{postcss-cleanup-plugin.cjs → postcss/cleanup-plugin.cjs} +0 -0
- /package/scripts/{onejs-tw-config.cjs → postcss/onejs-tw-config.cjs} +0 -0
- /package/scripts/{uss-transform-plugin.cjs → postcss/uss-transform-plugin.cjs} +0 -0
package/README.md
CHANGED
|
@@ -1,5 +1,103 @@
|
|
|
1
|
-
This is the Core JS Lib for OneJS V2. It
|
|
1
|
+
This is the Core JS Lib for OneJS V2. It contains the following:
|
|
2
2
|
|
|
3
3
|
1) Document and Dom wrappers
|
|
4
4
|
2) Type definitions for a good portion of built-in Unity assemblies
|
|
5
|
-
3) Utility scripts used by esbuild and tailwind
|
|
5
|
+
3) Utility scripts used by esbuild and tailwind
|
|
6
|
+
4) Convenience color parsing utils for better usage in JS
|
|
7
|
+
5) A suite of math utils to make vector, quaternion, and matrix math way easier in JS
|
|
8
|
+
|
|
9
|
+
## Examples
|
|
10
|
+
|
|
11
|
+
### Math Utils
|
|
12
|
+
|
|
13
|
+
https://github.com/Singtaa/onejs-core/tree/main/math
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { vec3, quat, mul, add } from 'onejs/math';
|
|
17
|
+
|
|
18
|
+
// Create a position vector
|
|
19
|
+
const position = vec3(1, 2, 3);
|
|
20
|
+
|
|
21
|
+
// Create a rotation
|
|
22
|
+
const rotation = quat(0, 0, 0, 1);
|
|
23
|
+
|
|
24
|
+
// Apply rotation to direction vector
|
|
25
|
+
const direction = vec3(0, 0, 1);
|
|
26
|
+
const rotatedDirection = mul(rotation, direction);
|
|
27
|
+
|
|
28
|
+
// Move in the rotated direction
|
|
29
|
+
const newPosition = add(position, rotatedDirection);
|
|
30
|
+
|
|
31
|
+
console.log(newPosition); // [1, 2, 4]
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Color Utils
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
import { namedColor, parseColor, palettes } from "onejs-core/utils"
|
|
38
|
+
import { useEffect, useRef } from "preact/hooks"
|
|
39
|
+
import { h, render } from "preact"
|
|
40
|
+
import { forwardRef } from "preact/compat"
|
|
41
|
+
import { GameObject, PrimitiveType, MeshRenderer, Vector3, Physics, Random, Rigidbody, CollisionDetectionMode, PhysicsMaterial, SphereCollider, Mathf, Camera, Collider } from "UnityEngine"
|
|
42
|
+
import { RuntimePanelUtils } from "UnityEngine/UIElements"
|
|
43
|
+
|
|
44
|
+
let plane = GameObject.CreatePrimitive(PrimitiveType.Plane)
|
|
45
|
+
plane.transform.position = new Vector3(0, -10, 0)
|
|
46
|
+
plane.GetComp(MeshRenderer).material.color = namedColor("maroon")
|
|
47
|
+
plane.transform.localScale = new Vector3(15, 1, 15)
|
|
48
|
+
|
|
49
|
+
let pm = new PhysicsMaterial()
|
|
50
|
+
pm.bounciness = 0.6
|
|
51
|
+
plane.GetComp(Collider).material = pm
|
|
52
|
+
|
|
53
|
+
var cam = GameObject.Find("Main Camera")
|
|
54
|
+
cam.transform.position = new Vector3(0, 6, -10)
|
|
55
|
+
cam.transform.LookAt(new Vector3(0, -15, 0))
|
|
56
|
+
|
|
57
|
+
Physics.gravity = new Vector3(0, -30, 0)
|
|
58
|
+
|
|
59
|
+
let balls: GameObject[] = []
|
|
60
|
+
|
|
61
|
+
function createRandomBall() {
|
|
62
|
+
let ball = GameObject.CreatePrimitive(PrimitiveType.Sphere)
|
|
63
|
+
ball.GetComp(MeshRenderer).material.color = parseColor(palettes[Mathf.RoundToInt(Random.Range(0, 99))][2])
|
|
64
|
+
ball.transform.position = Vector3.op_Multiply(Random.insideUnitSphere, 2)
|
|
65
|
+
let rb = ball.AddComp(Rigidbody)
|
|
66
|
+
rb.collisionDetectionMode = CollisionDetectionMode.Continuous
|
|
67
|
+
rb.drag = 0.3
|
|
68
|
+
ball.GetComp(SphereCollider).material = pm
|
|
69
|
+
balls.push(ball)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
for (let i = 0; i < 10; i++) {
|
|
73
|
+
createRandomBall()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const NamePlate = forwardRef(({ index }: { index: number }, ref) => {
|
|
77
|
+
return <div ref={ref} class="absolute hidden text-teal-700 text-xl">{`Ball ${index}`}</div>
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
const App = () => {
|
|
81
|
+
const refs = Array.from({ length: balls.length }, () => useRef<Element>())
|
|
82
|
+
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
var interval = setInterval(update)
|
|
85
|
+
return () => clearInterval(interval)
|
|
86
|
+
}, [])
|
|
87
|
+
|
|
88
|
+
function update() {
|
|
89
|
+
for (let i = 0; i < balls.length; i++) {
|
|
90
|
+
const ball = balls[i]
|
|
91
|
+
var pos = RuntimePanelUtils.CameraTransformWorldToPanel(document.body!.ve.panel, ball.transform.position, Camera.main);
|
|
92
|
+
refs[i].current!.style.translate = pos
|
|
93
|
+
refs[i].current!.style.display = "flex"
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return <div class="w-full h-full">
|
|
98
|
+
{balls.map((ball, i) => <NamePlate ref={refs[i]} index={i} />)}
|
|
99
|
+
</div>
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
render(<App />, document.body)
|
|
103
|
+
```
|
package/bin/oj.js
ADDED
|
@@ -242,8 +242,8 @@ declare namespace CS {
|
|
|
242
242
|
public get _children(): any;
|
|
243
243
|
public set _children(value: any);
|
|
244
244
|
public get _listeners(): System.Collections.Generic.Dictionary$2<string, UnityEngine.UIElements.EventCallback$1<UnityEngine.UIElements.EventBase>>;
|
|
245
|
-
public get
|
|
246
|
-
public set
|
|
245
|
+
public get className(): string;
|
|
246
|
+
public set className(value: string);
|
|
247
247
|
public SetBackgroundColor ($color: UnityEngine.Color) : void
|
|
248
248
|
public clearChildren () : void
|
|
249
249
|
public _addToListeners ($name: string, $callback: UnityEngine.UIElements.EventCallback$1<UnityEngine.UIElements.EventBase>) : void
|
package/dist/dom/dom.d.ts
CHANGED
|
@@ -18,14 +18,16 @@ export declare class DomWrapper {
|
|
|
18
18
|
get checked(): boolean;
|
|
19
19
|
get data(): any;
|
|
20
20
|
set data(value: any);
|
|
21
|
-
get
|
|
22
|
-
set
|
|
21
|
+
get className(): string;
|
|
22
|
+
set className(value: string);
|
|
23
|
+
get classList(): DomTokenList;
|
|
23
24
|
/**
|
|
24
25
|
* Not using private fields because of issues with the `#private;` line
|
|
25
26
|
* generated by tsc
|
|
26
27
|
*/
|
|
27
28
|
dom: CS.OneJS.Dom.Dom;
|
|
28
29
|
domStyleWrapper: DomStyleWrapper;
|
|
30
|
+
domTokenList: DomTokenList;
|
|
29
31
|
cachedChildNodes: DomWrapper[] | null;
|
|
30
32
|
boundListeners: WeakMap<WeakKey, any>;
|
|
31
33
|
constructor(dom: CS.OneJS.Dom.Dom);
|
|
@@ -36,7 +38,9 @@ export declare class DomWrapper {
|
|
|
36
38
|
contains(child: DomWrapper): boolean;
|
|
37
39
|
clearChildren(): void;
|
|
38
40
|
focus(): void;
|
|
39
|
-
addEventListener(type: string, listener: (event: EventBase) => void,
|
|
41
|
+
addEventListener(type: string, listener: (event: EventBase) => void, options?: boolean | {
|
|
42
|
+
once?: boolean;
|
|
43
|
+
}): void;
|
|
40
44
|
removeEventListener(type: string, listener: (event: EventBase) => void, useCapture?: boolean): void;
|
|
41
45
|
setAttribute(name: string, value: any): void;
|
|
42
46
|
removeAttribute(name: string): void;
|
|
@@ -57,3 +61,19 @@ export declare class DomWrapper {
|
|
|
57
61
|
}
|
|
58
62
|
export declare function querySelectorAll(root: DomWrapper, selector: string): DomWrapper[];
|
|
59
63
|
export declare function querySelector(root: DomWrapper, selector: string): DomWrapper | null;
|
|
64
|
+
declare class DomTokenList {
|
|
65
|
+
dom: CS.OneJS.Dom.Dom;
|
|
66
|
+
constructor(dom: CS.OneJS.Dom.Dom);
|
|
67
|
+
_tokens(): string[];
|
|
68
|
+
_update(tokens: string[]): void;
|
|
69
|
+
add(...tokens: string[]): void;
|
|
70
|
+
remove(...tokens: string[]): void;
|
|
71
|
+
toggle(token: string, force?: boolean): boolean;
|
|
72
|
+
contains(token: string): boolean;
|
|
73
|
+
replace(oldToken: string, newToken: string): boolean;
|
|
74
|
+
toString(): string;
|
|
75
|
+
get length(): number;
|
|
76
|
+
item(index: number): string | null;
|
|
77
|
+
[Symbol.iterator](): Iterator<string>;
|
|
78
|
+
}
|
|
79
|
+
export {};
|
package/dist/dom/dom.js
CHANGED
|
@@ -31,19 +31,22 @@ export class DomWrapper {
|
|
|
31
31
|
get checked() { return this.dom.checked; }
|
|
32
32
|
get data() { return this.dom.data; }
|
|
33
33
|
set data(value) { this.dom.data = value; }
|
|
34
|
-
get
|
|
35
|
-
set
|
|
34
|
+
get className() { return this.dom.className; }
|
|
35
|
+
set className(value) { this.dom.className = value; }
|
|
36
|
+
get classList() { return this.domTokenList; }
|
|
36
37
|
/**
|
|
37
38
|
* Not using private fields because of issues with the `#private;` line
|
|
38
39
|
* generated by tsc
|
|
39
40
|
*/
|
|
40
41
|
dom;
|
|
41
42
|
domStyleWrapper;
|
|
43
|
+
domTokenList;
|
|
42
44
|
cachedChildNodes = null;
|
|
43
45
|
boundListeners = new WeakMap();
|
|
44
46
|
constructor(dom) {
|
|
45
47
|
this.dom = dom;
|
|
46
48
|
this.domStyleWrapper = new DomStyleWrapper(dom.style);
|
|
49
|
+
this.domTokenList = new DomTokenList(dom);
|
|
47
50
|
}
|
|
48
51
|
appendChild(child) {
|
|
49
52
|
if (!child)
|
|
@@ -77,13 +80,22 @@ export class DomWrapper {
|
|
|
77
80
|
focus() {
|
|
78
81
|
this.dom.focus();
|
|
79
82
|
}
|
|
80
|
-
addEventListener(type, listener,
|
|
83
|
+
addEventListener(type, listener, options) {
|
|
81
84
|
let boundListener = this.boundListeners.get(listener);
|
|
82
85
|
if (!boundListener) {
|
|
83
86
|
boundListener = listener.bind(this);
|
|
84
87
|
this.boundListeners.set(listener, boundListener);
|
|
85
88
|
}
|
|
86
|
-
|
|
89
|
+
if (typeof options === 'object' && options.once) {
|
|
90
|
+
const onceWrapper = (event) => {
|
|
91
|
+
boundListener(event);
|
|
92
|
+
this.dom.removeEventListener(type, onceWrapper, false);
|
|
93
|
+
};
|
|
94
|
+
this.dom.addEventListener(type, onceWrapper, false);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
this.dom.addEventListener(type, boundListener, options ? true : false);
|
|
98
|
+
}
|
|
87
99
|
}
|
|
88
100
|
removeEventListener(type, listener, useCapture) {
|
|
89
101
|
const boundListener = this.boundListeners.get(listener);
|
|
@@ -175,7 +187,7 @@ function elementMatchesSelector(element, selectorInfo) {
|
|
|
175
187
|
}
|
|
176
188
|
// Check classes
|
|
177
189
|
if (selectorInfo.classes.length > 0) {
|
|
178
|
-
const elementClasses = element.
|
|
190
|
+
const elementClasses = element.className.split(' ').filter(c => c);
|
|
179
191
|
for (const className of selectorInfo.classes) {
|
|
180
192
|
if (!elementClasses.includes(className)) {
|
|
181
193
|
return false;
|
|
@@ -218,3 +230,60 @@ export function querySelector(root, selector) {
|
|
|
218
230
|
}
|
|
219
231
|
return traverse(root);
|
|
220
232
|
}
|
|
233
|
+
class DomTokenList {
|
|
234
|
+
dom;
|
|
235
|
+
constructor(dom) {
|
|
236
|
+
this.dom = dom;
|
|
237
|
+
}
|
|
238
|
+
_tokens() {
|
|
239
|
+
return this.dom.className.trim().split(/\s+/).filter(Boolean);
|
|
240
|
+
}
|
|
241
|
+
_update(tokens) {
|
|
242
|
+
this.dom.className = tokens.join(' ');
|
|
243
|
+
}
|
|
244
|
+
add(...tokens) {
|
|
245
|
+
const set = new Set(this._tokens());
|
|
246
|
+
tokens.forEach(t => t && set.add(t));
|
|
247
|
+
this._update(Array.from(set));
|
|
248
|
+
}
|
|
249
|
+
remove(...tokens) {
|
|
250
|
+
const set = new Set(this._tokens());
|
|
251
|
+
tokens.forEach(t => set.delete(t));
|
|
252
|
+
this._update(Array.from(set));
|
|
253
|
+
}
|
|
254
|
+
toggle(token, force) {
|
|
255
|
+
if (!token)
|
|
256
|
+
return false;
|
|
257
|
+
const has = this.contains(token);
|
|
258
|
+
if (force === true || (!has && force !== false)) {
|
|
259
|
+
this.add(token);
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
262
|
+
if (has && (force === false || force === undefined)) {
|
|
263
|
+
this.remove(token);
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
return has;
|
|
267
|
+
}
|
|
268
|
+
contains(token) {
|
|
269
|
+
return this._tokens().includes(token);
|
|
270
|
+
}
|
|
271
|
+
replace(oldToken, newToken) {
|
|
272
|
+
if (!this.contains(oldToken))
|
|
273
|
+
return false;
|
|
274
|
+
const tokens = this._tokens().map(t => (t === oldToken ? newToken : t));
|
|
275
|
+
this._update(tokens);
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
278
|
+
toString() {
|
|
279
|
+
return this.dom.className;
|
|
280
|
+
}
|
|
281
|
+
get length() { return this._tokens().length; }
|
|
282
|
+
item(index) {
|
|
283
|
+
const t = this._tokens();
|
|
284
|
+
return index >= 0 && index < t.length ? t[index] : null;
|
|
285
|
+
}
|
|
286
|
+
[Symbol.iterator]() {
|
|
287
|
+
return this._tokens()[Symbol.iterator]();
|
|
288
|
+
}
|
|
289
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -14,9 +14,6 @@ declare global {
|
|
|
14
14
|
interface Document extends DocumentWrapper {
|
|
15
15
|
}
|
|
16
16
|
interface Element extends DomWrapper {
|
|
17
|
-
classname: string;
|
|
18
|
-
nodeType: number;
|
|
19
|
-
ve: CS.UnityEngine.UIElements.VisualElement;
|
|
20
17
|
}
|
|
21
18
|
const newCsArray: <T>(type: {
|
|
22
19
|
new (...args: any[]): T;
|
package/dom/dom.ts
CHANGED
|
@@ -34,8 +34,9 @@ export class DomWrapper {
|
|
|
34
34
|
public get data(): any { return this.dom.data }
|
|
35
35
|
public set data(value: any) { this.dom.data = value }
|
|
36
36
|
|
|
37
|
-
public get
|
|
38
|
-
public set
|
|
37
|
+
public get className(): string { return this.dom.className }
|
|
38
|
+
public set className(value: string) { this.dom.className = value }
|
|
39
|
+
public get classList(): DomTokenList { return this.domTokenList }
|
|
39
40
|
|
|
40
41
|
/**
|
|
41
42
|
* Not using private fields because of issues with the `#private;` line
|
|
@@ -43,6 +44,7 @@ export class DomWrapper {
|
|
|
43
44
|
*/
|
|
44
45
|
dom: CS.OneJS.Dom.Dom
|
|
45
46
|
domStyleWrapper: DomStyleWrapper
|
|
47
|
+
domTokenList: DomTokenList
|
|
46
48
|
|
|
47
49
|
cachedChildNodes: DomWrapper[] | null = null
|
|
48
50
|
boundListeners = new WeakMap();
|
|
@@ -50,6 +52,7 @@ export class DomWrapper {
|
|
|
50
52
|
constructor(dom: CS.OneJS.Dom.Dom) {
|
|
51
53
|
this.dom = dom
|
|
52
54
|
this.domStyleWrapper = new DomStyleWrapper(dom.style)
|
|
55
|
+
this.domTokenList = new DomTokenList(dom)
|
|
53
56
|
}
|
|
54
57
|
|
|
55
58
|
appendChild(child: DomWrapper) {
|
|
@@ -88,13 +91,22 @@ export class DomWrapper {
|
|
|
88
91
|
this.dom.focus()
|
|
89
92
|
}
|
|
90
93
|
|
|
91
|
-
addEventListener(type: string, listener: (event: EventBase) => void,
|
|
94
|
+
addEventListener(type: string, listener: (event: EventBase) => void, options?: boolean | { once?: boolean }) {
|
|
92
95
|
let boundListener = this.boundListeners.get(listener);
|
|
93
96
|
if (!boundListener) {
|
|
94
97
|
boundListener = listener.bind(this);
|
|
95
98
|
this.boundListeners.set(listener, boundListener);
|
|
96
99
|
}
|
|
97
|
-
|
|
100
|
+
|
|
101
|
+
if (typeof options === 'object' && options.once) {
|
|
102
|
+
const onceWrapper = (event: EventBase) => {
|
|
103
|
+
boundListener(event);
|
|
104
|
+
this.dom.removeEventListener(type, onceWrapper, false);
|
|
105
|
+
};
|
|
106
|
+
this.dom.addEventListener(type, onceWrapper, false);
|
|
107
|
+
} else {
|
|
108
|
+
this.dom.addEventListener(type, boundListener, options ? true : false);
|
|
109
|
+
}
|
|
98
110
|
}
|
|
99
111
|
|
|
100
112
|
removeEventListener(type: string, listener: (event: EventBase) => void, useCapture?: boolean) {
|
|
@@ -212,7 +224,7 @@ function elementMatchesSelector(element: DomWrapper, selectorInfo: SelectorInfo)
|
|
|
212
224
|
|
|
213
225
|
// Check classes
|
|
214
226
|
if (selectorInfo.classes.length > 0) {
|
|
215
|
-
const elementClasses = element.
|
|
227
|
+
const elementClasses = element.className.split(' ').filter(c => c);
|
|
216
228
|
for (const className of selectorInfo.classes) {
|
|
217
229
|
if (!elementClasses.includes(className)) {
|
|
218
230
|
return false;
|
|
@@ -264,4 +276,71 @@ export function querySelector(root: DomWrapper, selector: string): DomWrapper |
|
|
|
264
276
|
}
|
|
265
277
|
|
|
266
278
|
return traverse(root);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
class DomTokenList {
|
|
282
|
+
dom: CS.OneJS.Dom.Dom
|
|
283
|
+
|
|
284
|
+
constructor(dom: CS.OneJS.Dom.Dom) {
|
|
285
|
+
this.dom = dom
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
_tokens(): string[] {
|
|
289
|
+
return this.dom.className.trim().split(/\s+/).filter(Boolean)
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
_update(tokens: string[]) {
|
|
293
|
+
this.dom.className = tokens.join(' ')
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
add(...tokens: string[]) {
|
|
297
|
+
const set = new Set(this._tokens())
|
|
298
|
+
tokens.forEach(t => t && set.add(t))
|
|
299
|
+
this._update(Array.from(set))
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
remove(...tokens: string[]) {
|
|
303
|
+
const set = new Set(this._tokens())
|
|
304
|
+
tokens.forEach(t => set.delete(t))
|
|
305
|
+
this._update(Array.from(set))
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
toggle(token: string, force?: boolean): boolean {
|
|
309
|
+
if (!token) return false
|
|
310
|
+
const has = this.contains(token)
|
|
311
|
+
if (force === true || (!has && force !== false)) {
|
|
312
|
+
this.add(token)
|
|
313
|
+
return true
|
|
314
|
+
}
|
|
315
|
+
if (has && (force === false || force === undefined)) {
|
|
316
|
+
this.remove(token)
|
|
317
|
+
return false
|
|
318
|
+
}
|
|
319
|
+
return has
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
contains(token: string): boolean {
|
|
323
|
+
return this._tokens().includes(token)
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
replace(oldToken: string, newToken: string): boolean {
|
|
327
|
+
if (!this.contains(oldToken)) return false
|
|
328
|
+
const tokens = this._tokens().map(t => (t === oldToken ? newToken : t))
|
|
329
|
+
this._update(tokens)
|
|
330
|
+
return true
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
toString(): string {
|
|
334
|
+
return this.dom.className
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
get length(): number { return this._tokens().length }
|
|
338
|
+
item(index: number): string | null {
|
|
339
|
+
const t = this._tokens()
|
|
340
|
+
return index >= 0 && index < t.length ? t[index] : null
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
[Symbol.iterator](): Iterator<string> {
|
|
344
|
+
return this._tokens()[Symbol.iterator]()
|
|
345
|
+
}
|
|
267
346
|
}
|
package/index.ts
CHANGED
|
@@ -40,9 +40,7 @@ export { emo } from "./styling/index"
|
|
|
40
40
|
declare global {
|
|
41
41
|
interface Document extends DocumentWrapper { }
|
|
42
42
|
interface Element extends DomWrapper {
|
|
43
|
-
|
|
44
|
-
nodeType: number
|
|
45
|
-
ve: CS.UnityEngine.UIElements.VisualElement
|
|
43
|
+
|
|
46
44
|
}
|
|
47
45
|
const newCsArray: <T>(type: { new(...args: any[]): T }, count: number) => CS.System.Array
|
|
48
46
|
const toJsArray: <T>(csArr: CS.System.Array) => T[]
|
package/math/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Convenience functions for working with vectors, quaternions, matrices, etc.
|
|
|
5
5
|
## Usage Example
|
|
6
6
|
|
|
7
7
|
```typescript
|
|
8
|
-
import { vec3, quat, mul, add } from 'onejs/math';
|
|
8
|
+
import { vec3, quat, mul, add } from 'onejs-core/math';
|
|
9
9
|
|
|
10
10
|
// Create a position vector
|
|
11
11
|
const position = vec3(1, 2, 3);
|
|
@@ -209,4 +209,4 @@ lerp(a: Vector3, b: Vector3, t: number): Vector3
|
|
|
209
209
|
lerp(a: Vector4, b: Vector4, t: number): Vector4
|
|
210
210
|
lerp(a: Quaternion, b: Quaternion, t: number): Quaternion
|
|
211
211
|
lerp(a: Color, b: Color, t: number): Color
|
|
212
|
-
```
|
|
212
|
+
```
|
package/package.json
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "onejs-core",
|
|
3
|
-
"description": "The JS part of OneJS, a UI framework and Scripting Engine for Unity.",
|
|
4
|
-
"version": "
|
|
5
|
-
"main": "./dist/index.js",
|
|
6
|
-
"types": "./typings.d.ts",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "onejs-core",
|
|
3
|
+
"description": "The JS part of OneJS, a UI framework and Scripting Engine for Unity.",
|
|
4
|
+
"version": "2.0.2",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./typings.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"oj": "./bin/oj.js"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"css-flatten": "^2.0.0",
|
|
12
|
+
"css-simple-parser": "^3.0.0",
|
|
13
|
+
"progress": "^2.0.3"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"esbuild": "^0.20.0",
|
|
17
|
+
"fs-extra": "^11.2.0",
|
|
18
|
+
"postcss": "^8.4.38",
|
|
19
|
+
"postcss-cli": "^11.0.0",
|
|
20
|
+
"rimraf": "^5.0.7",
|
|
21
|
+
"tailwindcss": "^3.4.17",
|
|
22
|
+
"tar": "^7.2.0",
|
|
23
|
+
"tiny-glob": "^0.2.9",
|
|
24
|
+
"xml2js": "^0.6.2"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const fs = require("fs")
|
|
2
|
+
const path = require("path")
|
|
3
|
+
const postcssImport = require("postcss-import")
|
|
4
|
+
|
|
5
|
+
module.exports = function optionalImportPlugin() {
|
|
6
|
+
const optionalImportMap = new Map()
|
|
7
|
+
|
|
8
|
+
return postcssImport({
|
|
9
|
+
resolve(id, basedir) {
|
|
10
|
+
const fullPath = path.resolve(basedir, id)
|
|
11
|
+
if (!fs.existsSync(fullPath)) {
|
|
12
|
+
const fakePath = path.resolve(".optional-imports", id.replace(/[\\/]/g, "_") + ".css")
|
|
13
|
+
optionalImportMap.set(fakePath, "")
|
|
14
|
+
console.warn(`[postcss-import] Skipping: ${id}`)
|
|
15
|
+
return fakePath
|
|
16
|
+
}
|
|
17
|
+
return fullPath
|
|
18
|
+
},
|
|
19
|
+
load(filename) {
|
|
20
|
+
if (optionalImportMap.has(filename)) {
|
|
21
|
+
return "/* optional import skipped */"
|
|
22
|
+
}
|
|
23
|
+
return fs.readFileSync(filename, "utf8")
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module.exports = () => {
|
|
2
|
+
return {
|
|
3
|
+
postcssPlugin: 'postcss-logging-plugin',
|
|
4
|
+
Once(root, { result }) {
|
|
5
|
+
process.stdout.write('\x1Bc')
|
|
6
|
+
console.log('[tailwindcss] compiler started...')
|
|
7
|
+
},
|
|
8
|
+
OnceExit(root, { result }) {
|
|
9
|
+
console.log('[tailwindcss] watching...')
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
package/scripts/switch.cjs
CHANGED
|
@@ -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.1
|
|
17
|
-
{ name: "V8", tgzUrl: "https://github.com/Tencent/puerts/releases/download/Unity_v2.1
|
|
18
|
-
{ name: "NodeJS", tgzUrl: "https://github.com/Tencent/puerts/releases/download/Unity_v2.1
|
|
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" }
|
|
19
19
|
]
|
|
20
20
|
|
|
21
21
|
const args = process.argv.slice(2)
|
|
@@ -30,16 +30,26 @@ if (args.length > 0 && args[0].toLowerCase() == "clear") {
|
|
|
30
30
|
console.log(`Deleted ${downloadedPath}`)
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
} else if (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
} else if (
|
|
34
|
+
args.length > 0 &&
|
|
35
|
+
(["quickjs", "v8", "nodejs"].includes(args[0].toLowerCase()) ||
|
|
36
|
+
(args[0].toLowerCase().endsWith('.tgz') || /^https?:\/\/.+\.tgz$/i.test(args[0])))
|
|
37
|
+
) {
|
|
38
|
+
let backend;
|
|
39
|
+
const outputDir = "./tmp";
|
|
40
|
+
if (["quickjs", "v8", "nodejs"].includes(args[0].toLowerCase())) {
|
|
41
|
+
backend = backends.find(b => b.name.toLowerCase() === args[0]);
|
|
42
|
+
} else {
|
|
43
|
+
backend = { name: "Custom", tgzUrl: args[0] };
|
|
44
|
+
}
|
|
45
|
+
Process(backend, outputDir);
|
|
37
46
|
} else {
|
|
38
|
-
console.log("Usage: npm run switch <quickjs|v8|nodejs|clear>\n")
|
|
47
|
+
console.log("Usage: npm run switch <quickjs|v8|nodejs|clear|tgz-url>\n")
|
|
39
48
|
console.log(" quickjs: Switch to QuickJS backend")
|
|
40
49
|
console.log(" v8: Switch to V8 backend")
|
|
41
50
|
console.log(" nodejs: Switch to NodeJS backend")
|
|
42
|
-
console.log(" clear: Clear all downloaded .tgz files
|
|
51
|
+
console.log(" clear: Clear all downloaded .tgz files")
|
|
52
|
+
console.log(" <tgz-url>: Switch using a custom .tgz package URL\n")
|
|
43
53
|
}
|
|
44
54
|
|
|
45
55
|
async function Process(backend, outputDir) {
|
|
@@ -266,4 +276,4 @@ async function deleteDirectorySafely(dirPath) {
|
|
|
266
276
|
return true
|
|
267
277
|
}
|
|
268
278
|
return false
|
|
269
|
-
}
|
|
279
|
+
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# name: Publish
|
|
2
|
-
# on:
|
|
3
|
-
# push:
|
|
4
|
-
# branches:
|
|
5
|
-
# - main
|
|
6
|
-
|
|
7
|
-
# jobs:
|
|
8
|
-
# publish:
|
|
9
|
-
# runs-on: ubuntu-latest
|
|
10
|
-
|
|
11
|
-
# permissions:
|
|
12
|
-
# contents: read
|
|
13
|
-
# id-token: write
|
|
14
|
-
|
|
15
|
-
# steps:
|
|
16
|
-
# - uses: actions/checkout@v4
|
|
17
|
-
|
|
18
|
-
# - name: Publish package
|
|
19
|
-
# run: npx jsr publish
|
|
File without changes
|
|
File without changes
|
|
File without changes
|