@holoscript/std 2.1.0 → 6.0.3

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 (159) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE +21 -0
  3. package/README.md +197 -0
  4. package/dist/__tests__/EconomicPrimitives.test.d.ts +2 -0
  5. package/dist/__tests__/EconomicPrimitives.test.d.ts.map +1 -0
  6. package/dist/__tests__/EconomicTraits.test.d.ts +2 -0
  7. package/dist/__tests__/EconomicTraits.test.d.ts.map +1 -0
  8. package/dist/__tests__/SimulationLabPrimitives.test.d.ts +2 -0
  9. package/dist/__tests__/SimulationLabPrimitives.test.d.ts.map +1 -0
  10. package/dist/__tests__/collections.test.d.ts +2 -0
  11. package/dist/__tests__/collections.test.d.ts.map +1 -0
  12. package/dist/__tests__/events.test.d.ts +2 -0
  13. package/dist/__tests__/events.test.d.ts.map +1 -0
  14. package/dist/__tests__/index.test.d.ts +2 -0
  15. package/dist/__tests__/index.test.d.ts.map +1 -0
  16. package/dist/__tests__/materials.test.d.ts +2 -0
  17. package/dist/__tests__/materials.test.d.ts.map +1 -0
  18. package/dist/__tests__/math.test.d.ts +2 -0
  19. package/dist/__tests__/math.test.d.ts.map +1 -0
  20. package/dist/__tests__/physics.test.d.ts +2 -0
  21. package/dist/__tests__/physics.test.d.ts.map +1 -0
  22. package/dist/__tests__/spatial.test.d.ts +2 -0
  23. package/dist/__tests__/spatial.test.d.ts.map +1 -0
  24. package/dist/__tests__/standard-library-fundamentals.test.d.ts +2 -0
  25. package/dist/__tests__/standard-library-fundamentals.test.d.ts.map +1 -0
  26. package/dist/__tests__/string-and-time-utilities.test.d.ts +2 -0
  27. package/dist/__tests__/string-and-time-utilities.test.d.ts.map +1 -0
  28. package/dist/__tests__/string-decoupled.test.d.ts +2 -0
  29. package/dist/__tests__/string-decoupled.test.d.ts.map +1 -0
  30. package/dist/__tests__/string.test.d.ts +2 -0
  31. package/dist/__tests__/string.test.d.ts.map +1 -0
  32. package/dist/__tests__/time.test.d.ts +2 -0
  33. package/dist/__tests__/time.test.d.ts.map +1 -0
  34. package/dist/chunk-7HVUYGPS.js +679 -0
  35. package/dist/chunk-7HVUYGPS.js.map +1 -0
  36. package/dist/chunk-P4O3WNG2.js +287 -0
  37. package/dist/chunk-P4O3WNG2.js.map +1 -0
  38. package/dist/chunk-PFX2JM4X.js +683 -0
  39. package/dist/chunk-PFX2JM4X.js.map +1 -0
  40. package/dist/chunk-W2Q3LUCM.js +348 -0
  41. package/dist/chunk-W2Q3LUCM.js.map +1 -0
  42. package/dist/chunk-WS6W35YC.js +443 -0
  43. package/dist/chunk-WS6W35YC.js.map +1 -0
  44. package/dist/chunk-ZXVZAQCZ.js +470 -0
  45. package/dist/chunk-ZXVZAQCZ.js.map +1 -0
  46. package/dist/collections.cjs +715 -0
  47. package/dist/collections.cjs.map +1 -0
  48. package/dist/collections.d.ts.map +1 -1
  49. package/dist/collections.js +16 -719
  50. package/dist/collections.js.map +1 -1
  51. package/dist/events.d.ts +32 -0
  52. package/dist/events.d.ts.map +1 -0
  53. package/dist/index.cjs +4101 -0
  54. package/dist/index.cjs.map +1 -0
  55. package/dist/index.d.ts +21 -9
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +1270 -157
  58. package/dist/index.js.map +1 -1
  59. package/dist/materials.d.ts +50 -0
  60. package/dist/materials.d.ts.map +1 -0
  61. package/dist/math.cjs +591 -0
  62. package/dist/math.cjs.map +1 -0
  63. package/dist/math.d.ts.map +1 -1
  64. package/dist/math.js +51 -537
  65. package/dist/math.js.map +1 -1
  66. package/dist/physics.d.ts +59 -0
  67. package/dist/physics.d.ts.map +1 -0
  68. package/dist/spatial.d.ts +82 -0
  69. package/dist/spatial.d.ts.map +1 -0
  70. package/dist/string.basic.test.d.ts +5 -0
  71. package/dist/string.basic.test.d.ts.map +1 -0
  72. package/dist/string.cjs +422 -0
  73. package/dist/string.cjs.map +1 -0
  74. package/dist/string.d.ts +5 -1
  75. package/dist/string.d.ts.map +1 -1
  76. package/dist/string.js +106 -442
  77. package/dist/string.js.map +1 -1
  78. package/dist/string.test.d.ts +5 -0
  79. package/dist/string.test.d.ts.map +1 -0
  80. package/dist/time.cjs +512 -0
  81. package/dist/time.cjs.map +1 -0
  82. package/dist/time.d.ts.map +1 -1
  83. package/dist/time.js +41 -528
  84. package/dist/time.js.map +1 -1
  85. package/dist/traits/ARTraits.d.ts +14 -0
  86. package/dist/traits/ARTraits.d.ts.map +1 -0
  87. package/dist/traits/EconomicPrimitives.cjs +335 -0
  88. package/dist/traits/EconomicPrimitives.cjs.map +1 -0
  89. package/dist/traits/EconomicPrimitives.d.ts +345 -0
  90. package/dist/traits/EconomicPrimitives.d.ts.map +1 -0
  91. package/dist/traits/EconomicPrimitives.js +55 -0
  92. package/dist/traits/EconomicPrimitives.js.map +1 -0
  93. package/dist/traits/EconomicTraits.cjs +471 -0
  94. package/dist/traits/EconomicTraits.cjs.map +1 -0
  95. package/dist/traits/EconomicTraits.d.ts +71 -0
  96. package/dist/traits/EconomicTraits.d.ts.map +1 -0
  97. package/dist/traits/EconomicTraits.js +17 -0
  98. package/dist/traits/EconomicTraits.js.map +1 -0
  99. package/dist/traits/IoTTraits.d.ts +14 -0
  100. package/dist/traits/IoTTraits.d.ts.map +1 -0
  101. package/dist/traits/SimulationLabPrimitives.d.ts +187 -0
  102. package/dist/traits/SimulationLabPrimitives.d.ts.map +1 -0
  103. package/dist/traits/SimulationLabTraits.d.ts +42 -0
  104. package/dist/traits/SimulationLabTraits.d.ts.map +1 -0
  105. package/dist/traits/VRRTraits.d.ts +150 -0
  106. package/dist/traits/VRRTraits.d.ts.map +1 -0
  107. package/dist/traits/__tests__/ARTraits.test.d.ts +2 -0
  108. package/dist/traits/__tests__/ARTraits.test.d.ts.map +1 -0
  109. package/dist/traits/__tests__/EconomicPrimitives.test.d.ts +2 -0
  110. package/dist/traits/__tests__/EconomicPrimitives.test.d.ts.map +1 -0
  111. package/dist/traits/__tests__/EconomicTraits.test.d.ts +2 -0
  112. package/dist/traits/__tests__/EconomicTraits.test.d.ts.map +1 -0
  113. package/dist/types.d.ts +9 -0
  114. package/dist/types.d.ts.map +1 -1
  115. package/error-utf8.log +6 -0
  116. package/error.log +0 -0
  117. package/package.json +42 -19
  118. package/src/__tests__/EconomicPrimitives.test.ts +690 -0
  119. package/src/__tests__/EconomicTraits.test.ts +425 -0
  120. package/src/__tests__/SimulationLabPrimitives.test.ts +415 -0
  121. package/src/__tests__/collections.test.ts +182 -0
  122. package/src/__tests__/events.test.ts +135 -0
  123. package/src/__tests__/index.test.ts +14 -0
  124. package/src/__tests__/materials.test.ts +84 -0
  125. package/src/__tests__/math.test.ts +246 -0
  126. package/src/__tests__/physics.test.ts +83 -0
  127. package/src/__tests__/spatial.test.ts +333 -0
  128. package/src/__tests__/standard-library-fundamentals.test.ts +1301 -0
  129. package/src/__tests__/string-and-time-utilities.test.ts +1070 -0
  130. package/src/__tests__/string-decoupled.test.ts +14 -0
  131. package/src/__tests__/string.test.ts +164 -0
  132. package/src/__tests__/time.test.ts +110 -0
  133. package/src/collections.ts +8 -2
  134. package/src/events.ts +88 -0
  135. package/src/index.ts +161 -11
  136. package/src/materials.ts +109 -0
  137. package/src/math.ts +30 -14
  138. package/src/physics.ts +141 -0
  139. package/src/spatial.ts +320 -0
  140. package/src/string.basic.test.ts +14 -0
  141. package/src/string.test.ts +335 -0
  142. package/src/string.ts +45 -13
  143. package/src/time.ts +10 -11
  144. package/src/traits/ARTraits.ts +103 -0
  145. package/src/traits/EconomicPrimitives.ts +755 -0
  146. package/src/traits/EconomicTraits.ts +552 -0
  147. package/src/traits/IoTTraits.ts +102 -0
  148. package/src/traits/SimulationLabPrimitives.ts +650 -0
  149. package/src/traits/SimulationLabTraits.ts +191 -0
  150. package/src/traits/VRRTraits.ts +326 -0
  151. package/src/traits/__tests__/ARTraits.test.ts +14 -0
  152. package/src/traits/__tests__/EconomicPrimitives.test.ts +14 -0
  153. package/src/traits/__tests__/EconomicTraits.test.ts +14 -0
  154. package/src/types.ts +47 -12
  155. package/std_error.log +5 -0
  156. package/tsup.config.ts +17 -0
  157. package/vitest.config.ts +10 -0
  158. package/dist/types.js +0 -198
  159. package/dist/types.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,177 +1,1290 @@
