onejs-core 3.0.3 → 3.0.5

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.
Files changed (103) hide show
  1. package/.gitattributes +2 -2
  2. package/.prettierrc +5 -5
  3. package/.vscode/settings.json +5 -5
  4. package/LICENSE +20 -20
  5. package/README.md +102 -102
  6. package/bin/oj.js +252 -252
  7. package/definitions/Assemblies/OneJS.Runtime.Ext.d.ts +6 -6
  8. package/definitions/Assemblies/OneJS.Runtime.d.ts +826 -826
  9. package/definitions/Assemblies/OneJS.Samples.d.ts +20 -20
  10. package/definitions/Assemblies/Unity.Mathematics.d.ts +9221 -9221
  11. package/definitions/Assemblies/UnityEditor.CoreModule.d.ts +32614 -32614
  12. package/definitions/Assemblies/UnityEngine.AIModule.d.ts +998 -998
  13. package/definitions/Assemblies/UnityEngine.AnimationModule.d.ts +3308 -3308
  14. package/definitions/Assemblies/UnityEngine.AssetBundleModule.d.ts +337 -337
  15. package/definitions/Assemblies/UnityEngine.AudioModule.d.ts +1154 -1154
  16. package/definitions/Assemblies/UnityEngine.CoreModule.d.ts +29587 -29587
  17. package/definitions/Assemblies/UnityEngine.PhysicsModule.d.ts +3137 -3137
  18. package/definitions/Assemblies/UnityEngine.TerrainModule.d.ts +1270 -1270
  19. package/definitions/Assemblies/UnityEngine.UIElementsModule.d.ts +32718 -32718
  20. package/definitions/Assemblies/UnityEngine.UnityAnalyticsCommonModule.d.ts +274 -274
  21. package/definitions/Assemblies/index.d.ts +16 -16
  22. package/definitions/Assemblies/mscorlib.d.ts +19416 -19416
  23. package/definitions/augments.d.ts +66 -66
  24. package/definitions/globals.d.ts +53 -53
  25. package/definitions/index.d.ts +11 -11
  26. package/definitions/jsx.d.ts +570 -570
  27. package/definitions/modules.d.ts +32 -32
  28. package/definitions/onejs.d.ts +171 -171
  29. package/definitions/preact.jsx.d.ts +6 -6
  30. package/definitions/proto-overrides.d.ts +41 -41
  31. package/definitions/puerts.d.ts +30 -30
  32. package/definitions/unity-engine.d.ts +22 -22
  33. package/dist/dom/document.d.ts +30 -0
  34. package/dist/dom/document.js +89 -0
  35. package/dist/dom/dom-style.d.ts +9 -0
  36. package/dist/dom/dom-style.js +27 -0
  37. package/dist/dom/dom.d.ts +83 -0
  38. package/dist/dom/dom.js +313 -0
  39. package/dist/dom/index.d.ts +4 -0
  40. package/dist/dom/index.js +4 -0
  41. package/dist/index.d.ts +25 -0
  42. package/dist/index.js +45 -0
  43. package/dist/math/index.d.ts +86 -0
  44. package/dist/math/index.js +361 -0
  45. package/dist/preloads/inject.d.ts +3 -0
  46. package/dist/preloads/inject.js +36 -0
  47. package/dist/styling/index.d.ts +10 -0
  48. package/dist/styling/index.js +28 -0
  49. package/dist/styling/utils/generateAlphabeticName.d.ts +1 -0
  50. package/dist/styling/utils/generateAlphabeticName.js +16 -0
  51. package/dist/styling/utils/generateComponentId.d.ts +1 -0
  52. package/dist/styling/utils/generateComponentId.js +5 -0
  53. package/dist/styling/utils/hash.d.ts +5 -0
  54. package/dist/styling/utils/hash.js +34 -0
  55. package/dist/utils/arrays.d.ts +1 -0
  56. package/dist/utils/arrays.js +10 -0
  57. package/dist/utils/color-palettes.d.ts +2 -0
  58. package/dist/utils/color-palettes.js +2 -0
  59. package/dist/utils/color-parser.d.ts +161 -0
  60. package/dist/utils/color-parser.js +241 -0
  61. package/dist/utils/float-parser.d.ts +7 -0
  62. package/dist/utils/float-parser.js +23 -0
  63. package/dist/utils/index.d.ts +12 -0
  64. package/dist/utils/index.js +15 -0
  65. package/dist/utils/subscribe.d.ts +4 -0
  66. package/dist/utils/subscribe.js +10 -0
  67. package/dist/utils/system.d.ts +1 -0
  68. package/dist/utils/system.js +16 -0
  69. package/dom/document.ts +115 -115
  70. package/dom/dom-style.ts +36 -36
  71. package/dom/dom.ts +376 -376
  72. package/dom/index.ts +3 -3
  73. package/index.ts +59 -59
  74. package/jsr.json +9 -9
  75. package/math/README.md +212 -212
  76. package/math/index.ts +487 -487
  77. package/package.json +34 -33
  78. package/preloads/inject.ts +43 -43
  79. package/scripts/esbuild/copy-assets.mjs +94 -94
  80. package/scripts/esbuild/decorator-fix.mjs +17 -17
  81. package/scripts/esbuild/import-transform.mjs +100 -100
  82. package/scripts/esbuild/index.mjs +3 -3
  83. package/scripts/esbuild/watch-output.mjs +38 -38
  84. package/scripts/postcss/cleanup-plugin.cjs +89 -89
  85. package/scripts/postcss/onejs-tw-config.cjs +252 -252
  86. package/scripts/postcss/optional-import-plugin.cjs +26 -26
  87. package/scripts/postcss/tailwind-logging-plugin.cjs +11 -11
  88. package/scripts/postcss/unwrap-is-plugin.cjs +16 -16
  89. package/scripts/postcss/uss-transform-plugin.cjs +92 -92
  90. package/scripts/switch.cjs +321 -290
  91. package/styling/index.tsx +32 -32
  92. package/styling/utils/generateAlphabeticName.ts +20 -20
  93. package/styling/utils/generateComponentId.ts +5 -5
  94. package/styling/utils/hash.ts +46 -46
  95. package/tsconfig.json +24 -24
  96. package/typings.d.ts +5 -5
  97. package/utils/arrays.ts +10 -10
  98. package/utils/color-palettes.ts +2 -2
  99. package/utils/color-parser.ts +248 -248
  100. package/utils/float-parser.ts +30 -30
  101. package/utils/index.ts +15 -15
  102. package/utils/subscribe.ts +16 -16
  103. package/utils/system.ts +16 -16
