@holoscript/std 3.1.1 → 7.0.0

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 (142) hide show
  1. package/LICENSE +21 -0
  2. package/dist/__tests__/EconomicPrimitives.test.d.ts +2 -0
  3. package/dist/__tests__/EconomicTraits.test.d.ts +2 -0
  4. package/dist/__tests__/SimulationLabPrimitives.test.d.ts +2 -0
  5. package/dist/__tests__/collections.test.d.ts +2 -0
  6. package/dist/__tests__/events.test.d.ts +2 -0
  7. package/dist/__tests__/index.test.d.ts +2 -0
  8. package/dist/__tests__/index.test.d.ts.map +1 -0
  9. package/dist/__tests__/materials.test.d.ts +2 -0
  10. package/dist/__tests__/math.test.d.ts +2 -0
  11. package/dist/__tests__/physics.test.d.ts +2 -0
  12. package/dist/__tests__/spatial.test.d.ts +2 -0
  13. package/dist/__tests__/standard-library-fundamentals.test.d.ts +2 -0
  14. package/dist/__tests__/standard-library-fundamentals.test.d.ts.map +1 -0
  15. package/dist/__tests__/string-and-time-utilities.test.d.ts +2 -0
  16. package/dist/__tests__/string-and-time-utilities.test.d.ts.map +1 -0
  17. package/dist/__tests__/string-decoupled.test.d.ts +2 -0
  18. package/dist/__tests__/string.test.d.ts +2 -0
  19. package/dist/__tests__/time.test.d.ts +2 -0
  20. package/dist/chunk-DZHAVOCH.js +686 -0
  21. package/dist/chunk-DZHAVOCH.js.map +1 -0
  22. package/dist/chunk-P4O3WNG2.js +287 -0
  23. package/dist/chunk-P4O3WNG2.js.map +1 -0
  24. package/dist/chunk-PFX2JM4X.js +683 -0
  25. package/dist/chunk-PFX2JM4X.js.map +1 -0
  26. package/dist/chunk-PR4QN5HX.js +43 -0
  27. package/dist/chunk-PR4QN5HX.js.map +1 -0
  28. package/dist/chunk-WS6W35YC.js +443 -0
  29. package/dist/chunk-WS6W35YC.js.map +1 -0
  30. package/dist/chunk-XBA4ARST.js +9313 -0
  31. package/dist/chunk-XBA4ARST.js.map +1 -0
  32. package/dist/chunk-XJIFG7G3.js +348 -0
  33. package/dist/chunk-XJIFG7G3.js.map +1 -0
  34. package/dist/chunk-ZXVZAQCZ.js +470 -0
  35. package/dist/chunk-ZXVZAQCZ.js.map +1 -0
  36. package/dist/collections.cjs +715 -0
  37. package/dist/collections.cjs.map +1 -0
  38. package/dist/collections.d.ts +177 -0
  39. package/dist/collections.js +18 -0
  40. package/dist/collections.js.map +1 -0
  41. package/dist/events.d.ts +32 -0
  42. package/dist/fs/__tests__/file-watch-system.test.d.ts +2 -0
  43. package/dist/fs/__tests__/file-watch-system.test.d.ts.map +1 -0
  44. package/dist/fs/__tests__/path-utilities.test.d.ts +2 -0
  45. package/dist/fs/__tests__/path-utilities.test.d.ts.map +1 -0
  46. package/dist/fs/__tests__/path.test.d.ts +2 -0
  47. package/dist/fs/__tests__/path.test.d.ts.map +1 -0
  48. package/dist/fs/fs.d.ts +288 -0
  49. package/dist/fs/fs.d.ts.map +1 -0
  50. package/dist/fs/index.cjs +9338 -0
  51. package/dist/fs/index.cjs.map +1 -0
  52. package/dist/fs/index.d.ts +51 -0
  53. package/dist/fs/index.d.ts.map +1 -0
  54. package/dist/fs/index.js +204 -0
  55. package/dist/fs/index.js.map +1 -0
  56. package/dist/fs/path.d.ts +135 -0
  57. package/dist/fs/path.d.ts.map +1 -0
  58. package/dist/fs/watch.d.ts +133 -0
  59. package/dist/fs/watch.d.ts.map +1 -0
  60. package/dist/index.cjs +13326 -0
  61. package/dist/index.cjs.map +1 -0
  62. package/dist/index.d.ts +102 -0
  63. package/dist/index.d.ts.map +1 -1
  64. package/dist/index.js +1275 -190
  65. package/dist/index.js.map +1 -0
  66. package/dist/materials.d.ts +50 -0
  67. package/dist/math.cjs +595 -0
  68. package/dist/math.cjs.map +1 -0
  69. package/dist/math.d.ts +162 -0
  70. package/dist/math.js +54 -0
  71. package/dist/math.js.map +1 -0
  72. package/dist/physics.d.ts +59 -0
  73. package/dist/spatial.d.ts +82 -0
  74. package/dist/string.basic.test.d.ts +5 -0
  75. package/dist/string.basic.test.d.ts.map +1 -0
  76. package/dist/string.cjs +422 -0
  77. package/dist/string.cjs.map +1 -0
  78. package/dist/string.d.ts +212 -0
  79. package/dist/string.d.ts.map +1 -1
  80. package/dist/string.js +108 -0
  81. package/dist/string.js.map +1 -0
  82. package/dist/string.test.d.ts +5 -0
  83. package/dist/string.test.d.ts.map +1 -0
  84. package/dist/time.cjs +512 -0
  85. package/dist/time.cjs.map +1 -0
  86. package/dist/time.d.ts +215 -0
  87. package/dist/time.js +44 -0
  88. package/dist/time.js.map +1 -0
  89. package/dist/traits/ARTraits.d.ts +14 -0
  90. package/dist/traits/EconomicPrimitives.cjs +335 -0
  91. package/dist/traits/EconomicPrimitives.cjs.map +1 -0
  92. package/dist/traits/EconomicPrimitives.d.ts +345 -0
  93. package/dist/traits/EconomicPrimitives.js +56 -0
  94. package/dist/traits/EconomicPrimitives.js.map +1 -0
  95. package/dist/traits/EconomicTraits.cjs +471 -0
  96. package/dist/traits/EconomicTraits.cjs.map +1 -0
  97. package/dist/traits/EconomicTraits.d.ts +71 -0
  98. package/dist/traits/EconomicTraits.js +18 -0
  99. package/dist/traits/EconomicTraits.js.map +1 -0
  100. package/dist/traits/IoTTraits.d.ts +14 -0
  101. package/dist/traits/SimulationLabPrimitives.d.ts +187 -0
  102. package/dist/traits/SimulationLabTraits.d.ts +42 -0
  103. package/dist/traits/VRRTraits.d.ts +150 -0
  104. package/dist/traits/__tests__/ARTraits.test.d.ts +2 -0
  105. package/dist/traits/__tests__/ARTraits.test.d.ts.map +1 -0
  106. package/dist/traits/__tests__/EconomicPrimitives.test.d.ts +2 -0
  107. package/dist/traits/__tests__/EconomicPrimitives.test.d.ts.map +1 -0
  108. package/dist/traits/__tests__/EconomicTraits.test.d.ts +2 -0
  109. package/dist/traits/__tests__/EconomicTraits.test.d.ts.map +1 -0
  110. package/dist/types.d.ts +202 -0
  111. package/dist/types.d.ts.map +1 -1
  112. package/error-utf8.log +6 -0
  113. package/error.log +0 -0
  114. package/package.json +35 -18
  115. package/src/__tests__/index.test.ts +14 -0
  116. package/src/__tests__/{Sprint33.test.ts → standard-library-fundamentals.test.ts} +91 -74
  117. package/src/__tests__/{Sprint56.test.ts → string-and-time-utilities.test.ts} +64 -64
  118. package/src/__tests__/string-decoupled.test.ts +6 -9
  119. package/src/fs/__tests__/file-watch-system.test.ts +675 -0
  120. package/src/fs/__tests__/path-utilities.test.ts +375 -0
  121. package/src/fs/__tests__/path.test.ts +287 -0
  122. package/src/fs/fs.ts +692 -0
  123. package/src/fs/index.ts +194 -0
  124. package/src/fs/path.ts +310 -0
  125. package/src/fs/watch.ts +413 -0
  126. package/src/index.ts +3 -1
  127. package/src/math.ts +1 -1
  128. package/src/string.basic.test.ts +1 -1
  129. package/src/string.test.ts +4 -4
  130. package/src/string.ts +32 -17
  131. package/src/time.ts +1 -1
  132. package/src/traits/ARTraits.ts +2 -2
  133. package/src/traits/IoTTraits.ts +2 -2
  134. package/src/traits/VRRTraits.ts +2 -2
  135. package/src/traits/__tests__/ARTraits.test.ts +8 -0
  136. package/src/traits/__tests__/EconomicPrimitives.test.ts +14 -0
  137. package/src/traits/__tests__/EconomicTraits.test.ts +16 -0
  138. package/src/types.ts +10 -3
  139. package/std_error.log +5 -0
  140. package/tsup.config.ts +20 -0
  141. package/dist/__tests__/Sprint33.test.d.ts.map +0 -1
  142. package/dist/__tests__/Sprint56.test.d.ts.map +0 -1
