onejs-core 3.0.3 → 3.0.4

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 (110) 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/definitions/Assemblies/OneJS.Runtime.Ext.d.ts +6 -6
  7. package/definitions/Assemblies/OneJS.Runtime.d.ts +826 -826
  8. package/definitions/Assemblies/OneJS.Samples.d.ts +20 -20
  9. package/definitions/Assemblies/Unity.Mathematics.d.ts +9221 -9221
  10. package/definitions/Assemblies/UnityEditor.CoreModule.d.ts +32614 -32614
  11. package/definitions/Assemblies/UnityEngine.AIModule.d.ts +998 -998
  12. package/definitions/Assemblies/UnityEngine.AnimationModule.d.ts +3308 -3308
  13. package/definitions/Assemblies/UnityEngine.AssetBundleModule.d.ts +337 -337
  14. package/definitions/Assemblies/UnityEngine.AudioModule.d.ts +1154 -1154
  15. package/definitions/Assemblies/UnityEngine.CoreModule.d.ts +29587 -29587
  16. package/definitions/Assemblies/UnityEngine.PhysicsModule.d.ts +3137 -3137
  17. package/definitions/Assemblies/UnityEngine.TerrainModule.d.ts +1270 -1270
  18. package/definitions/Assemblies/UnityEngine.UIElementsModule.d.ts +32718 -32718
  19. package/definitions/Assemblies/UnityEngine.UnityAnalyticsCommonModule.d.ts +274 -274
  20. package/definitions/Assemblies/index.d.ts +16 -16
  21. package/definitions/Assemblies/mscorlib.d.ts +19416 -19416
  22. package/definitions/augments.d.ts +66 -66
  23. package/definitions/globals.d.ts +53 -53
  24. package/definitions/index.d.ts +11 -11
  25. package/definitions/jsx.d.ts +570 -570
  26. package/definitions/modules.d.ts +32 -32
  27. package/definitions/onejs.d.ts +171 -171
  28. package/definitions/preact.jsx.d.ts +6 -6
  29. package/definitions/proto-overrides.d.ts +41 -41
  30. package/definitions/puerts.d.ts +30 -30
  31. package/definitions/unity-engine.d.ts +22 -22
  32. package/dist/csharp/index.d.ts +3 -0
  33. package/dist/csharp/index.js +3 -0
  34. package/dist/dom/document.d.ts +30 -0
  35. package/dist/dom/document.js +89 -0
  36. package/dist/dom/dom-style.d.ts +9 -0
  37. package/dist/dom/dom-style.js +27 -0
  38. package/dist/dom/dom.d.ts +83 -0
  39. package/dist/dom/dom.js +313 -0
  40. package/dist/dom/index.d.ts +4 -0
  41. package/dist/dom/index.js +4 -0
  42. package/dist/dom/selector.d.ts +0 -0
  43. package/dist/dom/selector.js +0 -0
  44. package/dist/index.d.ts +25 -0
  45. package/dist/index.js +45 -0
  46. package/dist/math/index.d.ts +86 -0
  47. package/dist/math/index.js +361 -0
  48. package/dist/preloads/inject.d.ts +3 -0
  49. package/dist/preloads/inject.js +36 -0
  50. package/dist/styling/index.d.ts +10 -0
  51. package/dist/styling/index.js +28 -0
  52. package/dist/styling/utils/generateAlphabeticName.d.ts +1 -0
  53. package/dist/styling/utils/generateAlphabeticName.js +16 -0
  54. package/dist/styling/utils/generateComponentId.d.ts +1 -0
  55. package/dist/styling/utils/generateComponentId.js +5 -0
  56. package/dist/styling/utils/hash.d.ts +5 -0
  57. package/dist/styling/utils/hash.js +34 -0
  58. package/dist/utils/arrays.d.ts +1 -0
  59. package/dist/utils/arrays.js +10 -0
  60. package/dist/utils/color-palettes.d.ts +2 -0
  61. package/dist/utils/color-palettes.js +2 -0
  62. package/dist/utils/color-parser.d.ts +161 -0
  63. package/dist/utils/color-parser.js +241 -0
  64. package/dist/utils/float-parser.d.ts +7 -0
  65. package/dist/utils/float-parser.js +23 -0
  66. package/dist/utils/index.d.ts +12 -0
  67. package/dist/utils/index.js +15 -0
  68. package/dist/utils/responsive.d.ts +4 -0
  69. package/dist/utils/responsive.js +23 -0
  70. package/dist/utils/subscribe.d.ts +4 -0
  71. package/dist/utils/subscribe.js +10 -0
  72. package/dist/utils/system.d.ts +1 -0
  73. package/dist/utils/system.js +16 -0
  74. package/dist/utils/toJsArray.d.ts +1 -0
  75. package/dist/utils/toJsArray.js +10 -0
  76. package/dom/document.ts +115 -115
  77. package/dom/dom-style.ts +36 -36
  78. package/dom/dom.ts +376 -376
  79. package/dom/index.ts +3 -3
  80. package/index.ts +59 -59
  81. package/jsr.json +9 -9
  82. package/math/README.md +212 -212
  83. package/math/index.ts +487 -487
  84. package/package.json +33 -33
  85. package/preloads/inject.ts +43 -43
  86. package/scripts/esbuild/copy-assets.mjs +94 -94
  87. package/scripts/esbuild/decorator-fix.mjs +17 -17
  88. package/scripts/esbuild/import-transform.mjs +100 -100
  89. package/scripts/esbuild/index.mjs +3 -3
  90. package/scripts/esbuild/watch-output.mjs +38 -38
  91. package/scripts/postcss/cleanup-plugin.cjs +89 -89
  92. package/scripts/postcss/onejs-tw-config.cjs +252 -252
  93. package/scripts/postcss/optional-import-plugin.cjs +26 -26
  94. package/scripts/postcss/tailwind-logging-plugin.cjs +11 -11
  95. package/scripts/postcss/unwrap-is-plugin.cjs +16 -16
  96. package/scripts/postcss/uss-transform-plugin.cjs +92 -92
  97. package/scripts/switch.cjs +290 -290
  98. package/styling/index.tsx +32 -32
  99. package/styling/utils/generateAlphabeticName.ts +20 -20
  100. package/styling/utils/generateComponentId.ts +5 -5
  101. package/styling/utils/hash.ts +46 -46
  102. package/tsconfig.json +24 -24
  103. package/typings.d.ts +5 -5
  104. package/utils/arrays.ts +10 -10
  105. package/utils/color-palettes.ts +2 -2
  106. package/utils/color-parser.ts +248 -248
  107. package/utils/float-parser.ts +30 -30
  108. package/utils/index.ts +15 -15
  109. package/utils/subscribe.ts +16 -16
  110. package/utils/system.ts +16 -16