package/.gitattributes CHANGED
@@ -1,2 +1,2 @@
1
- # Auto detect text files and perform LF normalization
2
- * text=auto
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
package/.prettierrc CHANGED
@@ -1,5 +1,5 @@
1
- {
2
- "printWidth": 120,
3
- "semi": false,
4
- "tabWidth": 4
5
- }
1
+ {
2
+ "printWidth": 120,
3
+ "semi": false,
4
+ "tabWidth": 4
5
+ }
@@ -1,6 +1,6 @@
1
- {
2
- "search.exclude": {
3
- "**/dist": true,
4
- "**/node_modules": true,
5
- }
1
+ {
2
+ "search.exclude": {
3
+ "**/dist": true,
4
+ "**/node_modules": true,
5
+ }
6
6
  }
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2025-present Singtaa, DragonGround LLC
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025-present Singtaa, DragonGround LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
package/README.md CHANGED
@@ -1,103 +1,103 @@
1
- This is the Core JS Lib for OneJS V2. It contains the following:
2
-
3
- 1) Document and Dom wrappers
4
- 2) Type definitions for a good portion of built-in Unity assemblies
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)
1
+ This is the Core JS Lib for OneJS V2. It contains the following:
2
+
3
+ 1) Document and Dom wrappers
4
+ 2) Type definitions for a good portion of built-in Unity assemblies
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
103
  ```