1
- /**
2
- * @holoscript/std - Standard Library for HoloScript Plus
3
- *
4
- * Provides core types, math utilities, collections, string operations,
5
- * and time management for HoloScript Plus programs.
6
- *
7
- * @example
8
- * ```hsplus
9
- * import { Vec3, List, sleep } from "@holoscript/std";
10
- *
11
- * let position = Vec3(0, 1, 0);
12
- * let items = List.of(1, 2, 3).map(n => n * 2);
13
- *
14
- * async fn main() {
15
- * await sleep(1000);
16
- * print("Done!");
17
- * }
18
- * ```
19
- */
20
- // Re-export everything from types.js
21
- export * from './types.js';
22
- // Math utilities - export objects from math.ts
23
- export {
24
- // Constants
25
- PI, TAU, HALF_PI, EPSILON, DEG_TO_RAD, RAD_TO_DEG,
26
- // Basic math functions
27
- clamp, lerp, inverseLerp, remap, smoothstep, smootherstep, sign, fract, mod, step, degToRad, radToDeg,
28
- // Math utility objects (access methods like vec2Math.add(), vec3Math.cross(), etc.)
29
- vec2Math, vec3Math, quatMath, aabbMath, noise, random, } from './math.js';
30
- // Re-export with alternate names for convenience
31
- export { degToRad as toRadians, radToDeg as toDegrees } from './math.js';
32
- // Collections
33
- export { List, HoloMap, HoloSet, HoloMap as Map, HoloSet as Set, SpatialGrid, PriorityQueue, } from './collections.js';
34
- // String utilities
35
- export { isBlank, isNotBlank, capitalize, titleCase, camelCase, pascalCase, snakeCase, kebabCase, constantCase, padLeft, padRight, center, truncate, truncateMiddle, repeat, reverse, count, containsIgnoreCase, startsWithIgnoreCase, endsWithIgnoreCase, removeWhitespace, collapseWhitespace, removePrefix, removeSuffix, wrap as wrapString, unwrap, lines, words, chars, join, format, formatNumber, numberWithCommas, formatBytes, formatDuration, escapeHtml, unescapeHtml, escapeRegex, slugify, isValidIdentifier, isNumeric, isAlphanumeric, isAlpha, randomString, uuid, indent, dedent, wordWrap, levenshtein, similarity, } from './string.js';
36
- // Time utilities
37
- export { now, hrTime, sleep, waitUntil, withTimeout, retry, debounce, throttle, measure, timed, Stopwatch, IntervalTimer, CountdownTimer, FrameTimer, schedule, scheduleInterval, scheduleFrame, createTicker, DateTime, } from './time.js';
38
- /**
39
- * Print to console (HoloScript standard output)
40
- */
41
- export function print(...args) {
42
- console.log(...args);
43
- }
44
- /**
45
- * Print error to console
46
- */
47
- export function printError(...args) {
48
- console.error(...args);
49
- }
50
- /**
51
- * Print warning to console
52
- */
53
- export function printWarn(...args) {
54
- console.warn(...args);
55
- }
56
- /**
57
- * Assert a condition is true
58
- */
59
- export function assert(condition, message) {
60
- if (!condition) {
61
- throw new Error(message ?? 'Assertion failed');
1
+ import {
2
+ HoloMap,
3
+ HoloSet,
4
+ List,
5
+ PriorityQueue,
6
+ SpatialGrid
7
+ } from "./chunk-PFX2JM4X.js";
8
+ import {
9
+ DEG_TO_RAD,
10
+ EPSILON,
11
+ HALF_PI,
12
+ PI,
13
+ RAD_TO_DEG,
14
+ TAU,
15
+ aabb,
16
+ aabbMath,
17
+ arrayToQuat,
18
+ arrayToVec3,
19
+ clamp,
20
+ colorToHex,
21
+ degToRad,
22
+ fract,
23
+ hsl,
24
+ inverseLerp,
25
+ lerp,
26
+ mod,
27
+ noise,
28
+ parseColor,
29
+ quat,
30
+ quatMath,
31
+ quatToArray,
32
+ radToDeg,
33
+ random,
34
+ ray,
35
+ remap,
36
+ rgb,
37
+ rgba,
38
+ sign,
39
+ smootherstep,
40
+ smoothstep,
41
+ step,
42
+ transform,
43
+ vec2,
44
+ vec2Math,
45
+ vec3,
46
+ vec3Math,
47
+ vec3ToArray,
48
+ vec4
49
+ } from "./chunk-7HVUYGPS.js";
50
+ import {
51
+ camelCase,
52
+ capitalize,
53
+ center,
54
+ chars,
55
+ collapseWhitespace,
56
+ constantCase,
57
+ containsIgnoreCase,
58
+ count,
59
+ dedent,
60
+ endsWithIgnoreCase,
61
+ escapeHtml,
62
+ escapeRegex,
63
+ extractTraits,
64
+ format,
65
+ formatBytes,
66
+ formatDuration,
67
+ formatNumber,
68
+ indent,
69
+ isAlpha,
70
+ isAlphanumeric,
71
+ isBlank,
72
+ isNotBlank,
73
+ isNumeric,
74
+ isValidIdentifier,
75
+ join,
76
+ kebabCase,
77
+ levenshtein,
78
+ lines,
79
+ numberWithCommas,
80
+ padLeft,
81
+ padRight,
82
+ pascalCase,
83
+ randomString,
84
+ removePrefix,
85
+ removeSuffix,
86
+ removeWhitespace,
87
+ repeat,
88
+ reverse,
89
+ similarity,
90
+ slugify,
91
+ snakeCase,
92
+ startsWithIgnoreCase,
93
+ titleCase,
94
+ truncate,
95
+ truncateMiddle,
96
+ unescapeHtml,
97
+ unwrap,
98
+ uuid,
99
+ wordWrap,
100
+ words,
101
+ wrap
102
+ } from "./chunk-W2Q3LUCM.js";
103
+ import {
104
+ CountdownTimer,
105
+ DateTime,
106
+ FrameTimer,
107
+ IntervalTimer,
108
+ Stopwatch,
109
+ createTicker,
110
+ debounce,
111
+ hrTime,
112
+ measure,
113
+ now,
114
+ retry,
115
+ schedule,
116
+ scheduleFrame,
117
+ scheduleInterval,
118
+ sleep,
119
+ throttle,
120
+ timed,
121
+ waitUntil,
122
+ withTimeout
123
+ } from "./chunk-ZXVZAQCZ.js";
124
+ import {
125
+ DEFAULT_BONDING_CURVE,
126
+ DEFAULT_DEPRECIATION,
127
+ DEFAULT_PID,
128
+ DEFAULT_WEALTH_TAX,
129
+ bondingCurveBuyCost,
130
+ bondingCurvePrice,
131
+ bondingCurveSellRefund,
132
+ calculateDepreciation,
133
+ calculateRedistribution,
134
+ calculateRepairCost,
135
+ calculateTaxAmount,
136
+ calculateTaxRate,
137
+ createDualLoopPIDState,
138
+ createFaucetSinkMetrics,
139
+ createPIDState,
140
+ depreciatedValue,
141
+ executeTrade,
142
+ generateTxHash,
143
+ isDestroyed,
144
+ recordFaucet,
145
+ recordSink,
146
+ resetMetricsPeriod,
147
+ spatialPrice,
148
+ updateDualLoopPID,
149
+ updatePID
150
+ } from "./chunk-P4O3WNG2.js";
151
+ import {
152
+ EconomicTraits,
153
+ getEconomicTrait,
154
+ getEconomicTraitNames,
155
+ getRequiredPermissions,
156
+ validateTraitComposition
157
+ } from "./chunk-WS6W35YC.js";
158
+
159
+ // src/spatial.ts
160
+ var Vec3 = class _Vec3 {
161
+ constructor(x = 0, y = 0, z = 0) {
162
+ this.x = x;
163
+ this.y = y;
164
+ this.z = z;
165
+ }
166
+ static zero() {
167
+ return new _Vec3(0, 0, 0);
168
+ }
169
+ static one() {
170
+ return new _Vec3(1, 1, 1);
171
+ }
172
+ static up() {
173
+ return new _Vec3(0, 1, 0);
174
+ }
175
+ static down() {
176
+ return new _Vec3(0, -1, 0);
177
+ }
178
+ static forward() {
179
+ return new _Vec3(0, 0, -1);
180
+ }
181
+ static right() {
182
+ return new _Vec3(1, 0, 0);
183
+ }
184
+ add(other) {
185
+ return new _Vec3(this.x + other.x, this.y + other.y, this.z + other.z);
186
+ }
187
+ sub(other) {
188
+ return new _Vec3(this.x - other.x, this.y - other.y, this.z - other.z);
189
+ }
190
+ mul(s) {
191
+ return new _Vec3(this.x * s, this.y * s, this.z * s);
192
+ }
193
+ div(s) {
194
+ return new _Vec3(this.x / s, this.y / s, this.z / s);
195
+ }
196
+ dot(other) {
197
+ return this.x * other.x + this.y * other.y + this.z * other.z;
198
+ }
199
+ cross(other) {
200
+ return new _Vec3(
201
+ this.y * other.z - this.z * other.y,
202
+ this.z * other.x - this.x * other.z,
203
+ this.x * other.y - this.y * other.x
204
+ );
205
+ }
206
+ length() {
207
+ return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
208
+ }
209
+ lengthSquared() {
210
+ return this.x * this.x + this.y * this.y + this.z * this.z;
211
+ }
212
+ normalize() {
213
+ const l = this.length();
214
+ return l > 0 ? this.div(l) : _Vec3.zero();
215
+ }
216
+ distanceTo(other) {
217
+ return this.sub(other).length();
218
+ }
219
+ lerp(other, t) {
220
+ return this.add(other.sub(this).mul(t));
221
+ }
222
+ toArray() {
223
+ return [this.x, this.y, this.z];
224
+ }
225
+ static fromArray(arr) {
226
+ return new _Vec3(arr[0] || 0, arr[1] || 0, arr[2] || 0);
227
+ }
228
+ equals(other, epsilon = 1e-6) {
229
+ return Math.abs(this.x - other.x) < epsilon && Math.abs(this.y - other.y) < epsilon && Math.abs(this.z - other.z) < epsilon;
230
+ }
231
+ toString() {
232
+ return `Vec3(${this.x}, ${this.y}, ${this.z})`;
233
+ }
234
+ };
235
+ var Quaternion = class _Quaternion {
236
+ constructor(x = 0, y = 0, z = 0, w = 1) {
237
+ this.x = x;
238
+ this.y = y;
239
+ this.z = z;
240
+ this.w = w;
241
+ }
242
+ static identity() {
243
+ return new _Quaternion(0, 0, 0, 1);
244
+ }
245
+ static fromEuler(x, y, z) {
246
+ const cx = Math.cos(x * 0.5), sx = Math.sin(x * 0.5);
247
+ const cy = Math.cos(y * 0.5), sy = Math.sin(y * 0.5);
248
+ const cz = Math.cos(z * 0.5), sz = Math.sin(z * 0.5);
249
+ return new _Quaternion(
250
+ sx * cy * cz - cx * sy * sz,
251
+ cx * sy * cz + sx * cy * sz,
252
+ cx * cy * sz - sx * sy * cz,
253
+ cx * cy * cz + sx * sy * sz
254
+ );
255
+ }
256
+ static fromAxisAngle(axis, angle) {
257
+ const half = angle * 0.5;
258
+ const s = Math.sin(half);
259
+ const n = axis.normalize();
260
+ return new _Quaternion(n.x * s, n.y * s, n.z * s, Math.cos(half));
261
+ }
262
+ multiply(other) {
263
+ return new _Quaternion(
264
+ this.w * other.x + this.x * other.w + this.y * other.z - this.z * other.y,
265
+ this.w * other.y - this.x * other.z + this.y * other.w + this.z * other.x,
266
+ this.w * other.z + this.x * other.y - this.y * other.x + this.z * other.w,
267
+ this.w * other.w - this.x * other.x - this.y * other.y - this.z * other.z
268
+ );
269
+ }
270
+ rotateVec3(v) {
271
+ const u = new Vec3(this.x, this.y, this.z);
272
+ const s = this.w;
273
+ return u.mul(2 * u.dot(v)).add(v.mul(s * s - u.dot(u))).add(u.cross(v).mul(2 * s));
274
+ }
275
+ slerp(other, t) {
276
+ let dot = this.x * other.x + this.y * other.y + this.z * other.z + this.w * other.w;
277
+ const neg = dot < 0;
278
+ if (neg) dot = -dot;
279
+ if (dot > 0.9995) {
280
+ const r = new _Quaternion(
281
+ this.x + t * ((neg ? -other.x : other.x) - this.x),
282
+ this.y + t * ((neg ? -other.y : other.y) - this.y),
283
+ this.z + t * ((neg ? -other.z : other.z) - this.z),
284
+ this.w + t * ((neg ? -other.w : other.w) - this.w)
285
+ );
286
+ const len = Math.sqrt(r.x * r.x + r.y * r.y + r.z * r.z + r.w * r.w);
287
+ return new _Quaternion(r.x / len, r.y / len, r.z / len, r.w / len);
62
288
  }
289
+ const theta = Math.acos(dot);
290
+ const sinTheta = Math.sin(theta);
291
+ const a = Math.sin((1 - t) * theta) / sinTheta;
292
+ const b = Math.sin(t * theta) / sinTheta * (neg ? -1 : 1);
293
+ return new _Quaternion(
294
+ a * this.x + b * other.x,
295
+ a * this.y + b * other.y,
296
+ a * this.z + b * other.z,
297
+ a * this.w + b * other.w
298
+ );
299
+ }
300
+ normalize() {
301
+ const len = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
302
+ return new _Quaternion(this.x / len, this.y / len, this.z / len, this.w / len);
303
+ }
304
+ toEuler() {
305
+ const sinr = 2 * (this.w * this.x + this.y * this.z);
306
+ const cosr = 1 - 2 * (this.x * this.x + this.y * this.y);
307
+ const sinp = 2 * (this.w * this.y - this.z * this.x);
308
+ const siny = 2 * (this.w * this.z + this.x * this.y);
309
+ const cosy = 1 - 2 * (this.y * this.y + this.z * this.z);
310
+ return new Vec3(
311
+ Math.atan2(sinr, cosr),
312
+ Math.abs(sinp) >= 1 ? Math.sign(sinp) * Math.PI / 2 : Math.asin(sinp),
313
+ Math.atan2(siny, cosy)
314
+ );
315
+ }
316
+ };
317
+ var Transform = class _Transform {
318
+ constructor(position = Vec3.zero(), rotation = Quaternion.identity(), scale = Vec3.one()) {
319
+ this.position = position;
320
+ this.rotation = rotation;
321
+ this.scale = scale;
322
+ }
323
+ static identity() {
324
+ return new _Transform();
325
+ }
326
+ transformPoint(point) {
327
+ const scaled = new Vec3(point.x * this.scale.x, point.y * this.scale.y, point.z * this.scale.z);
328
+ return this.rotation.rotateVec3(scaled).add(this.position);
329
+ }
330
+ transformDirection(dir) {
331
+ return this.rotation.rotateVec3(dir);
332
+ }
333
+ };
334
+ var Ray = class {
335
+ constructor(origin, direction) {
336
+ this.origin = origin;
337
+ this.direction = direction;
338
+ }
339
+ pointAt(t) {
340
+ return this.origin.add(this.direction.mul(t));
341
+ }
342
+ };
343
+ var AABB = class {
344
+ constructor(min, max) {
345
+ this.min = min;
346
+ this.max = max;
347
+ }
348
+ contains(point) {
349
+ return point.x >= this.min.x && point.x <= this.max.x && point.y >= this.min.y && point.y <= this.max.y && point.z >= this.min.z && point.z <= this.max.z;
350
+ }
351
+ intersects(other) {
352
+ return this.min.x <= other.max.x && this.max.x >= other.min.x && this.min.y <= other.max.y && this.max.y >= other.min.y && this.min.z <= other.max.z && this.max.z >= other.min.z;
353
+ }
354
+ center() {
355
+ return this.min.add(this.max).div(2);
356
+ }
357
+ size() {
358
+ return this.max.sub(this.min);
359
+ }
360
+ intersectsRay(ray2) {
361
+ let tmin = (this.min.x - ray2.origin.x) / ray2.direction.x;
362
+ let tmax = (this.max.x - ray2.origin.x) / ray2.direction.x;
363
+ if (tmin > tmax) [tmin, tmax] = [tmax, tmin];
364
+ let tymin = (this.min.y - ray2.origin.y) / ray2.direction.y;
365
+ let tymax = (this.max.y - ray2.origin.y) / ray2.direction.y;
366
+ if (tymin > tymax) [tymin, tymax] = [tymax, tymin];
367
+ if (tmin > tymax || tymin > tmax) return null;
368
+ tmin = Math.max(tmin, tymin);
369
+ tmax = Math.min(tmax, tymax);
370
+ let tzmin = (this.min.z - ray2.origin.z) / ray2.direction.z;
371
+ let tzmax = (this.max.z - ray2.origin.z) / ray2.direction.z;
372
+ if (tzmin > tzmax) [tzmin, tzmax] = [tzmax, tzmin];
373
+ if (tmin > tzmax || tzmin > tmax) return null;
374
+ return Math.max(tmin, tzmin);
375
+ }
376
+ };
377
+ function distance(a, b) {
378
+ return a.distanceTo(b);
63
379
  }
64
- /**
65
- * Assert a value is not null or undefined
66
- */
67
- export function assertDefined(value, message) {
68
- if (value === null || value === undefined) {
69
- throw new Error(message ?? 'Value is null or undefined');
70
- }
380
+ function lerp2(a, b, t) {
381
+ return a + (b - a) * t;
71
382
  }
72
- /**
73
- * Unreachable code marker (for exhaustiveness checking)
74
- */
75
- export function unreachable(message) {
76
- throw new Error(message ?? 'Unreachable code reached');
77
- }
78
- /**
79
- * Todo marker (throws at runtime)
80
- */
81
- export function todo(message) {
82
- throw new Error(`TODO: ${message ?? 'Not implemented'}`);
83
- }
84
- /**
85
- * Deep clone an object
86
- */
87
- export function clone(value) {
88
- if (value === null || typeof value !== 'object') {
89
- return value;
90
- }
91
- if (Array.isArray(value)) {
92
- return value.map(clone);
93
- }
94
- if (value instanceof Date) {
95
- return new Date(value.getTime());
383
+ function clamp2(v, min, max) {
384
+ return Math.min(Math.max(v, min), max);
385
+ }
386
+ function degToRad2(deg) {
387
+ return deg * (Math.PI / 180);
388
+ }
389
+ function radToDeg2(rad) {
390
+ return rad * (180 / Math.PI);
391
+ }
392
+
393
+ // src/physics.ts
394
+ function createBoxCollider(halfExtents, options) {
395
+ return {
396
+ shape: "box",
397
+ isTrigger: false,
398
+ friction: 0.5,
399
+ restitution: 0,
400
+ halfExtents,
401
+ ...options
402
+ };
403
+ }
404
+ function createSphereCollider(radius, options) {
405
+ return { shape: "sphere", isTrigger: false, friction: 0.5, restitution: 0, radius, ...options };
406
+ }
407
+ function createCapsuleCollider(radius, height, options) {
408
+ return {
409
+ shape: "capsule",
410
+ isTrigger: false,
411
+ friction: 0.5,
412
+ restitution: 0,
413
+ radius,
414
+ height,
415
+ ...options
416
+ };
417
+ }
418
+ function createRigidbody(mass, options) {
419
+ return {
420
+ mass,
421
+ useGravity: true,
422
+ linearDamping: 0,
423
+ angularDamping: 0.05,
424
+ freezePosition: [false, false, false],
425
+ freezeRotation: [false, false, false],
426
+ isKinematic: false,
427
+ ...options
428
+ };
429
+ }
430
+
431
+ // src/materials.ts
432
+ var MATERIAL_PRESETS = {
433
+ metal: { roughness: 0.2, metallic: 1 },
434
+ wood: { roughness: 0.85, metallic: 0, baseColor: "#8B6914" },
435
+ glass: { roughness: 0.05, metallic: 0, opacity: 0.3, ior: 1.5 },
436
+ plastic: { roughness: 0.4, metallic: 0 },
437
+ concrete: { roughness: 0.95, metallic: 0, baseColor: "#808080" },
438
+ fabric: { roughness: 0.9, metallic: 0, subsurface: 0.2 },
439
+ water: { roughness: 0.05, metallic: 0, opacity: 0.7, ior: 1.33 },
440
+ rubber: { roughness: 0.95, metallic: 0, baseColor: "#222222" },
441
+ marble: { roughness: 0.3, metallic: 0, baseColor: "#f0f0f0" },
442
+ skin: { roughness: 0.6, metallic: 0, subsurface: 0.5 },
443
+ foliage: { roughness: 0.8, metallic: 0, baseColor: "#2d5a27", subsurface: 0.3 },
444
+ chrome: { roughness: 0.05, metallic: 1, baseColor: "#cccccc" },
445
+ gold: { roughness: 0.2, metallic: 1, baseColor: "#ffd700" },
446
+ copper: { roughness: 0.3, metallic: 1, baseColor: "#b87333" },
447
+ ice: { roughness: 0.1, metallic: 0, opacity: 0.8, ior: 1.31 }
448
+ };
449
+ function createPBRMaterial(name, preset, overrides) {
450
+ const base = preset ? MATERIAL_PRESETS[preset] : {};
451
+ return {
452
+ name,
453
+ baseColor: "#ffffff",
454
+ roughness: 0.5,
455
+ metallic: 0,
456
+ ...base,
457
+ ...overrides
458
+ };
459
+ }
460
+
461
+ // src/events.ts
462
+ var EventBus = class {
463
+ listeners = /* @__PURE__ */ new Map();
464
+ wildcardListeners = [];
465
+ /** Register an event listener. */
466
+ on(event, handler) {
467
+ if (!this.listeners.has(event)) this.listeners.set(event, []);
468
+ const listener = { handler, once: false };
469
+ this.listeners.get(event).push(listener);
470
+ return () => this.off(event, handler);
471
+ }
472
+ /** Register a one-time event listener. */
473
+ once(event, handler) {
474
+ if (!this.listeners.has(event)) this.listeners.set(event, []);
475
+ const listener = { handler, once: true };
476
+ this.listeners.get(event).push(listener);
477
+ return () => this.off(event, handler);
478
+ }
479
+ /** Remove an event listener. */
480
+ off(event, handler) {
481
+ const list = this.listeners.get(event);
482
+ if (!list) return;
483
+ this.listeners.set(
484
+ event,
485
+ list.filter((l) => l.handler !== handler)
486
+ );
487
+ }
488
+ /** Emit an event to all registered listeners. */
489
+ emit(event, data) {
490
+ const list = this.listeners.get(event);
491
+ if (list) {
492
+ const remaining = [];
493
+ for (const l of list) {
494
+ l.handler(data);
495
+ if (!l.once) remaining.push(l);
496
+ }
497
+ this.listeners.set(event, remaining);
96
498
  }
97
- if (value instanceof Map) {
98
- return new Map([...value].map(([k, v]) => [clone(k), clone(v)]));
499
+ for (const l of this.wildcardListeners) {
500
+ l.handler({ event, data });
99
501
  }
100
- if (value instanceof Set) {
101
- return new Set([...value].map(clone));
502
+ }
503
+ /** Listen to all events. */
504
+ onAny(handler) {
505
+ const listener = { handler, once: false };
506
+ this.wildcardListeners.push(listener);
507
+ return () => {
508
+ this.wildcardListeners = this.wildcardListeners.filter((l) => l !== listener);
509
+ };
510
+ }
511
+ /** Remove all listeners. */
512
+ clear() {
513
+ this.listeners.clear();
514
+ this.wildcardListeners = [];
515
+ }
516
+ /** Get count of listeners for an event (or all events). */
517
+ listenerCount(event) {
518
+ if (event) return (this.listeners.get(event) || []).length;
519
+ let total = this.wildcardListeners.length;
520
+ for (const [, list] of this.listeners) total += list.length;
521
+ return total;
522
+ }
523
+ };
524
+
525
+ // src/traits/SimulationLabPrimitives.ts
526
+ function isParameterRange(sweep) {
527
+ return "min" in sweep && "max" in sweep && "step" in sweep;
528
+ }
529
+ function expandSweep(sweep) {
530
+ if (!isParameterRange(sweep)) {
531
+ return sweep.values.slice();
532
+ }
533
+ const range = sweep;
534
+ if (range.step <= 0) return [range.min];
535
+ if (range.min > range.max) return [];
536
+ const values = [];
537
+ for (let v = range.min; v <= range.max + range.step * 1e-3; v += range.step) {
538
+ values.push(Math.round(v * 1e10) / 1e10);
539
+ }
540
+ return values;
541
+ }
542
+ function generateSweepCombinations(sweeps) {
543
+ if (sweeps.length === 0) return [{}];
544
+ const expanded = sweeps.map((s) => ({
545
+ name: s.name,
546
+ values: expandSweep(s)
547
+ }));
548
+ let combinations = [{}];
549
+ for (const { name, values } of expanded) {
550
+ const newCombinations = [];
551
+ for (const combo of combinations) {
552
+ for (const val of values) {
553
+ newCombinations.push({ ...combo, [name]: val });
554
+ }
102
555
  }
103
- const result = {};
104
- for (const key in value) {
105
- if (Object.prototype.hasOwnProperty.call(value, key)) {
106
- result[key] = clone(value[key]);
107
- }
556
+ combinations = newCombinations;
557
+ }
558
+ return combinations;
559
+ }
560
+ function mean(data) {
561
+ if (data.length === 0) return 0;
562
+ return data.reduce((sum, v) => sum + v, 0) / data.length;
563
+ }
564
+ function variance(data) {
565
+ if (data.length < 2) return 0;
566
+ const m = mean(data);
567
+ const squaredDiffs = data.reduce((sum, v) => sum + (v - m) ** 2, 0);
568
+ return squaredDiffs / (data.length - 1);
569
+ }
570
+ function standardDeviation(data) {
571
+ return Math.sqrt(variance(data));
572
+ }
573
+ function standardError(data) {
574
+ if (data.length === 0) return 0;
575
+ return standardDeviation(data) / Math.sqrt(data.length);
576
+ }
577
+ function cohensD(group1, group2) {
578
+ if (group1.length < 2 || group2.length < 2) return 0;
579
+ const m1 = mean(group1);
580
+ const m2 = mean(group2);
581
+ const v1 = variance(group1);
582
+ const v2 = variance(group2);
583
+ const n1 = group1.length;
584
+ const n2 = group2.length;
585
+ const pooledVar = ((n1 - 1) * v1 + (n2 - 1) * v2) / (n1 + n2 - 2);
586
+ const pooledStd = Math.sqrt(pooledVar);
587
+ if (pooledStd === 0) return 0;
588
+ return (m1 - m2) / pooledStd;
589
+ }
590
+ function tTest(group1, group2, alpha = 0.05, direction = "different") {
591
+ const n1 = group1.length;
592
+ const n2 = group2.length;
593
+ if (n1 < 2 || n2 < 2) {
594
+ return {
595
+ statistic: 0,
596
+ pValue: 1,
597
+ significant: false,
598
+ confidenceInterval: [0, 0],
599
+ effectSize: 0,
600
+ testName: "welch_t_test",
601
+ sampleSize: n1 + n2
602
+ };
603
+ }
604
+ const m1 = mean(group1);
605
+ const m2 = mean(group2);
606
+ const v1 = variance(group1);
607
+ const v2 = variance(group2);
608
+ const se = Math.sqrt(v1 / n1 + v2 / n2);
609
+ if (se === 0) {
610
+ return {
611
+ statistic: 0,
612
+ pValue: m1 === m2 ? 1 : 0,
613
+ significant: m1 !== m2,
614
+ confidenceInterval: [m1 - m2, m1 - m2],
615
+ effectSize: 0,
616
+ testName: "welch_t_test",
617
+ sampleSize: n1 + n2
618
+ };
619
+ }
620
+ const t = (m1 - m2) / se;
621
+ const num = (v1 / n1 + v2 / n2) ** 2;
622
+ const den = (v1 / n1) ** 2 / (n1 - 1) + (v2 / n2) ** 2 / (n2 - 1);
623
+ const df = num / den;
624
+ const pTwoTailed = tDistPValue(Math.abs(t), df);
625
+ let pValue;
626
+ switch (direction) {
627
+ case "greater":
628
+ pValue = t > 0 ? pTwoTailed / 2 : 1 - pTwoTailed / 2;
629
+ break;
630
+ case "less":
631
+ pValue = t < 0 ? pTwoTailed / 2 : 1 - pTwoTailed / 2;
632
+ break;
633
+ case "equal":
634
+ pValue = 1 - pTwoTailed;
635
+ break;
636
+ default:
637
+ pValue = pTwoTailed;
638
+ }
639
+ const tCrit = tDistCritical(alpha, df);
640
+ const diff = m1 - m2;
641
+ const ci = [diff - tCrit * se, diff + tCrit * se];
642
+ return {
643
+ statistic: t,
644
+ pValue,
645
+ significant: pValue < alpha,
646
+ confidenceInterval: ci,
647
+ effectSize: cohensD(group1, group2),
648
+ testName: "welch_t_test",
649
+ sampleSize: n1 + n2
650
+ };
651
+ }
652
+ function oneSampleTTest(data, populationMean, alpha = 0.05, direction = "different") {
653
+ const n = data.length;
654
+ if (n < 2) {
655
+ return {
656
+ statistic: 0,
657
+ pValue: 1,
658
+ significant: false,
659
+ confidenceInterval: [0, 0],
660
+ effectSize: 0,
661
+ testName: "one_sample_t_test",
662
+ sampleSize: n
663
+ };
664
+ }
665
+ const m = mean(data);
666
+ const se = standardError(data);
667
+ if (se === 0) {
668
+ return {
669
+ statistic: 0,
670
+ pValue: m === populationMean ? 1 : 0,
671
+ significant: m !== populationMean,
672
+ confidenceInterval: [m, m],
673
+ effectSize: 0,
674
+ testName: "one_sample_t_test",
675
+ sampleSize: n
676
+ };
677
+ }
678
+ const t = (m - populationMean) / se;
679
+ const df = n - 1;
680
+ const pTwoTailed = tDistPValue(Math.abs(t), df);
681
+ let pValue;
682
+ switch (direction) {
683
+ case "greater":
684
+ pValue = t > 0 ? pTwoTailed / 2 : 1 - pTwoTailed / 2;
685
+ break;
686
+ case "less":
687
+ pValue = t < 0 ? pTwoTailed / 2 : 1 - pTwoTailed / 2;
688
+ break;
689
+ default:
690
+ pValue = pTwoTailed;
691
+ }
692
+ const tCrit = tDistCritical(alpha, df);
693
+ const ci = [m - tCrit * se, m + tCrit * se];
694
+ const sd = standardDeviation(data);
695
+ const effectSize = sd > 0 ? (m - populationMean) / sd : 0;
696
+ return {
697
+ statistic: t,
698
+ pValue,
699
+ significant: pValue < alpha,
700
+ confidenceInterval: ci,
701
+ effectSize,
702
+ testName: "one_sample_t_test",
703
+ sampleSize: n
704
+ };
705
+ }
706
+ function mannWhitneyU(group1, group2, alpha = 0.05) {
707
+ const n1 = group1.length;
708
+ const n2 = group2.length;
709
+ if (n1 === 0 || n2 === 0) {
710
+ return {
711
+ statistic: 0,
712
+ pValue: 1,
713
+ significant: false,
714
+ confidenceInterval: [0, 0],
715
+ effectSize: 0,
716
+ testName: "mann_whitney_u",
717
+ sampleSize: n1 + n2
718
+ };
719
+ }
720
+ let u1 = 0;
721
+ for (const a of group1) {
722
+ for (const b of group2) {
723
+ if (a > b) u1++;
724
+ else if (a === b) u1 += 0.5;
108
725
  }
109
- return result;
110
- }
111
- /**
112
- * Deep equality check
113
- */
114
- export function equals(a, b) {
115
- if (a === b)
116
- return true;
117
- if (a === null || b === null)
726
+ }
727
+ const u2 = n1 * n2 - u1;
728
+ const u = Math.min(u1, u2);
729
+ const meanU = n1 * n2 / 2;
730
+ const sigmaU = Math.sqrt(n1 * n2 * (n1 + n2 + 1) / 12);
731
+ if (sigmaU === 0) {
732
+ return {
733
+ statistic: u,
734
+ pValue: 1,
735
+ significant: false,
736
+ confidenceInterval: [0, 0],
737
+ effectSize: 0,
738
+ testName: "mann_whitney_u",
739
+ sampleSize: n1 + n2
740
+ };
741
+ }
742
+ const z = (u - meanU) / sigmaU;
743
+ const pValue = 2 * normalCDF(-Math.abs(z));
744
+ const effectSize = 1 - 2 * u / (n1 * n2);
745
+ return {
746
+ statistic: u,
747
+ pValue,
748
+ significant: pValue < alpha,
749
+ confidenceInterval: [0, 0],
750
+ // CI not standard for U-test
751
+ effectSize,
752
+ testName: "mann_whitney_u",
753
+ sampleSize: n1 + n2
754
+ };
755
+ }
756
+ function chiSquaredTest(observed, expected, alpha = 0.05) {
757
+ if (observed.length !== expected.length || observed.length === 0) {
758
+ return {
759
+ statistic: 0,
760
+ pValue: 1,
761
+ significant: false,
762
+ confidenceInterval: [0, 0],
763
+ effectSize: 0,
764
+ testName: "chi_squared",
765
+ sampleSize: 0
766
+ };
767
+ }
768
+ let chiSq = 0;
769
+ let totalObserved = 0;
770
+ for (let i = 0; i < observed.length; i++) {
771
+ if (expected[i] <= 0) continue;
772
+ chiSq += (observed[i] - expected[i]) ** 2 / expected[i];
773
+ totalObserved += observed[i];
774
+ }
775
+ const df = observed.length - 1;
776
+ if (df <= 0) {
777
+ return {
778
+ statistic: chiSq,
779
+ pValue: 1,
780
+ significant: false,
781
+ confidenceInterval: [0, 0],
782
+ effectSize: 0,
783
+ testName: "chi_squared",
784
+ sampleSize: totalObserved
785
+ };
786
+ }
787
+ const pValue = chiSquaredPValue(chiSq, df);
788
+ const k = observed.length;
789
+ const effectSize = totalObserved > 0 ? Math.sqrt(chiSq / (totalObserved * (k - 1))) : 0;
790
+ return {
791
+ statistic: chiSq,
792
+ pValue,
793
+ significant: pValue < alpha,
794
+ confidenceInterval: [0, 0],
795
+ effectSize,
796
+ testName: "chi_squared",
797
+ sampleSize: totalObserved
798
+ };
799
+ }
800
+ function extractMetric(results, metricName) {
801
+ return results.filter((r) => metricName in r.values).map((r) => r.values[metricName]);
802
+ }
803
+ function groupByParameter(results, paramName) {
804
+ const groups = /* @__PURE__ */ new Map();
805
+ for (const r of results) {
806
+ const val = r.params[paramName];
807
+ if (val === void 0) continue;
808
+ if (!groups.has(val)) groups.set(val, []);
809
+ groups.get(val).push(r);
810
+ }
811
+ return groups;
812
+ }
813
+ function summarizeMetrics(results, metricName) {
814
+ const values = extractMetric(results, metricName);
815
+ if (values.length === 0) {
816
+ return { mean: 0, std: 0, min: 0, max: 0, n: 0 };
817
+ }
818
+ return {
819
+ mean: mean(values),
820
+ std: standardDeviation(values),
821
+ min: Math.min(...values),
822
+ max: Math.max(...values),
823
+ n: values.length
824
+ };
825
+ }
826
+ function normalCDF(x) {
827
+ if (x < -8) return 0;
828
+ if (x > 8) return 1;
829
+ const a1 = 0.254829592;
830
+ const a2 = -0.284496736;
831
+ const a3 = 1.421413741;
832
+ const a4 = -1.453152027;
833
+ const a5 = 1.061405429;
834
+ const p = 0.3275911;
835
+ const sign2 = x < 0 ? -1 : 1;
836
+ const absX = Math.abs(x);
837
+ const t = 1 / (1 + p * absX);
838
+ const y = 1 - ((((a5 * t + a4) * t + a3) * t + a2) * t + a1) * t * Math.exp(-absX * absX / 2);
839
+ return 0.5 * (1 + sign2 * y);
840
+ }
841
+ function tDistPValue(absT, df) {
842
+ if (df <= 0) return 1;
843
+ const z = absT * (1 - 1 / (4 * df)) / Math.sqrt(1 + absT * absT / (2 * df));
844
+ return 2 * (1 - normalCDF(z));
845
+ }
846
+ function tDistCritical(alpha, df) {
847
+ const p = 1 - alpha / 2;
848
+ const a = p - 0.5;
849
+ const r = a * a;
850
+ let z = a * (2.50662823884 + r * (-18.61500062529 + r * (41.39119773534 + r * -25.44106049637))) / (1 + r * (-8.4735109309 + r * (23.08336743743 + r * (-21.06224101826 + r * 3.13082909833))));
851
+ const g1 = (z ** 3 + z) / (4 * df);
852
+ const g2 = (5 * z ** 5 + 16 * z ** 3 + 3 * z) / (96 * df * df);
853
+ z = z + g1 + g2;
854
+ return Math.abs(z);
855
+ }
856
+ function chiSquaredPValue(chiSq, df) {
857
+ if (df <= 0) return 1;
858
+ if (chiSq <= 0) return 1;
859
+ const z = Math.pow(chiSq / df, 1 / 3) - (1 - 2 / (9 * df));
860
+ const denom = Math.sqrt(2 / (9 * df));
861
+ return 1 - normalCDF(z / denom);
862
+ }
863
+
864
+ // src/traits/SimulationLabTraits.ts
865
+ var SimulationLabTraits = {
866
+ simulation_lab: {
867
+ name: "@simulation_lab",
868
+ description: "Attaches scientific hypothesis testing to any HoloScript composition. Enables parameter sweeps, multi-epoch execution, statistical analysis, and exportable results. The universe gets one sample \u2014 HoloScript gives you infinite. Results are marketplace-sellable as verified simulation data.",
869
+ params: {
870
+ hypothesis: {
871
+ type: "string",
872
+ required: true,
873
+ description: "Human-readable hypothesis description."
874
+ },
875
+ null_hypothesis: {
876
+ type: "string",
877
+ required: false,
878
+ default: "",
879
+ description: "Formal null hypothesis (H0). Auto-generated if empty."
880
+ },
881
+ alternative_hypothesis: {
882
+ type: "string",
883
+ required: false,
884
+ default: "",
885
+ description: "Formal alternative hypothesis (H1). Auto-generated if empty."
886
+ },
887
+ direction: {
888
+ type: "string",
889
+ required: false,
890
+ default: "different",
891
+ description: "Expected direction of effect: greater | less | different | equal."
892
+ },
893
+ epochs: {
894
+ type: "number",
895
+ required: false,
896
+ default: 1e3,
897
+ description: "Number of simulation runs per parameter combination. More = higher power."
898
+ },
899
+ seed_start: {
900
+ type: "number",
901
+ required: false,
902
+ default: 0,
903
+ description: "Starting seed for reproducibility. Seeds increment per epoch."
904
+ },
905
+ confidence_level: {
906
+ type: "number",
907
+ required: false,
908
+ default: 0.95,
909
+ description: "Confidence level for statistical tests (0.0 - 1.0). Default 0.95 = \u03B1=0.05."
910
+ },
911
+ metrics: {
912
+ type: "string[]",
913
+ required: true,
914
+ description: "List of metric names to collect each epoch. Must match emitted metric events."
915
+ },
916
+ statistical_test: {
917
+ type: "string",
918
+ required: false,
919
+ default: "auto",
920
+ description: "Statistical test to use: t_test | mann_whitney_u | chi_squared | auto. Auto selects based on data distribution."
921
+ },
922
+ export_training_data: {
923
+ type: "boolean",
924
+ required: false,
925
+ default: false,
926
+ description: "Whether to export results as training data for DataForge pipeline."
927
+ },
928
+ marketplace_publishable: {
929
+ type: "boolean",
930
+ required: false,
931
+ default: false,
932
+ description: "Whether to package results for marketplace listing as verified simulation data."
933
+ },
934
+ max_duration_ms: {
935
+ type: "number",
936
+ required: false,
937
+ default: 3e5,
938
+ description: "Maximum wall-clock time for the entire experiment (5 min default). Prevents runaway simulations."
939
+ },
940
+ worker_count: {
941
+ type: "number",
942
+ required: false,
943
+ default: 4,
944
+ description: "Number of parallel workers for epoch execution."
945
+ }
946
+ },
947
+ validator: (params) => {
948
+ if (!params.hypothesis || typeof params.hypothesis !== "string") return false;
949
+ if (!params.metrics || !Array.isArray(params.metrics) || params.metrics.length === 0)
118
950
  return false;
119
- if (typeof a !== typeof b)
951
+ if (params.epochs !== void 0 && (params.epochs < 1 || params.epochs > 1e6))
120
952
  return false;
121
- if (typeof a !== 'object')
953
+ if (params.confidence_level !== void 0 && (params.confidence_level <= 0 || params.confidence_level >= 1))
122
954
  return false;
123
- if (Array.isArray(a) && Array.isArray(b)) {
124
- if (a.length !== b.length)
125
- return false;
126
- return a.every((item, i) => equals(item, b[i]));
955
+ if (params.direction !== void 0) {
956
+ if (!["greater", "less", "different", "equal"].includes(params.direction)) return false;
957
+ }
958
+ if (params.statistical_test !== void 0) {
959
+ if (!["t_test", "mann_whitney_u", "chi_squared", "auto"].includes(params.statistical_test))
960
+ return false;
961
+ }
962
+ return true;
963
+ },
964
+ composesWith: [
965
+ "@tradeable",
966
+ "@depreciating",
967
+ "@bonding_curved",
968
+ "@taxable_wealth",
969
+ "@pid_controlled"
970
+ ],
971
+ compiler_hints: {
972
+ requires_runtime: [
973
+ "SimulationRuntime.runExperiment",
974
+ "SimulationRuntime.collectMetrics",
975
+ "SimulationRuntime.runStatisticalTest",
976
+ "SimulationRuntime.exportResults"
977
+ ],
978
+ thread_safety: "worker_thread",
979
+ performance_budget_ms: 3e5,
980
+ // Experiment budget, not per-frame
981
+ batch_mode: true
127
982
  }
128
- if (a instanceof Date && b instanceof Date) {
129
- return a.getTime() === b.getTime();
983
+ }
984
+ };
985
+ function getSimulationTraitNames() {
986
+ return Object.keys(SimulationLabTraits).map((k) => SimulationLabTraits[k].name);
987
+ }
988
+ function getSimulationTrait(name) {
989
+ const key = name.startsWith("@") ? name.slice(1) : name;
990
+ return SimulationLabTraits[key];
991
+ }
992
+
993
+ // src/index.ts
994
+ function print(...args) {
995
+ console.log(...args);
996
+ }
997
+ function printError(...args) {
998
+ console.error(...args);
999
+ }
1000
+ function printWarn(...args) {
1001
+ console.warn(...args);
1002
+ }
1003
+ function assert(condition, message) {
1004
+ if (!condition) {
1005
+ throw new Error(message ?? "Assertion failed");
1006
+ }
1007
+ }
1008
+ function assertDefined(value, message) {
1009
+ if (value === null || value === void 0) {
1010
+ throw new Error(message ?? "Value is null or undefined");
1011
+ }
1012
+ }
1013
+ function unreachable(message) {
1014
+ throw new Error(message ?? "Unreachable code reached");
1015
+ }
1016
+ function todo(message) {
1017
+ throw new Error(`TODO: ${message ?? "Not implemented"}`);
1018
+ }
1019
+ function clone(value) {
1020
+ if (value === null || typeof value !== "object") {
1021
+ return value;
1022
+ }
1023
+ if (Array.isArray(value)) {
1024
+ return value.map(clone);
1025
+ }
1026
+ if (value instanceof Date) {
1027
+ return new Date(value.getTime());
1028
+ }
1029
+ if (value instanceof Map) {
1030
+ return new Map([...value].map(([k, v]) => [clone(k), clone(v)]));
1031
+ }
1032
+ if (value instanceof Set) {
1033
+ return new Set([...value].map(clone));
1034
+ }
1035
+ const result = {};
1036
+ for (const key in value) {
1037
+ if (Object.prototype.hasOwnProperty.call(value, key)) {
1038
+ result[key] = clone(value[key]);
130
1039
  }
131
- if (a instanceof Map && b instanceof Map) {
132
- if (a.size !== b.size)
133
- return false;
134
- for (const [key, value] of a) {
135
- if (!b.has(key) || !equals(value, b.get(key)))
136
- return false;
137
- }
138
- return true;
1040
+ }
1041
+ return result;
1042
+ }
1043
+ function equals(a, b) {
1044
+ if (a === b) return true;
1045
+ if (a === null || b === null) return false;
1046
+ if (typeof a !== typeof b) return false;
1047
+ if (typeof a !== "object") return false;
1048
+ if (Array.isArray(a) && Array.isArray(b)) {
1049
+ if (a.length !== b.length) return false;
1050
+ return a.every((item, i) => equals(item, b[i]));
1051
+ }
1052
+ if (a instanceof Date && b instanceof Date) {
1053
+ return a.getTime() === b.getTime();
1054
+ }
1055
+ if (a instanceof Map && b instanceof Map) {
1056
+ if (a.size !== b.size) return false;
1057
+ for (const [key, value] of a) {
1058
+ if (!b.has(key) || !equals(value, b.get(key))) return false;
139
1059
  }
140
- if (a instanceof Set && b instanceof Set) {
141
- if (a.size !== b.size)
142
- return false;
143
- for (const value of a) {
144
- if (!b.has(value))
145
- return false;
146
- }
147
- return true;
1060
+ return true;
1061
+ }
1062
+ if (a instanceof Set && b instanceof Set) {
1063
+ if (a.size !== b.size) return false;
1064
+ for (const value of a) {
1065
+ if (!b.has(value)) return false;
148
1066
  }
149
- const keysA = Object.keys(a);
150
- const keysB = Object.keys(b);
151
- if (keysA.length !== keysB.length)
152
- return false;
153
- return keysA.every((key) => equals(a[key], b[key]));
1067
+ return true;
1068
+ }
1069
+ const keysA = Object.keys(a);
1070
+ const keysB = Object.keys(b);
1071
+ if (keysA.length !== keysB.length) return false;
1072
+ return keysA.every(
1073
+ (key) => equals(a[key], b[key])
1074
+ );
154
1075
  }
155
- export function pipe(value, ...fns) {
156
- return fns.reduce((acc, fn) => fn(acc), value);
1076
+ function pipe(value, ...fns) {
1077
+ return fns.reduce((acc, fn) => fn(acc), value);
157
1078
  }
158
- export function compose(...fns) {
159
- return (value) => fns.reduceRight((acc, fn) => fn(acc), value);
1079
+ function compose(...fns) {
1080
+ return (value) => fns.reduceRight((acc, fn) => fn(acc), value);
160
1081
  }
161
- /**
162
- * Identity function
163
- */
164
- export function identity(value) {
165
- return value;
1082
+ function identity(value) {
1083
+ return value;
1084
+ }
1085
+ function noop() {
166
1086
  }
167
- /**
168
- * No-operation function
169
- */
170
- export function noop() { }
171
- /**
172
- * Create a constant function
173
- */
174
- export function constant(value) {
175
- return () => value;
1087
+ function constant(value) {
1088
+ return () => value;
176
1089
  }
1090
+ export {
1091
+ AABB,
1092
+ CountdownTimer,
1093
+ DEFAULT_BONDING_CURVE,
1094
+ DEFAULT_DEPRECIATION,
1095
+ DEFAULT_PID,
1096
+ DEFAULT_WEALTH_TAX,
1097
+ DEG_TO_RAD,
1098
+ DateTime,
1099
+ EPSILON,
1100
+ EconomicTraits,
1101
+ EventBus,
1102
+ FrameTimer,
1103
+ HALF_PI,
1104
+ HoloMap,
1105
+ HoloSet,
1106
+ IntervalTimer,
1107
+ List,
1108
+ MATERIAL_PRESETS,
1109
+ HoloMap as Map,
1110
+ PI,
1111
+ PriorityQueue,
1112
+ Quaternion,
1113
+ RAD_TO_DEG,
1114
+ Ray,
1115
+ HoloSet as Set,
1116
+ SimulationLabTraits,
1117
+ SpatialGrid,
1118
+ Stopwatch,
1119
+ TAU,
1120
+ Transform,
1121
+ Vec3,
1122
+ aabb,
1123
+ aabbMath,
1124
+ arrayToQuat,
1125
+ arrayToVec3,
1126
+ assert,
1127
+ assertDefined,
1128
+ bondingCurveBuyCost,
1129
+ bondingCurvePrice,
1130
+ bondingCurveSellRefund,
1131
+ calculateDepreciation,
1132
+ calculateRedistribution,
1133
+ calculateRepairCost,
1134
+ calculateTaxAmount,
1135
+ calculateTaxRate,
1136
+ camelCase,
1137
+ capitalize,
1138
+ center,
1139
+ chars,
1140
+ chiSquaredTest,
1141
+ clamp,
1142
+ clone,
1143
+ cohensD,
1144
+ collapseWhitespace,
1145
+ colorToHex,
1146
+ compose,
1147
+ constant,
1148
+ constantCase,
1149
+ containsIgnoreCase,
1150
+ count,
1151
+ createBoxCollider,
1152
+ createCapsuleCollider,
1153
+ createDualLoopPIDState,
1154
+ createFaucetSinkMetrics,
1155
+ createPBRMaterial,
1156
+ createPIDState,
1157
+ createRigidbody,
1158
+ createSphereCollider,
1159
+ createTicker,
1160
+ debounce,
1161
+ dedent,
1162
+ degToRad,
1163
+ depreciatedValue,
1164
+ distance,
1165
+ endsWithIgnoreCase,
1166
+ equals,
1167
+ escapeHtml,
1168
+ escapeRegex,
1169
+ executeTrade,
1170
+ expandSweep,
1171
+ extractMetric,
1172
+ extractTraits,
1173
+ format,
1174
+ formatBytes,
1175
+ formatDuration,
1176
+ formatNumber,
1177
+ fract,
1178
+ generateSweepCombinations,
1179
+ generateTxHash,
1180
+ getEconomicTrait,
1181
+ getEconomicTraitNames,
1182
+ getRequiredPermissions,
1183
+ getSimulationTrait,
1184
+ getSimulationTraitNames,
1185
+ groupByParameter,
1186
+ hrTime,
1187
+ hsl,
1188
+ identity,
1189
+ indent,
1190
+ inverseLerp,
1191
+ isAlpha,
1192
+ isAlphanumeric,
1193
+ isBlank,
1194
+ isDestroyed,
1195
+ isNotBlank,
1196
+ isNumeric,
1197
+ isParameterRange,
1198
+ isValidIdentifier,
1199
+ join,
1200
+ kebabCase,
1201
+ lerp,
1202
+ levenshtein,
1203
+ lines,
1204
+ mannWhitneyU,
1205
+ mean,
1206
+ measure,
1207
+ mod,
1208
+ noise,
1209
+ noop,
1210
+ now,
1211
+ numberWithCommas,
1212
+ oneSampleTTest,
1213
+ padLeft,
1214
+ padRight,
1215
+ parseColor,
1216
+ pascalCase,
1217
+ pipe,
1218
+ print,
1219
+ printError,
1220
+ printWarn,
1221
+ quat,
1222
+ quatMath,
1223
+ quatToArray,
1224
+ radToDeg,
1225
+ random,
1226
+ randomString,
1227
+ ray,
1228
+ recordFaucet,
1229
+ recordSink,
1230
+ remap,
1231
+ removePrefix,
1232
+ removeSuffix,
1233
+ removeWhitespace,
1234
+ repeat,
1235
+ resetMetricsPeriod,
1236
+ retry,
1237
+ reverse,
1238
+ rgb,
1239
+ rgba,
1240
+ schedule,
1241
+ scheduleFrame,
1242
+ scheduleInterval,
1243
+ sign,
1244
+ similarity,
1245
+ sleep,
1246
+ slugify,
1247
+ smootherstep,
1248
+ smoothstep,
1249
+ snakeCase,
1250
+ clamp2 as spatialClamp,
1251
+ degToRad2 as spatialDegToRad,
1252
+ lerp2 as spatialLerp,
1253
+ spatialPrice,
1254
+ radToDeg2 as spatialRadToDeg,
1255
+ standardDeviation,
1256
+ standardError,
1257
+ startsWithIgnoreCase,
1258
+ step,
1259
+ summarizeMetrics,
1260
+ tTest,
1261
+ throttle,
1262
+ timed,
1263
+ titleCase,
1264
+ radToDeg as toDegrees,
1265
+ degToRad as toRadians,
1266
+ todo,
1267
+ transform,
1268
+ truncate,
1269
+ truncateMiddle,
1270
+ unescapeHtml,
1271
+ unreachable,
1272
+ unwrap,
1273
+ updateDualLoopPID,
1274
+ updatePID,
1275
+ uuid,
1276
+ validateTraitComposition,
1277
+ variance,
1278
+ vec2,
1279
+ vec2Math,
1280
+ vec3,
1281
+ vec3Math,
1282
+ vec3ToArray,
1283
+ vec4,
1284
+ waitUntil,
1285
+ withTimeout,
1286
+ wordWrap,
1287
+ words,
1288
+ wrap as wrapString
1289
+ };
177
1290
  //# sourceMappingURL=index.js.map