@@ -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
+ }
@@ -0,0 +1,3 @@
1
+ /// <reference path="../../definitions/index.d.ts" />
2
+ export declare function btoa(text: string): string;
3
+ export declare function atob(base64: string): string;
@@ -0,0 +1,36 @@
1
+ /// <reference path="../definitions/index.d.ts" />
2
+ export function btoa(text) {
3
+ // return CS.OneJS.CommonGlobals.btoa(text);
4
+ const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
5
+ let str = text;
6
+ let output = '';
7
+ for (let i = 0; i < str.length; i += 3) {
8
+ let block = (str.charCodeAt(i) << 16) | ((i + 1 < str.length ? str.charCodeAt(i + 1) : 0) << 8) | (i + 2 < str.length ? str.charCodeAt(i + 2) : 0);
9
+ output += chars[(block >> 18) & 0x3F] +
10
+ chars[(block >> 12) & 0x3F] +
11
+ (i + 1 < str.length ? chars[(block >> 6) & 0x3F] : '=') +
12
+ (i + 2 < str.length ? chars[block & 0x3F] : '=');
13
+ }
14
+ return output;
15
+ }
16
+ // function uint8ArrayToString(uint8Array) {
17
+ // const chars: any = [];
18
+ // for (let i = 0; i < uint8Array.length; i++) {
19
+ // chars.push(String.fromCharCode(uint8Array[i]));
20
+ // }
21
+ // return chars.join('');
22
+ // }
23
+ export function atob(base64) {
24
+ // return CS.OneJS.CommonGlobals.atob(base64);
25
+ // return CS.System.Text.Encoding.UTF8.GetString(CS.System.Convert.FromBase64String(base64))
26
+ const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
27
+ let str = base64.replace(/=+$/, '');
28
+ let output = '';
29
+ if (str.length % 4 == 1) {
30
+ throw new Error('Invalid base64 string');
31
+ }
32
+ for (let bc = 0, bs = 0, buffer, idx = 0; buffer = str.charAt(idx++); ~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer, bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0) {
33
+ buffer = chars.indexOf(buffer);
34
+ }
35
+ return output;
36
+ }
@@ -0,0 +1,10 @@
1
+ /// <reference path="../../definitions/index.d.ts" />
2
+ export declare function hashAndAddRuntimeUSS(style: string): string;
3
+ /**
4
+ * Similar to the Emotion api, this function takes a template string and returns
5
+ * a class name that can be used to style an element.
6
+ * @param strings
7
+ * @param values
8
+ * @returns
9
+ */
10
+ export declare const emo: (strings: TemplateStringsArray, ...values: any[]) => string;
@@ -0,0 +1,28 @@
1
+ /// <reference path="../definitions/index.d.ts" />
2
+ import flatten from "css-flatten";
3
+ import generateComponentId from "./utils/generateComponentId";
4
+ const _pastCompIds = new Set();
5
+ export function hashAndAddRuntimeUSS(style) {
6
+ let compId = generateComponentId(style);
7
+ if (_pastCompIds.has(compId))
8
+ return compId;
9
+ style = `.${compId} {${style}}`;
10
+ style = flatten(style);
11
+ globalThis.___document.addRuntimeUSS(style);
12
+ _pastCompIds.add(compId);
13
+ return compId;
14
+ }
15
+ /**
16
+ * Similar to the Emotion api, this function takes a template string and returns
17
+ * a class name that can be used to style an element.
18
+ * @param strings
19
+ * @param values
20
+ * @returns
21
+ */
22
+ export const emo = function (strings, ...values) {
23
+ let style = values.reduce((result, expr, index) => {
24
+ const value = expr;
25
+ return result + (value ? value : "") + strings[index + 1];
26
+ }, strings[0]);
27
+ return hashAndAddRuntimeUSS(style);
28
+ };
@@ -0,0 +1 @@
1
+ export default function generateAlphabeticName(code: number): string;
@@ -0,0 +1,16 @@
1
+ const AD_REPLACER_R = /(a)(d)/gi;
2
+ /* This is the "capacity" of our alphabet i.e. 2x26 for all letters plus their capitalised
3
+ * counterparts */
4
+ const charsLength = 52;
5
+ /* start at 75 for 'a' until 'z' (25) and then start at 65 for capitalised letters */
6
+ const getAlphabeticChar = (code) => String.fromCharCode(code + (code > 25 ? 39 : 97));
7
+ /* input a number, usually a hash and convert it to base-52 */
8
+ export default function generateAlphabeticName(code) {
9
+ let name = '';
10
+ let x;
11
+ /* get a char and divide by alphabet-length */
12
+ for (x = Math.abs(code); x > charsLength; x = (x / charsLength) | 0) {
13
+ name = getAlphabeticChar(x % charsLength) + name;
14
+ }
15
+ return (getAlphabeticChar(x % charsLength) + name).replace(AD_REPLACER_R, '$1-$2');
16
+ }
@@ -0,0 +1 @@
1
+ export default function generateComponentId(str: string): string;
@@ -0,0 +1,5 @@
1
+ import generateAlphabeticName from './generateAlphabeticName';
2
+ import { hash } from './hash';
3
+ export default function generateComponentId(str) {
4
+ return generateAlphabeticName(hash(str) >>> 0);
5
+ }
@@ -0,0 +1,5 @@
1
+ export declare const SEED = 5381;
2
+ export declare const phash: (h: number, x: string) => number;
3
+ export declare const hash: (x: string) => number;
4
+ export declare function generateAlphabeticName(code: number): string;
5
+ export default function generateComponentId(str: string): string;
@@ -0,0 +1,34 @@
1
+ export const SEED = 5381;
2
+ // When we have separate strings it's useful to run a progressive
3
+ // version of djb2 where we pretend that we're still looping over
4
+ // the same string
5
+ export const phash = (h, x) => {
6
+ let i = x.length;
7
+ while (i) {
8
+ h = (h * 33) ^ x.charCodeAt(--i);
9
+ }
10
+ return h;
11
+ };
12
+ // This is a djb2 hashing function
13
+ export const hash = (x) => {
14
+ return phash(SEED, x);
15
+ };
16
+ const AD_REPLACER_R = /(a)(d)/gi;
17
+ /* This is the "capacity" of our alphabet i.e. 2x26 for all letters plus their capitalised
18
+ * counterparts */
19
+ const charsLength = 52;
20
+ /* start at 75 for 'a' until 'z' (25) and then start at 65 for capitalised letters */
21
+ const getAlphabeticChar = (code) => String.fromCharCode(code + (code > 25 ? 39 : 97));
22
+ /* input a number, usually a hash and convert it to base-52 */
23
+ export function generateAlphabeticName(code) {
24
+ let name = '';
25
+ let x;
26
+ /* get a char and divide by alphabet-length */
27
+ for (x = Math.abs(code); x > charsLength; x = (x / charsLength) | 0) {
28
+ name = getAlphabeticChar(x % charsLength) + name;
29
+ }
30
+ return (getAlphabeticChar(x % charsLength) + name).replace(AD_REPLACER_R, '$1-$2');
31
+ }
32
+ export default function generateComponentId(str) {
33
+ return generateAlphabeticName(hash(str) >>> 0);
34
+ }
@@ -0,0 +1 @@
1
+ export declare function toJsArray<T>(csArr: any): T[];
@@ -0,0 +1,10 @@
1
+ export function toJsArray(csArr) {
2
+ if (!csArr)
3
+ return [];
4
+ let arr = new Array(csArr.Length);
5
+ var i = csArr.Length;
6
+ while (i--) {
7
+ arr[i] = csArr.get_Item(i);
8
+ }
9
+ return arr;
10
+ }
@@ -0,0 +1,2 @@
1
+ declare let palettes: string[][];
2
+ export { palettes };
@@ -0,0 +1,2 @@
1
+ let palettes = [["#69d2e7", "#a7dbd8", "#e0e4cc", "#f38630", "#fa6900"], ["#fe4365", "#fc9d9a", "#f9cdad", "#c8c8a9", "#83af9b"], ["#ecd078", "#d95b43", "#c02942", "#542437", "#53777a"], ["#556270", "#4ecdc4", "#c7f464", "#ff6b6b", "#c44d58"], ["#774f38", "#e08e79", "#f1d4af", "#ece5ce", "#c5e0dc"], ["#e8ddcb", "#cdb380", "#036564", "#033649", "#031634"], ["#490a3d", "#bd1550", "#e97f02", "#f8ca00", "#8a9b0f"], ["#594f4f", "#547980", "#45ada8", "#9de0ad", "#e5fcc2"], ["#00a0b0", "#6a4a3c", "#cc333f", "#eb6841", "#edc951"], ["#e94e77", "#d68189", "#c6a49a", "#c6e5d9", "#f4ead5"], ["#3fb8af", "#7fc7af", "#dad8a7", "#ff9e9d", "#ff3d7f"], ["#d9ceb2", "#948c75", "#d5ded9", "#7a6a53", "#99b2b7"], ["#ffffff", "#cbe86b", "#f2e9e1", "#1c140d", "#cbe86b"], ["#efffcd", "#dce9be", "#555152", "#2e2633", "#99173c"], ["#343838", "#005f6b", "#008c9e", "#00b4cc", "#00dffc"], ["#413e4a", "#73626e", "#b38184", "#f0b49e", "#f7e4be"], ["#ff4e50", "#fc913a", "#f9d423", "#ede574", "#e1f5c4"], ["#99b898", "#fecea8", "#ff847c", "#e84a5f", "#2a363b"], ["#655643", "#80bca3", "#f6f7bd", "#e6ac27", "#bf4d28"], ["#00a8c6", "#40c0cb", "#f9f2e7", "#aee239", "#8fbe00"], ["#351330", "#424254", "#64908a", "#e8caa4", "#cc2a41"], ["#554236", "#f77825", "#d3ce3d", "#f1efa5", "#60b99a"], ["#5d4157", "#838689", "#a8caba", "#cad7b2", "#ebe3aa"], ["#8c2318", "#5e8c6a", "#88a65e", "#bfb35a", "#f2c45a"], ["#fad089", "#ff9c5b", "#f5634a", "#ed303c", "#3b8183"], ["#ff4242", "#f4fad2", "#d4ee5e", "#e1edb9", "#f0f2eb"], ["#f8b195", "#f67280", "#c06c84", "#6c5b7b", "#355c7d"], ["#d1e751", "#ffffff", "#000000", "#4dbce9", "#26ade4"], ["#1b676b", "#519548", "#88c425", "#bef202", "#eafde6"], ["#5e412f", "#fcebb6", "#78c0a8", "#f07818", "#f0a830"], ["#bcbdac", "#cfbe27", "#f27435", "#f02475", "#3b2d38"], ["#452632", "#91204d", "#e4844a", "#e8bf56", "#e2f7ce"], ["#eee6ab", "#c5bc8e", "#696758", "#45484b", "#36393b"], ["#f0d8a8", "#3d1c00", "#86b8b1", "#f2d694", "#fa2a00"], ["#2a044a", "#0b2e59", "#0d6759", "#7ab317", "#a0c55f"], ["#f04155", "#ff823a", "#f2f26f", "#fff7bd", "#95cfb7"], ["#b9d7d9", "#668284", "#2a2829", "#493736", "#7b3b3b"], ["#bbbb88", "#ccc68d", "#eedd99", "#eec290", "#eeaa88"], ["#b3cc57", "#ecf081", "#ffbe40", "#ef746f", "#ab3e5b"], ["#a3a948", "#edb92e", "#f85931", "#ce1836", "#009989"], ["#300030", "#480048", "#601848", "#c04848", "#f07241"], ["#67917a", "#170409", "#b8af03", "#ccbf82", "#e33258"], ["#aab3ab", "#c4cbb7", "#ebefc9", "#eee0b7", "#e8caaf"], ["#e8d5b7", "#0e2430", "#fc3a51", "#f5b349", "#e8d5b9"], ["#ab526b", "#bca297", "#c5ceae", "#f0e2a4", "#f4ebc3"], ["#607848", "#789048", "#c0d860", "#f0f0d8", "#604848"], ["#b6d8c0", "#c8d9bf", "#dadabd", "#ecdbbc", "#fedcba"], ["#a8e6ce", "#dcedc2", "#ffd3b5", "#ffaaa6", "#ff8c94"], ["#3e4147", "#fffedf", "#dfba69", "#5a2e2e", "#2a2c31"], ["#fc354c", "#29221f", "#13747d", "#0abfbc", "#fcf7c5"], ["#cc0c39", "#e6781e", "#c8cf02", "#f8fcc1", "#1693a7"], ["#1c2130", "#028f76", "#b3e099", "#ffeaad", "#d14334"], ["#a7c5bd", "#e5ddcb", "#eb7b59", "#cf4647", "#524656"], ["#dad6ca", "#1bb0ce", "#4f8699", "#6a5e72", "#563444"], ["#5c323e", "#a82743", "#e15e32", "#c0d23e", "#e5f04c"], ["#edebe6", "#d6e1c7", "#94c7b6", "#403b33", "#d3643b"], ["#fdf1cc", "#c6d6b8", "#987f69", "#e3ad40", "#fcd036"], ["#230f2b", "#f21d41", "#ebebbc", "#bce3c5", "#82b3ae"], ["#b9d3b0", "#81bda4", "#b28774", "#f88f79", "#f6aa93"], ["#3a111c", "#574951", "#83988e", "#bcdea5", "#e6f9bc"], ["#5e3929", "#cd8c52", "#b7d1a3", "#dee8be", "#fcf7d3"], ["#1c0113", "#6b0103", "#a30006", "#c21a01", "#f03c02"], ["#000000", "#9f111b", "#b11623", "#292c37", "#cccccc"], ["#382f32", "#ffeaf2", "#fcd9e5", "#fbc5d8", "#f1396d"], ["#e3dfba", "#c8d6bf", "#93ccc6", "#6cbdb5", "#1a1f1e"], ["#f6f6f6", "#e8e8e8", "#333333", "#990100", "#b90504"], ["#1b325f", "#9cc4e4", "#e9f2f9", "#3a89c9", "#f26c4f"], ["#a1dbb2", "#fee5ad", "#faca66", "#f7a541", "#f45d4c"], ["#c1b398", "#605951", "#fbeec2", "#61a6ab", "#accec0"], ["#5e9fa3", "#dcd1b4", "#fab87f", "#f87e7b", "#b05574"], ["#951f2b", "#f5f4d7", "#e0dfb1", "#a5a36c", "#535233"], ["#8dccad", "#988864", "#fea6a2", "#f9d6ac", "#ffe9af"], ["#2d2d29", "#215a6d", "#3ca2a2", "#92c7a3", "#dfece6"], ["#413d3d", "#040004", "#c8ff00", "#fa023c", "#4b000f"], ["#eff3cd", "#b2d5ba", "#61ada0", "#248f8d", "#605063"], ["#ffefd3", "#fffee4", "#d0ecea", "#9fd6d2", "#8b7a5e"], ["#cfffdd", "#b4dec1", "#5c5863", "#a85163", "#ff1f4c"], ["#9dc9ac", "#fffec7", "#f56218", "#ff9d2e", "#919167"], ["#4e395d", "#827085", "#8ebe94", "#ccfc8e", "#dc5b3e"], ["#a8a7a7", "#cc527a", "#e8175d", "#474747", "#363636"], ["#f8edd1", "#d88a8a", "#474843", "#9d9d93", "#c5cfc6"], ["#046d8b", "#309292", "#2fb8ac", "#93a42a", "#ecbe13"], ["#f38a8a", "#55443d", "#a0cab5", "#cde9ca", "#f1edd0"], ["#a70267", "#f10c49", "#fb6b41", "#f6d86b", "#339194"], ["#ff003c", "#ff8a00", "#fabe28", "#88c100", "#00c176"], ["#ffedbf", "#f7803c", "#f54828", "#2e0d23", "#f8e4c1"], ["#4e4d4a", "#353432", "#94ba65", "#2790b0", "#2b4e72"], ["#0ca5b0", "#4e3f30", "#fefeeb", "#f8f4e4", "#a5b3aa"], ["#4d3b3b", "#de6262", "#ffb88c", "#ffd0b3", "#f5e0d3"], ["#fffbb7", "#a6f6af", "#66b6ab", "#5b7c8d", "#4f2958"], ["#edf6ee", "#d1c089", "#b3204d", "#412e28", "#151101"], ["#9d7e79", "#ccac95", "#9a947c", "#748b83", "#5b756c"], ["#fcfef5", "#e9ffe1", "#cdcfb7", "#d6e6c3", "#fafbe3"], ["#9cddc8", "#bfd8ad", "#ddd9ab", "#f7af63", "#633d2e"], ["#30261c", "#403831", "#36544f", "#1f5f61", "#0b8185"], ["#aaff00", "#ffaa00", "#ff00aa", "#aa00ff", "#00aaff"], ["#d1313d", "#e5625c", "#f9bf76", "#8eb2c5", "#615375"], ["#ffe181", "#eee9e5", "#fad3b2", "#ffba7f", "#ff9c97"], ["#73c8a9", "#dee1b6", "#e1b866", "#bd5532", "#373b44"], ["#805841", "#dcf7f3", "#fffcdd", "#ffd8d8", "#f5a2a2"]];
2
+ export { palettes };