@@ -0,0 +1,686 @@
1
+ // src/types.ts
2
+ function vec2(x = 0, y = 0) {
3
+ const v = [x, y];
4
+ Object.defineProperty(v, "x", { value: x, writable: true, enumerable: false, configurable: true });
5
+ Object.defineProperty(v, "y", { value: y, writable: true, enumerable: false, configurable: true });
6
+ return v;
7
+ }
8
+ function vec3(x = 0, y = 0, z = 0) {
9
+ const v = [x, y, z];
10
+ Object.defineProperty(v, "x", { value: x, writable: true, enumerable: false, configurable: true });
11
+ Object.defineProperty(v, "y", { value: y, writable: true, enumerable: false, configurable: true });
12
+ Object.defineProperty(v, "z", { value: z, writable: true, enumerable: false, configurable: true });
13
+ return v;
14
+ }
15
+ function vec4(x = 0, y = 0, z = 0, w = 0) {
16
+ return { x, y, z, w };
17
+ }
18
+ function quat(x = 0, y = 0, z = 0, w = 1) {
19
+ return { x, y, z, w };
20
+ }
21
+ function transform(position = vec3(), rotation = quat(), scale = vec3(1, 1, 1)) {
22
+ return { position, rotation, scale };
23
+ }
24
+ function rgb(r, g, b) {
25
+ return { r, g, b };
26
+ }
27
+ function rgba(r, g, b, a = 1) {
28
+ return { r, g, b, a };
29
+ }
30
+ function hsl(h, s, l) {
31
+ return { h, s, l };
32
+ }
33
+ function aabb(min = vec3(), max = vec3()) {
34
+ return { min, max };
35
+ }
36
+ function ray(origin, direction) {
37
+ return { origin, direction };
38
+ }
39
+ function vec3ToArray(v) {
40
+ return [v.x, v.y, v.z];
41
+ }
42
+ function arrayToVec3(arr) {
43
+ return vec3(arr[0] || 0, arr[1] || 0, arr[2] || 0);
44
+ }
45
+ function quatToArray(q) {
46
+ return [q.x, q.y, q.z, q.w];
47
+ }
48
+ function arrayToQuat(arr) {
49
+ return { x: arr[0] || 0, y: arr[1] || 0, z: arr[2] || 0, w: arr[3] ?? 1 };
50
+ }
51
+ function parseColor(color) {
52
+ if (typeof color === "string") {
53
+ if (color.startsWith("#")) {
54
+ const hex = color.slice(1);
55
+ if (hex.length === 3) {
56
+ return {
57
+ r: parseInt(hex[0] + hex[0], 16) / 255,
58
+ g: parseInt(hex[1] + hex[1], 16) / 255,
59
+ b: parseInt(hex[2] + hex[2], 16) / 255,
60
+ a: 1
61
+ };
62
+ } else if (hex.length === 6) {
63
+ return {
64
+ r: parseInt(hex.slice(0, 2), 16) / 255,
65
+ g: parseInt(hex.slice(2, 4), 16) / 255,
66
+ b: parseInt(hex.slice(4, 6), 16) / 255,
67
+ a: 1
68
+ };
69
+ } else if (hex.length === 8) {
70
+ return {
71
+ r: parseInt(hex.slice(0, 2), 16) / 255,
72
+ g: parseInt(hex.slice(2, 4), 16) / 255,
73
+ b: parseInt(hex.slice(4, 6), 16) / 255,
74
+ a: parseInt(hex.slice(6, 8), 16) / 255
75
+ };
76
+ }
77
+ }
78
+ const namedColors = {
79
+ white: { r: 1, g: 1, b: 1, a: 1 },
80
+ black: { r: 0, g: 0, b: 0, a: 1 },
81
+ red: { r: 1, g: 0, b: 0, a: 1 },
82
+ green: { r: 0, g: 1, b: 0, a: 1 },
83
+ blue: { r: 0, g: 0, b: 1, a: 1 },
84
+ yellow: { r: 1, g: 1, b: 0, a: 1 },
85
+ cyan: { r: 0, g: 1, b: 1, a: 1 },
86
+ magenta: { r: 1, g: 0, b: 1, a: 1 }
87
+ };
88
+ return namedColors[color.toLowerCase()] || { r: 1, g: 1, b: 1, a: 1 };
89
+ }
90
+ if (typeof color === "number") {
91
+ return {
92
+ r: (color >> 16 & 255) / 255,
93
+ g: (color >> 8 & 255) / 255,
94
+ b: (color & 255) / 255,
95
+ a: 1
96
+ };
97
+ }
98
+ if ("h" in color) {
99
+ const { h, s, l } = color;
100
+ const c = (1 - Math.abs(2 * l - 1)) * s;
101
+ const x = c * (1 - Math.abs(h / 60 % 2 - 1));
102
+ const m = l - c / 2;
103
+ let r = 0, g = 0, b = 0;
104
+ if (h < 60) {
105
+ r = c;
106
+ g = x;
107
+ } else if (h < 120) {
108
+ r = x;
109
+ g = c;
110
+ } else if (h < 180) {
111
+ g = c;
112
+ b = x;
113
+ } else if (h < 240) {
114
+ g = x;
115
+ b = c;
116
+ } else if (h < 300) {
117
+ r = x;
118
+ b = c;
119
+ } else {
120
+ r = c;
121
+ b = x;
122
+ }
123
+ return { r: r + m, g: g + m, b: b + m, a: 1 };
124
+ }
125
+ if ("a" in color) {
126
+ return color;
127
+ }
128
+ return { ...color, a: 1 };
129
+ }
130
+ function colorToHex(color) {
131
+ const r = Math.round(color.r * 255).toString(16).padStart(2, "0");
132
+ const g = Math.round(color.g * 255).toString(16).padStart(2, "0");
133
+ const b = Math.round(color.b * 255).toString(16).padStart(2, "0");
134
+ return `#${r}${g}${b}`;
135
+ }
136
+
137
+ // src/math.ts
138
+ var PI = Math.PI;
139
+ var TAU = Math.PI * 2;
140
+ var HALF_PI = Math.PI / 2;
141
+ var DEG_TO_RAD = Math.PI / 180;
142
+ var RAD_TO_DEG = 180 / Math.PI;
143
+ var EPSILON = 1e-6;
144
+ function clamp(value, min, max) {
145
+ return Math.max(min, Math.min(max, value));
146
+ }
147
+ function lerp(a, b, t) {
148
+ return a + (b - a) * t;
149
+ }
150
+ function inverseLerp(a, b, value) {
151
+ return (value - a) / (b - a);
152
+ }
153
+ function remap(value, inMin, inMax, outMin, outMax) {
154
+ return lerp(outMin, outMax, inverseLerp(inMin, inMax, value));
155
+ }
156
+ function smoothstep(edge0, edge1, x) {
157
+ const t = clamp((x - edge0) / (edge1 - edge0), 0, 1);
158
+ return t * t * (3 - 2 * t);
159
+ }
160
+ function smootherstep(edge0, edge1, x) {
161
+ const t = clamp((x - edge0) / (edge1 - edge0), 0, 1);
162
+ return t * t * t * (t * (t * 6 - 15) + 10);
163
+ }
164
+ function degToRad(degrees) {
165
+ return degrees * DEG_TO_RAD;
166
+ }
167
+ function radToDeg(radians) {
168
+ return radians * RAD_TO_DEG;
169
+ }
170
+ function mod(n, m) {
171
+ return (n % m + m) % m;
172
+ }
173
+ function fract(x) {
174
+ return x - Math.floor(x);
175
+ }
176
+ function sign(x) {
177
+ return x > 0 ? 1 : x < 0 ? -1 : 0;
178
+ }
179
+ function step(edge, x) {
180
+ return x < edge ? 0 : 1;
181
+ }
182
+ var vec2Math = {
183
+ add: (a, b) => ({ x: a.x + b.x, y: a.y + b.y }),
184
+ sub: (a, b) => ({ x: a.x - b.x, y: a.y - b.y }),
185
+ mul: (a, s) => ({ x: a.x * s, y: a.y * s }),
186
+ div: (a, s) => ({ x: a.x / s, y: a.y / s }),
187
+ dot: (a, b) => a.x * b.x + a.y * b.y,
188
+ length: (v) => Math.sqrt(v.x * v.x + v.y * v.y),
189
+ lengthSq: (v) => v.x * v.x + v.y * v.y,
190
+ normalize: (v) => {
191
+ const len = vec2Math.length(v);
192
+ return len > 0 ? vec2Math.div(v, len) : { x: 0, y: 0 };
193
+ },
194
+ distance: (a, b) => vec2Math.length(vec2Math.sub(a, b)),
195
+ lerp: (a, b, t) => ({
196
+ x: lerp(a.x, b.x, t),
197
+ y: lerp(a.y, b.y, t)
198
+ }),
199
+ rotate: (v, angle) => {
200
+ const c = Math.cos(angle);
201
+ const s = Math.sin(angle);
202
+ return { x: v.x * c - v.y * s, y: v.x * s + v.y * c };
203
+ },
204
+ angle: (v) => Math.atan2(v.y, v.x),
205
+ angleBetween: (a, b) => {
206
+ return Math.acos(clamp(vec2Math.dot(vec2Math.normalize(a), vec2Math.normalize(b)), -1, 1));
207
+ }
208
+ };
209
+ var vec3Math = {
210
+ zero: () => vec3(0, 0, 0),
211
+ one: () => vec3(1, 1, 1),
212
+ up: () => vec3(0, 1, 0),
213
+ down: () => vec3(0, -1, 0),
214
+ forward: () => vec3(0, 0, -1),
215
+ back: () => vec3(0, 0, 1),
216
+ left: () => vec3(-1, 0, 0),
217
+ right: () => vec3(1, 0, 0),
218
+ add: (a, b) => vec3(a.x + b.x, a.y + b.y, a.z + b.z),
219
+ sub: (a, b) => ({ x: a.x - b.x, y: a.y - b.y, z: a.z - b.z }),
220
+ mul: (a, s) => ({ x: a.x * s, y: a.y * s, z: a.z * s }),
221
+ div: (a, s) => ({ x: a.x / s, y: a.y / s, z: a.z / s }),
222
+ mulVec: (a, b) => ({ x: a.x * b.x, y: a.y * b.y, z: a.z * b.z }),
223
+ dot: (a, b) => a.x * b.x + a.y * b.y + a.z * b.z,
224
+ cross: (a, b) => ({
225
+ x: a.y * b.z - a.z * b.y,
226
+ y: a.z * b.x - a.x * b.z,
227
+ z: a.x * b.y - a.y * b.x
228
+ }),
229
+ length: (v) => Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z),
230
+ lengthSq: (v) => v.x * v.x + v.y * v.y + v.z * v.z,
231
+ normalize: (v) => {
232
+ const len = vec3Math.length(v);
233
+ return len > EPSILON ? vec3Math.div(v, len) : vec3(0, 0, 0);
234
+ },
235
+ distance: (a, b) => vec3Math.length(vec3Math.sub(a, b)),
236
+ distanceSq: (a, b) => vec3Math.lengthSq(vec3Math.sub(a, b)),
237
+ lerp: (a, b, t) => ({
238
+ x: lerp(a.x, b.x, t),
239
+ y: lerp(a.y, b.y, t),
240
+ z: lerp(a.z, b.z, t)
241
+ }),
242
+ slerp: (a, b, t) => {
243
+ const dot = clamp(vec3Math.dot(a, b), -1, 1);
244
+ const theta = Math.acos(dot) * t;
245
+ const relative = vec3Math.normalize(vec3Math.sub(b, vec3Math.mul(a, dot)));
246
+ return vec3Math.add(vec3Math.mul(a, Math.cos(theta)), vec3Math.mul(relative, Math.sin(theta)));
247
+ },
248
+ negate: (v) => ({ x: -v.x, y: -v.y, z: -v.z }),
249
+ abs: (v) => ({ x: Math.abs(v.x), y: Math.abs(v.y), z: Math.abs(v.z) }),
250
+ min: (a, b) => ({
251
+ x: Math.min(a.x, b.x),
252
+ y: Math.min(a.y, b.y),
253
+ z: Math.min(a.z, b.z)
254
+ }),
255
+ max: (a, b) => ({
256
+ x: Math.max(a.x, b.x),
257
+ y: Math.max(a.y, b.y),
258
+ z: Math.max(a.z, b.z)
259
+ }),
260
+ clamp: (v, min, max) => ({
261
+ x: clamp(v.x, min.x, max.x),
262
+ y: clamp(v.y, min.y, max.y),
263
+ z: clamp(v.z, min.z, max.z)
264
+ }),
265
+ floor: (v) => ({
266
+ x: Math.floor(v.x),
267
+ y: Math.floor(v.y),
268
+ z: Math.floor(v.z)
269
+ }),
270
+ ceil: (v) => ({
271
+ x: Math.ceil(v.x),
272
+ y: Math.ceil(v.y),
273
+ z: Math.ceil(v.z)
274
+ }),
275
+ round: (v) => ({
276
+ x: Math.round(v.x),
277
+ y: Math.round(v.y),
278
+ z: Math.round(v.z)
279
+ }),
280
+ reflect: (v, normal) => {
281
+ const dot = vec3Math.dot(v, normal);
282
+ return vec3Math.sub(v, vec3Math.mul(normal, 2 * dot));
283
+ },
284
+ project: (v, onto) => {
285
+ const dot = vec3Math.dot(v, onto);
286
+ const lenSq = vec3Math.lengthSq(onto);
287
+ return vec3Math.mul(onto, dot / lenSq);
288
+ },
289
+ angle: (a, b) => {
290
+ const dot = vec3Math.dot(vec3Math.normalize(a), vec3Math.normalize(b));
291
+ return Math.acos(clamp(dot, -1, 1));
292
+ },
293
+ equals: (a, b, epsilon = EPSILON) => {
294
+ return Math.abs(a.x - b.x) < epsilon && Math.abs(a.y - b.y) < epsilon && Math.abs(a.z - b.z) < epsilon;
295
+ }
296
+ };
297
+ var quatMath = {
298
+ identity: () => quat(0, 0, 0, 1),
299
+ fromAxisAngle: (axis, angle) => {
300
+ const halfAngle = angle / 2;
301
+ const s = Math.sin(halfAngle);
302
+ const normalized = vec3Math.normalize(axis);
303
+ return {
304
+ x: normalized.x * s,
305
+ y: normalized.y * s,
306
+ z: normalized.z * s,
307
+ w: Math.cos(halfAngle)
308
+ };
309
+ },
310
+ fromEuler: (euler) => {
311
+ const { x, y, z } = euler;
312
+ const c1 = Math.cos(degToRad(x) / 2);
313
+ const c2 = Math.cos(degToRad(y) / 2);
314
+ const c3 = Math.cos(degToRad(z) / 2);
315
+ const s1 = Math.sin(degToRad(x) / 2);
316
+ const s2 = Math.sin(degToRad(y) / 2);
317
+ const s3 = Math.sin(degToRad(z) / 2);
318
+ return {
319
+ x: s1 * c2 * c3 + c1 * s2 * s3,
320
+ y: c1 * s2 * c3 - s1 * c2 * s3,
321
+ z: c1 * c2 * s3 + s1 * s2 * c3,
322
+ w: c1 * c2 * c3 - s1 * s2 * s3
323
+ };
324
+ },
325
+ toEuler: (q) => {
326
+ const sinr_cosp = 2 * (q.w * q.x + q.y * q.z);
327
+ const cosr_cosp = 1 - 2 * (q.x * q.x + q.y * q.y);
328
+ const x = Math.atan2(sinr_cosp, cosr_cosp);
329
+ const sinp = 2 * (q.w * q.y - q.z * q.x);
330
+ let y;
331
+ if (Math.abs(sinp) >= 1) {
332
+ y = Math.PI / 2 * Math.sign(sinp);
333
+ } else {
334
+ y = Math.asin(sinp);
335
+ }
336
+ const siny_cosp = 2 * (q.w * q.z + q.x * q.y);
337
+ const cosy_cosp = 1 - 2 * (q.y * q.y + q.z * q.z);
338
+ const z = Math.atan2(siny_cosp, cosy_cosp);
339
+ return {
340
+ x: radToDeg(x),
341
+ y: radToDeg(y),
342
+ z: radToDeg(z)
343
+ };
344
+ },
345
+ multiply: (a, b) => ({
346
+ x: a.w * b.x + a.x * b.w + a.y * b.z - a.z * b.y,
347
+ y: a.w * b.y - a.x * b.z + a.y * b.w + a.z * b.x,
348
+ z: a.w * b.z + a.x * b.y - a.y * b.x + a.z * b.w,
349
+ w: a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z
350
+ }),
351
+ conjugate: (q) => ({ x: -q.x, y: -q.y, z: -q.z, w: q.w }),
352
+ inverse: (q) => {
353
+ const lenSq = q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w;
354
+ return {
355
+ x: -q.x / lenSq,
356
+ y: -q.y / lenSq,
357
+ z: -q.z / lenSq,
358
+ w: q.w / lenSq
359
+ };
360
+ },
361
+ normalize: (q) => {
362
+ const len = Math.sqrt(q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w);
363
+ return { x: q.x / len, y: q.y / len, z: q.z / len, w: q.w / len };
364
+ },
365
+ dot: (a, b) => a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w,
366
+ slerp: (a, b, t) => {
367
+ let dot = quatMath.dot(a, b);
368
+ let bAdjusted = b;
369
+ if (dot < 0) {
370
+ bAdjusted = { x: -b.x, y: -b.y, z: -b.z, w: -b.w };
371
+ dot = -dot;
372
+ }
373
+ if (dot > 0.9995) {
374
+ return quatMath.normalize({
375
+ x: lerp(a.x, bAdjusted.x, t),
376
+ y: lerp(a.y, bAdjusted.y, t),
377
+ z: lerp(a.z, bAdjusted.z, t),
378
+ w: lerp(a.w, bAdjusted.w, t)
379
+ });
380
+ }
381
+ const theta0 = Math.acos(dot);
382
+ const theta = theta0 * t;
383
+ const sinTheta = Math.sin(theta);
384
+ const sinTheta0 = Math.sin(theta0);
385
+ const s0 = Math.cos(theta) - dot * sinTheta / sinTheta0;
386
+ const s1 = sinTheta / sinTheta0;
387
+ return {
388
+ x: a.x * s0 + bAdjusted.x * s1,
389
+ y: a.y * s0 + bAdjusted.y * s1,
390
+ z: a.z * s0 + bAdjusted.z * s1,
391
+ w: a.w * s0 + bAdjusted.w * s1
392
+ };
393
+ },
394
+ rotateVec3: (q, v) => {
395
+ const qv = { x: q.x, y: q.y, z: q.z };
396
+ const uv = vec3Math.cross(qv, v);
397
+ const uuv = vec3Math.cross(qv, uv);
398
+ return vec3Math.add(v, vec3Math.add(vec3Math.mul(uv, 2 * q.w), vec3Math.mul(uuv, 2)));
399
+ },
400
+ lookAt: (forward, up = vec3(0, 1, 0)) => {
401
+ const f = vec3Math.normalize(forward);
402
+ const r = vec3Math.normalize(vec3Math.cross(up, f));
403
+ const u = vec3Math.cross(f, r);
404
+ const trace = r.x + u.y + f.z;
405
+ let q;
406
+ if (trace > 0) {
407
+ const s = 0.5 / Math.sqrt(trace + 1);
408
+ q = {
409
+ w: 0.25 / s,
410
+ x: (u.z - f.y) * s,
411
+ y: (f.x - r.z) * s,
412
+ z: (r.y - u.x) * s
413
+ };
414
+ } else if (r.x > u.y && r.x > f.z) {
415
+ const s = 2 * Math.sqrt(1 + r.x - u.y - f.z);
416
+ q = {
417
+ w: (u.z - f.y) / s,
418
+ x: 0.25 * s,
419
+ y: (u.x + r.y) / s,
420
+ z: (f.x + r.z) / s
421
+ };
422
+ } else if (u.y > f.z) {
423
+ const s = 2 * Math.sqrt(1 + u.y - r.x - f.z);
424
+ q = {
425
+ w: (f.x - r.z) / s,
426
+ x: (u.x + r.y) / s,
427
+ y: 0.25 * s,
428
+ z: (f.y + u.z) / s
429
+ };
430
+ } else {
431
+ const s = 2 * Math.sqrt(1 + f.z - r.x - u.y);
432
+ q = {
433
+ w: (r.y - u.x) / s,
434
+ x: (f.x + r.z) / s,
435
+ y: (f.y + u.z) / s,
436
+ z: 0.25 * s
437
+ };
438
+ }
439
+ return quatMath.normalize(q);
440
+ }
441
+ };
442
+ var aabbMath = {
443
+ contains: (aabb2, point) => {
444
+ return point.x >= aabb2.min.x && point.x <= aabb2.max.x && point.y >= aabb2.min.y && point.y <= aabb2.max.y && point.z >= aabb2.min.z && point.z <= aabb2.max.z;
445
+ },
446
+ intersects: (a, b) => {
447
+ return a.min.x <= b.max.x && a.max.x >= b.min.x && a.min.y <= b.max.y && a.max.y >= b.min.y && a.min.z <= b.max.z && a.max.z >= b.min.z;
448
+ },
449
+ center: (aabb2) => vec3Math.mul(vec3Math.add(aabb2.min, aabb2.max), 0.5),
450
+ size: (aabb2) => vec3Math.sub(aabb2.max, aabb2.min),
451
+ expand: (aabb2, point) => ({
452
+ min: vec3Math.min(aabb2.min, point),
453
+ max: vec3Math.max(aabb2.max, point)
454
+ }),
455
+ merge: (a, b) => ({
456
+ min: vec3Math.min(a.min, b.min),
457
+ max: vec3Math.max(a.max, b.max)
458
+ })
459
+ };
460
+ var perm = new Uint8Array(512);
461
+ for (let i = 0; i < 256; i++) perm[i] = perm[i + 256] = i;
462
+ for (let i = 255; i > 0; i--) {
463
+ const j = Math.floor(Math.random() * (i + 1));
464
+ [perm[i], perm[j]] = [perm[j], perm[i]];
465
+ perm[i + 256] = perm[i];
466
+ }
467
+ function fade(t) {
468
+ return t * t * t * (t * (t * 6 - 15) + 10);
469
+ }
470
+ function grad(hash, x, y, z) {
471
+ const h = hash & 15;
472
+ const u = h < 8 ? x : y;
473
+ const v = h < 4 ? y : h === 12 || h === 14 ? x : z;
474
+ return ((h & 1) === 0 ? u : -u) + ((h & 2) === 0 ? v : -v);
475
+ }
476
+ var noise = {
477
+ /**
478
+ * 3D Perlin noise (-1 to 1)
479
+ */
480
+ perlin3d: (x, y, z) => {
481
+ const X = Math.floor(x) & 255;
482
+ const Y = Math.floor(y) & 255;
483
+ const Z = Math.floor(z) & 255;
484
+ x -= Math.floor(x);
485
+ y -= Math.floor(y);
486
+ z -= Math.floor(z);
487
+ const u = fade(x);
488
+ const v = fade(y);
489
+ const w = fade(z);
490
+ const A = perm[X] + Y;
491
+ const AA = perm[A] + Z;
492
+ const AB = perm[A + 1] + Z;
493
+ const B = perm[X + 1] + Y;
494
+ const BA = perm[B] + Z;
495
+ const BB = perm[B + 1] + Z;
496
+ return lerp(
497
+ lerp(
498
+ lerp(grad(perm[AA], x, y, z), grad(perm[BA], x - 1, y, z), u),
499
+ lerp(grad(perm[AB], x, y - 1, z), grad(perm[BB], x - 1, y - 1, z), u),
500
+ v
501
+ ),
502
+ lerp(
503
+ lerp(grad(perm[AA + 1], x, y, z - 1), grad(perm[BA + 1], x - 1, y, z - 1), u),
504
+ lerp(grad(perm[AB + 1], x, y - 1, z - 1), grad(perm[BB + 1], x - 1, y - 1, z - 1), u),
505
+ v
506
+ ),
507
+ w
508
+ );
509
+ },
510
+ /**
511
+ * 2D Perlin noise (-1 to 1)
512
+ */
513
+ perlin2d: (x, y) => {
514
+ return noise.perlin3d(x, y, 0);
515
+ },
516
+ /**
517
+ * Fractal Brownian Motion (fBm)
518
+ */
519
+ fbm: (x, y, z, octaves = 6, lacunarity = 2, gain = 0.5) => {
520
+ let value = 0;
521
+ let amplitude = 1;
522
+ let frequency = 1;
523
+ let maxValue = 0;
524
+ for (let i = 0; i < octaves; i++) {
525
+ value += amplitude * noise.perlin3d(x * frequency, y * frequency, z * frequency);
526
+ maxValue += amplitude;
527
+ amplitude *= gain;
528
+ frequency *= lacunarity;
529
+ }
530
+ return value / maxValue;
531
+ },
532
+ /**
533
+ * Simplex-like noise (approximation using perlin)
534
+ */
535
+ simplex: (x, y) => {
536
+ return noise.perlin2d(x * 1.2, y * 1.2);
537
+ },
538
+ /**
539
+ * Worley/Cellular noise
540
+ */
541
+ worley: (x, y, z) => {
542
+ const xi = Math.floor(x);
543
+ const yi = Math.floor(y);
544
+ const zi = Math.floor(z);
545
+ let minDist = Infinity;
546
+ for (let i = -1; i <= 1; i++) {
547
+ for (let j = -1; j <= 1; j++) {
548
+ for (let k = -1; k <= 1; k++) {
549
+ const cellX = xi + i;
550
+ const cellY = yi + j;
551
+ const cellZ = zi + k;
552
+ const hash = perm[perm[perm[cellX & 255] + cellY & 255] + cellZ & 255];
553
+ const px = cellX + hash / 255;
554
+ const py = cellY + hash * 7 % 255 / 255;
555
+ const pz = cellZ + hash * 13 % 255 / 255;
556
+ const dist = (x - px) * (x - px) + (y - py) * (y - py) + (z - pz) * (z - pz);
557
+ minDist = Math.min(minDist, dist);
558
+ }
559
+ }
560
+ }
561
+ return Math.sqrt(minDist);
562
+ }
563
+ };
564
+ var random = {
565
+ /**
566
+ * Random float between 0 and 1
567
+ */
568
+ float: () => Math.random(),
569
+ /**
570
+ * Random float in range [min, max)
571
+ */
572
+ range: (min, max) => min + Math.random() * (max - min),
573
+ /**
574
+ * Random integer in range [min, max]
575
+ */
576
+ int: (min, max) => Math.floor(min + Math.random() * (max - min + 1)),
577
+ /**
578
+ * Random boolean with probability
579
+ */
580
+ bool: (probability = 0.5) => Math.random() < probability,
581
+ /**
582
+ * Random element from array
583
+ */
584
+ pick: (array) => array[Math.floor(Math.random() * array.length)],
585
+ /**
586
+ * Shuffle array (Fisher-Yates)
587
+ */
588
+ shuffle: (array) => {
589
+ const result = [...array];
590
+ for (let i = result.length - 1; i > 0; i--) {
591
+ const j = Math.floor(Math.random() * (i + 1));
592
+ [result[i], result[j]] = [result[j], result[i]];
593
+ }
594
+ return result;
595
+ },
596
+ /**
597
+ * Random Vec3 in unit sphere
598
+ */
599
+ insideUnitSphere: () => {
600
+ const theta = Math.random() * TAU;
601
+ const phi = Math.acos(2 * Math.random() - 1);
602
+ const r = Math.cbrt(Math.random());
603
+ return {
604
+ x: r * Math.sin(phi) * Math.cos(theta),
605
+ y: r * Math.sin(phi) * Math.sin(theta),
606
+ z: r * Math.cos(phi)
607
+ };
608
+ },
609
+ /**
610
+ * Random Vec3 on unit sphere surface
611
+ */
612
+ onUnitSphere: () => {
613
+ const theta = Math.random() * TAU;
614
+ const phi = Math.acos(2 * Math.random() - 1);
615
+ return {
616
+ x: Math.sin(phi) * Math.cos(theta),
617
+ y: Math.sin(phi) * Math.sin(theta),
618
+ z: Math.cos(phi)
619
+ };
620
+ },
621
+ /**
622
+ * Random Vec2 in unit circle
623
+ */
624
+ insideUnitCircle: () => {
625
+ const theta = Math.random() * TAU;
626
+ const r = Math.sqrt(Math.random());
627
+ return {
628
+ x: r * Math.cos(theta),
629
+ y: r * Math.sin(theta)
630
+ };
631
+ },
632
+ /**
633
+ * Seeded random number generator
634
+ */
635
+ seeded: (seed) => {
636
+ let s = seed;
637
+ return () => {
638
+ s = s * 1103515245 + 12345 & 2147483647;
639
+ return s / 2147483647;
640
+ };
641
+ }
642
+ };
643
+
644
+ export {
645
+ vec2,
646
+ vec3,
647
+ vec4,
648
+ quat,
649
+ transform,
650
+ rgb,
651
+ rgba,
652
+ hsl,
653
+ aabb,
654
+ ray,
655
+ vec3ToArray,
656
+ arrayToVec3,
657
+ quatToArray,
658
+ arrayToQuat,
659
+ parseColor,
660
+ colorToHex,
661
+ PI,
662
+ TAU,
663
+ HALF_PI,
664
+ DEG_TO_RAD,
665
+ RAD_TO_DEG,
666
+ EPSILON,
667
+ clamp,
668
+ lerp,
669
+ inverseLerp,
670
+ remap,
671
+ smoothstep,
672
+ smootherstep,
673
+ degToRad,
674
+ radToDeg,
675
+ mod,
676
+ fract,
677
+ sign,
678
+ step,
679
+ vec2Math,
680
+ vec3Math,
681
+ quatMath,
682
+ aabbMath,
683
+ noise,
684
+ random
685
+ };
686
+ //# sourceMappingURL=chunk-DZHAVOCH.js.map