@mesh2play/core 0.0.0-stage → 0.3.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.
- package/LICENSE +21 -0
- package/README.md +22 -2
- package/dist/index.d.ts +172 -0
- package/dist/index.js +280 -0
- package/dist/index.js.map +1 -0
- package/package.json +49 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Serot.Dev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @mesh2play/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Deterministic core of Mesh2Play: seeded RNG, integer math, fixed-step loop, typed events and state hashing. No dependencies.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm i @mesh2play/core
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { Rng, FixedLoop, runLoop, applyBp } from '@mesh2play/core';
|
|
11
|
+
|
|
12
|
+
const rng = new Rng(1234);
|
|
13
|
+
rng.int(1, 6); // same seed → same sequence on every device
|
|
14
|
+
applyBp(200, 1500); // 15% of 200 = 30, no floats
|
|
15
|
+
|
|
16
|
+
runLoop(new FixedLoop((tick) => world.step(), { tickRate: 20 }));
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Docs: [English](https://serot-dev.github.io/mesh2play/packages/core) · [Español](https://serot-dev.github.io/mesh2play/es/packages/core) · [GitHub](https://github.com/serot-dev/mesh2play) · MIT
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
Mesh2Play 0.3.0 · developed by Serot.Dev · MIT License
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/** The Mesh2Play release these packages belong to (every package and both hubs share it). */
|
|
2
|
+
declare const VERSION = "0.3.0";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Deterministic pseudo-random number generator (SFC32).
|
|
6
|
+
*
|
|
7
|
+
* Same seed → same sequence on every device and JS engine. This is what makes
|
|
8
|
+
* simulations verifiable: an auditor can replay exactly the same hits and drops.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const rng = new Rng(1234);
|
|
13
|
+
* rng.int(1, 6); // dice roll
|
|
14
|
+
* rng.chance(2500); // 25% chance (basis points)
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare class Rng {
|
|
18
|
+
private a;
|
|
19
|
+
private b;
|
|
20
|
+
private c;
|
|
21
|
+
private d;
|
|
22
|
+
/** @param seed Integer seed (use {@link seedFrom} to combine several values). */
|
|
23
|
+
constructor(seed: number);
|
|
24
|
+
/** Unsigned 32-bit integer. */
|
|
25
|
+
next(): number;
|
|
26
|
+
/** Float in [0, 1). Deterministic, but prefer {@link int} inside game rules. */
|
|
27
|
+
float(): number;
|
|
28
|
+
/** Unbiased uniform integer in [min, max] (both inclusive). */
|
|
29
|
+
int(min: number, max: number): number;
|
|
30
|
+
/** `true` with probability `bp / 10000` (basis points: 10000 = 100%). */
|
|
31
|
+
chance(bp: number): boolean;
|
|
32
|
+
/** Random element of a non-empty list. */
|
|
33
|
+
pick<T>(list: readonly T[]): T;
|
|
34
|
+
/** Shuffled copy of a list (Fisher–Yates). */
|
|
35
|
+
shuffle<T>(list: readonly T[]): T[];
|
|
36
|
+
/** Independent child generator (e.g. one per monster) that does not advance this one. */
|
|
37
|
+
fork(...label: (string | number)[]): Rng;
|
|
38
|
+
/** Serializable state (for snapshots and replays). */
|
|
39
|
+
getState(): [number, number, number, number];
|
|
40
|
+
/** Restores a state returned by {@link getState}. */
|
|
41
|
+
setState(s: readonly [number, number, number, number]): void;
|
|
42
|
+
/** Creates a generator from a saved state. */
|
|
43
|
+
static fromState(s: readonly [number, number, number, number]): Rng;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Mixes several values (numbers or strings) into a 32-bit seed.
|
|
47
|
+
* Type and order matter: `seedFrom(1, 2) !== seedFrom(2, 1)`, `seedFrom('1') !== seedFrom(1)`.
|
|
48
|
+
* Useful for sealed randomness: `seedFrom(beacon, monsterId, tick)`.
|
|
49
|
+
*/
|
|
50
|
+
declare function seedFrom(...parts: (string | number)[]): number;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Deterministic integer math.
|
|
54
|
+
*
|
|
55
|
+
* Floating point and functions such as `Math.pow` or `Math.sin` may differ
|
|
56
|
+
* between browsers. Game rules that must be verifiable should only use
|
|
57
|
+
* integers; these helpers make that comfortable.
|
|
58
|
+
*/
|
|
59
|
+
/** 100% expressed in basis points. `2500` = 25%. */
|
|
60
|
+
declare const BP = 10000;
|
|
61
|
+
/** Clamps `v` to [min, max]. */
|
|
62
|
+
declare function clamp(v: number, min: number, max: number): number;
|
|
63
|
+
/** Integer division rounding down (also for negatives). */
|
|
64
|
+
declare function floorDiv(a: number, b: number): number;
|
|
65
|
+
/** Applies a percentage in basis points: `applyBp(200, 1500)` → 30. */
|
|
66
|
+
declare function applyBp(value: number, bp: number): number;
|
|
67
|
+
/** Exact integer square root (floor) for safe integers. */
|
|
68
|
+
declare function isqrt(n: number): number;
|
|
69
|
+
/** Exact integer power (integer base, exponent >= 0). */
|
|
70
|
+
declare function ipow(base: number, exp: number): number;
|
|
71
|
+
/** Integer linear interpolation; `t` in basis points (0..10000). */
|
|
72
|
+
declare function lerpBp(a: number, b: number, t: number): number;
|
|
73
|
+
/** Throws if `v` is not a safe integer. Handy in debug builds. */
|
|
74
|
+
declare function assertInt(v: number, name?: string): number;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Typed event bus. Listeners run in subscription order (deterministic).
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* type Events = { kill: { killer: number; victim: number } };
|
|
82
|
+
* const bus = new EventBus<Events>();
|
|
83
|
+
* const off = bus.on('kill', (e) => console.log(e.killer));
|
|
84
|
+
* bus.emit('kill', { killer: 1, victim: 2 });
|
|
85
|
+
* off(); // unsubscribe
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
declare class EventBus<Events extends Record<string, unknown>> {
|
|
89
|
+
private listeners;
|
|
90
|
+
/** Subscribes a listener. Returns an unsubscribe function. */
|
|
91
|
+
on<K extends keyof Events>(type: K, fn: (e: Events[K]) => void): () => void;
|
|
92
|
+
/** Subscribes a listener that runs only once. */
|
|
93
|
+
once<K extends keyof Events>(type: K, fn: (e: Events[K]) => void): () => void;
|
|
94
|
+
/** Removes a listener. */
|
|
95
|
+
off<K extends keyof Events>(type: K, fn: (e: Events[K]) => void): void;
|
|
96
|
+
/** Emits an event to all its listeners. */
|
|
97
|
+
emit<K extends keyof Events>(type: K, event: Events[K]): void;
|
|
98
|
+
/** Removes all listeners (of one type, or all). */
|
|
99
|
+
clear(type?: keyof Events): void;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Fixed-step loop: the simulation always advances in ticks of the same size,
|
|
104
|
+
* even if the real clock stutters. Essential for determinism.
|
|
105
|
+
*/
|
|
106
|
+
interface FixedLoopOptions {
|
|
107
|
+
/** Ticks per second (default 20). */
|
|
108
|
+
tickRate?: number;
|
|
109
|
+
/** Max ticks to catch up at once after a stall (avoids the "spiral of death"). Default 10. */
|
|
110
|
+
maxCatchUp?: number;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Accumulates real time and runs `step(tick)` as many times as needed.
|
|
114
|
+
* It owns no timer: you call {@link FixedLoop.advance} with the elapsed time,
|
|
115
|
+
* so it behaves the same on servers, browsers and tests.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* const loop = new FixedLoop((tick) => world.step(), { tickRate: 20 });
|
|
120
|
+
* loop.advance(50); // runs 1 tick
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
declare class FixedLoop {
|
|
124
|
+
private readonly step;
|
|
125
|
+
readonly tickRate: number;
|
|
126
|
+
readonly tickMs: number;
|
|
127
|
+
private readonly maxCatchUp;
|
|
128
|
+
private acc;
|
|
129
|
+
/** Number of the next tick to run. */
|
|
130
|
+
tick: number;
|
|
131
|
+
constructor(step: (tick: number) => void, opts?: FixedLoopOptions);
|
|
132
|
+
/**
|
|
133
|
+
* Advances the clock by `elapsedMs`.
|
|
134
|
+
* @returns number of ticks executed.
|
|
135
|
+
*/
|
|
136
|
+
advance(elapsedMs: number): number;
|
|
137
|
+
/** Fraction (0..1) towards the next tick: use it to interpolate rendering. */
|
|
138
|
+
get alpha(): number;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Runs a {@link FixedLoop} with a real timer.
|
|
142
|
+
* Uses `setTimeout` by default; in browsers you can pass `requestAnimationFrame`.
|
|
143
|
+
* @returns a function that stops the loop.
|
|
144
|
+
*/
|
|
145
|
+
declare function runLoop(loop: FixedLoop, schedule?: (cb: () => void) => unknown, now?: () => number): () => void;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Canonical serialization and fast state hashing.
|
|
149
|
+
*
|
|
150
|
+
* Two machines holding the same state produce exactly the same bytes (sorted
|
|
151
|
+
* keys), so they can compare 32-bit fingerprints every tick without sending
|
|
152
|
+
* the whole state.
|
|
153
|
+
*/
|
|
154
|
+
/** Values allowed in a serializable state. */
|
|
155
|
+
type Serializable = null | boolean | number | string | Serializable[] | {
|
|
156
|
+
[k: string]: Serializable | undefined;
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* Canonical JSON: sorted keys, no `undefined`. Rejects `NaN`/`Infinity`
|
|
160
|
+
* because they have no stable representation.
|
|
161
|
+
*/
|
|
162
|
+
declare function canonicalJson(value: unknown): string;
|
|
163
|
+
/** 32-bit FNV-1a hash of a string. Fast, NOT cryptographic. */
|
|
164
|
+
declare function fnv1a(text: string): number;
|
|
165
|
+
/**
|
|
166
|
+
* Fast fingerprint of any serializable state.
|
|
167
|
+
* For cryptographic proofs use `hashValue` from `@mesh2play/trust`.
|
|
168
|
+
*/
|
|
169
|
+
declare function hashState(value: unknown): number;
|
|
170
|
+
|
|
171
|
+
export { BP, EventBus, FixedLoop, Rng, VERSION, applyBp, assertInt, canonicalJson, clamp, floorDiv, fnv1a, hashState, ipow, isqrt, lerpBp, runLoop, seedFrom };
|
|
172
|
+
export type { FixedLoopOptions, Serializable };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/*! Mesh2Play v0.3.0 — developed by Serot.Dev — MIT License */
|
|
2
|
+
|
|
3
|
+
// src/version.ts
|
|
4
|
+
var VERSION = "0.3.0";
|
|
5
|
+
|
|
6
|
+
// src/rng.ts
|
|
7
|
+
var Rng = class _Rng {
|
|
8
|
+
a;
|
|
9
|
+
b;
|
|
10
|
+
c;
|
|
11
|
+
d;
|
|
12
|
+
/** @param seed Integer seed (use {@link seedFrom} to combine several values). */
|
|
13
|
+
constructor(seed) {
|
|
14
|
+
this.a = 2654435769;
|
|
15
|
+
this.b = 608135816;
|
|
16
|
+
this.c = 3084996962;
|
|
17
|
+
this.d = seed >>> 0;
|
|
18
|
+
for (let i = 0; i < 12; i++) this.next();
|
|
19
|
+
}
|
|
20
|
+
/** Unsigned 32-bit integer. */
|
|
21
|
+
next() {
|
|
22
|
+
const t = (this.a + this.b | 0) + this.d | 0;
|
|
23
|
+
this.d = this.d + 1 | 0;
|
|
24
|
+
this.a = this.b ^ this.b >>> 9;
|
|
25
|
+
this.b = this.c + (this.c << 3) | 0;
|
|
26
|
+
this.c = this.c << 21 | this.c >>> 11;
|
|
27
|
+
this.c = this.c + t | 0;
|
|
28
|
+
return t >>> 0;
|
|
29
|
+
}
|
|
30
|
+
/** Float in [0, 1). Deterministic, but prefer {@link int} inside game rules. */
|
|
31
|
+
float() {
|
|
32
|
+
return this.next() / 4294967296;
|
|
33
|
+
}
|
|
34
|
+
/** Unbiased uniform integer in [min, max] (both inclusive). */
|
|
35
|
+
int(min, max) {
|
|
36
|
+
if (!Number.isFinite(min) || !Number.isFinite(max)) throw new RangeError(`Rng.int: bounds must be finite (${min}, ${max})`);
|
|
37
|
+
min = Math.floor(min);
|
|
38
|
+
max = Math.floor(max);
|
|
39
|
+
if (max < min) [min, max] = [max, min];
|
|
40
|
+
const range = max - min + 1;
|
|
41
|
+
if (range <= 1) return min;
|
|
42
|
+
if (range > 4294967296) throw new RangeError("Rng.int: range larger than 2^32");
|
|
43
|
+
const limit = 4294967296 - 4294967296 % range;
|
|
44
|
+
let v;
|
|
45
|
+
do
|
|
46
|
+
v = this.next();
|
|
47
|
+
while (v >= limit);
|
|
48
|
+
return min + v % range;
|
|
49
|
+
}
|
|
50
|
+
/** `true` with probability `bp / 10000` (basis points: 10000 = 100%). */
|
|
51
|
+
chance(bp) {
|
|
52
|
+
return this.int(0, 9999) < bp;
|
|
53
|
+
}
|
|
54
|
+
/** Random element of a non-empty list. */
|
|
55
|
+
pick(list) {
|
|
56
|
+
if (list.length === 0) throw new Error("Rng.pick: empty list");
|
|
57
|
+
return list[this.int(0, list.length - 1)];
|
|
58
|
+
}
|
|
59
|
+
/** Shuffled copy of a list (Fisher–Yates). */
|
|
60
|
+
shuffle(list) {
|
|
61
|
+
const out = list.slice();
|
|
62
|
+
for (let i = out.length - 1; i > 0; i--) {
|
|
63
|
+
const j = this.int(0, i);
|
|
64
|
+
[out[i], out[j]] = [out[j], out[i]];
|
|
65
|
+
}
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
/** Independent child generator (e.g. one per monster) that does not advance this one. */
|
|
69
|
+
fork(...label) {
|
|
70
|
+
return new _Rng(seedFrom(this.a, this.b, this.c, this.d, ...label));
|
|
71
|
+
}
|
|
72
|
+
/** Serializable state (for snapshots and replays). */
|
|
73
|
+
getState() {
|
|
74
|
+
return [this.a, this.b, this.c, this.d];
|
|
75
|
+
}
|
|
76
|
+
/** Restores a state returned by {@link getState}. */
|
|
77
|
+
setState(s) {
|
|
78
|
+
const v = s;
|
|
79
|
+
if (!Array.isArray(v) || v.length !== 4 || v.some((x) => !Number.isInteger(x) || x < -2147483648 || x > 4294967295) || v.every((x) => x === 0)) {
|
|
80
|
+
throw new RangeError("Rng: bad state");
|
|
81
|
+
}
|
|
82
|
+
[this.a, this.b, this.c, this.d] = s;
|
|
83
|
+
}
|
|
84
|
+
/** Creates a generator from a saved state. */
|
|
85
|
+
static fromState(s) {
|
|
86
|
+
const r = new _Rng(0);
|
|
87
|
+
r.setState(s);
|
|
88
|
+
return r;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
function seedFrom(...parts) {
|
|
92
|
+
let h = 2166136261;
|
|
93
|
+
for (const p of parts) {
|
|
94
|
+
const s = typeof p === "number" ? `n${p}` : `s${p}`;
|
|
95
|
+
for (let i = 0; i < s.length; i++) {
|
|
96
|
+
h ^= s.charCodeAt(i);
|
|
97
|
+
h = Math.imul(h, 16777619);
|
|
98
|
+
}
|
|
99
|
+
h ^= 255;
|
|
100
|
+
h = Math.imul(h, 16777619);
|
|
101
|
+
}
|
|
102
|
+
h ^= h >>> 16;
|
|
103
|
+
h = Math.imul(h, 2246822507);
|
|
104
|
+
h ^= h >>> 13;
|
|
105
|
+
return h >>> 0;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// src/math.ts
|
|
109
|
+
var BP = 1e4;
|
|
110
|
+
function clamp(v, min, max) {
|
|
111
|
+
return v < min ? min : v > max ? max : v;
|
|
112
|
+
}
|
|
113
|
+
function floorDiv(a, b) {
|
|
114
|
+
if (b === 0) throw new RangeError("floorDiv: division by zero");
|
|
115
|
+
return Math.floor(a / b);
|
|
116
|
+
}
|
|
117
|
+
function applyBp(value, bp) {
|
|
118
|
+
if (Number.isSafeInteger(value * bp)) return floorDiv(value * bp, BP);
|
|
119
|
+
const q = Math.floor(value / BP), r = value - q * BP;
|
|
120
|
+
return q * bp + floorDiv(r * bp, BP);
|
|
121
|
+
}
|
|
122
|
+
function isqrt(n) {
|
|
123
|
+
if (!(n >= 0) || !Number.isFinite(n)) throw new RangeError(`isqrt: needs a finite number \u2265 0 (${n})`);
|
|
124
|
+
n = Math.floor(n);
|
|
125
|
+
if (n < 2) return n;
|
|
126
|
+
let x = Math.floor(Math.sqrt(n));
|
|
127
|
+
while (x * x > n) x--;
|
|
128
|
+
while ((x + 1) * (x + 1) <= n) x++;
|
|
129
|
+
return x;
|
|
130
|
+
}
|
|
131
|
+
function ipow(base, exp) {
|
|
132
|
+
if (!Number.isSafeInteger(exp) || exp < 0) throw new RangeError(`ipow: the exponent must be a whole number \u2265 0 (${exp})`);
|
|
133
|
+
let r = 1;
|
|
134
|
+
for (let i = 0; i < exp; i++) r *= base;
|
|
135
|
+
return r;
|
|
136
|
+
}
|
|
137
|
+
function lerpBp(a, b, t) {
|
|
138
|
+
return a + applyBp(b - a, t);
|
|
139
|
+
}
|
|
140
|
+
function assertInt(v, name = "value") {
|
|
141
|
+
if (!Number.isSafeInteger(v)) throw new TypeError(`${name} must be an integer, got ${v}`);
|
|
142
|
+
return v;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// src/events.ts
|
|
146
|
+
var EventBus = class {
|
|
147
|
+
listeners = /* @__PURE__ */ new Map();
|
|
148
|
+
/** Subscribes a listener. Returns an unsubscribe function. */
|
|
149
|
+
on(type, fn) {
|
|
150
|
+
const list = this.listeners.get(type) ?? [];
|
|
151
|
+
list.push(fn);
|
|
152
|
+
this.listeners.set(type, list);
|
|
153
|
+
return () => this.off(type, fn);
|
|
154
|
+
}
|
|
155
|
+
/** Subscribes a listener that runs only once. */
|
|
156
|
+
once(type, fn) {
|
|
157
|
+
const off = this.on(type, (e) => {
|
|
158
|
+
off();
|
|
159
|
+
fn(e);
|
|
160
|
+
});
|
|
161
|
+
return off;
|
|
162
|
+
}
|
|
163
|
+
/** Removes a listener. */
|
|
164
|
+
off(type, fn) {
|
|
165
|
+
const list = this.listeners.get(type);
|
|
166
|
+
if (!list) return;
|
|
167
|
+
const i = list.indexOf(fn);
|
|
168
|
+
if (i >= 0) list.splice(i, 1);
|
|
169
|
+
}
|
|
170
|
+
/** Emits an event to all its listeners. */
|
|
171
|
+
emit(type, event) {
|
|
172
|
+
const list = this.listeners.get(type);
|
|
173
|
+
if (!list) return;
|
|
174
|
+
for (const fn of list.slice()) fn(event);
|
|
175
|
+
}
|
|
176
|
+
/** Removes all listeners (of one type, or all). */
|
|
177
|
+
clear(type) {
|
|
178
|
+
if (type) this.listeners.delete(type);
|
|
179
|
+
else this.listeners.clear();
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
// src/loop.ts
|
|
184
|
+
var FixedLoop = class {
|
|
185
|
+
constructor(step, opts = {}) {
|
|
186
|
+
this.step = step;
|
|
187
|
+
this.tickRate = opts.tickRate ?? 20;
|
|
188
|
+
if (!(this.tickRate > 0) || !Number.isFinite(this.tickRate)) throw new RangeError("FixedLoop: tickRate must be a positive number");
|
|
189
|
+
this.tickMs = 1e3 / this.tickRate;
|
|
190
|
+
this.maxCatchUp = opts.maxCatchUp ?? 10;
|
|
191
|
+
}
|
|
192
|
+
step;
|
|
193
|
+
tickRate;
|
|
194
|
+
tickMs;
|
|
195
|
+
maxCatchUp;
|
|
196
|
+
acc = 0;
|
|
197
|
+
/** Number of the next tick to run. */
|
|
198
|
+
tick = 0;
|
|
199
|
+
/**
|
|
200
|
+
* Advances the clock by `elapsedMs`.
|
|
201
|
+
* @returns number of ticks executed.
|
|
202
|
+
*/
|
|
203
|
+
advance(elapsedMs) {
|
|
204
|
+
this.acc += Number.isFinite(elapsedMs) ? Math.max(0, elapsedMs) : 0;
|
|
205
|
+
let n = 0;
|
|
206
|
+
while (this.acc >= this.tickMs && n < this.maxCatchUp) {
|
|
207
|
+
this.step(this.tick++);
|
|
208
|
+
this.acc -= this.tickMs;
|
|
209
|
+
n++;
|
|
210
|
+
}
|
|
211
|
+
if (n === this.maxCatchUp) this.acc = 0;
|
|
212
|
+
return n;
|
|
213
|
+
}
|
|
214
|
+
/** Fraction (0..1) towards the next tick: use it to interpolate rendering. */
|
|
215
|
+
get alpha() {
|
|
216
|
+
return this.acc / this.tickMs;
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
function runLoop(loop, schedule = (cb) => setTimeout(cb, loop.tickMs / 2), now = () => performance.now()) {
|
|
220
|
+
let running = true;
|
|
221
|
+
let last = now();
|
|
222
|
+
const frame = () => {
|
|
223
|
+
if (!running) return;
|
|
224
|
+
const t = now();
|
|
225
|
+
loop.advance(t - last);
|
|
226
|
+
last = t;
|
|
227
|
+
schedule(frame);
|
|
228
|
+
};
|
|
229
|
+
schedule(frame);
|
|
230
|
+
return () => {
|
|
231
|
+
running = false;
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// src/hash.ts
|
|
236
|
+
function canonicalJson(value) {
|
|
237
|
+
if (value === null || typeof value === "boolean" || typeof value === "string") return JSON.stringify(value);
|
|
238
|
+
if (typeof value === "number") {
|
|
239
|
+
if (!Number.isFinite(value)) throw new TypeError(`canonicalJson: non-finite number (${value})`);
|
|
240
|
+
return JSON.stringify(value);
|
|
241
|
+
}
|
|
242
|
+
if (Array.isArray(value)) return `[${Array.from(value, (v) => v === void 0 ? "null" : canonicalJson(v)).join(",")}]`;
|
|
243
|
+
if (typeof value === "object") {
|
|
244
|
+
const obj = value;
|
|
245
|
+
const keys = Object.keys(obj).filter((k) => obj[k] !== void 0).sort();
|
|
246
|
+
return `{${keys.map((k) => `${JSON.stringify(k)}:${canonicalJson(obj[k])}`).join(",")}}`;
|
|
247
|
+
}
|
|
248
|
+
throw new TypeError(`canonicalJson: unsupported type (${typeof value})`);
|
|
249
|
+
}
|
|
250
|
+
function fnv1a(text) {
|
|
251
|
+
let h = 2166136261;
|
|
252
|
+
for (let i = 0; i < text.length; i++) {
|
|
253
|
+
h ^= text.charCodeAt(i);
|
|
254
|
+
h = Math.imul(h, 16777619);
|
|
255
|
+
}
|
|
256
|
+
return h >>> 0;
|
|
257
|
+
}
|
|
258
|
+
function hashState(value) {
|
|
259
|
+
return fnv1a(canonicalJson(value));
|
|
260
|
+
}
|
|
261
|
+
export {
|
|
262
|
+
BP,
|
|
263
|
+
EventBus,
|
|
264
|
+
FixedLoop,
|
|
265
|
+
Rng,
|
|
266
|
+
VERSION,
|
|
267
|
+
applyBp,
|
|
268
|
+
assertInt,
|
|
269
|
+
canonicalJson,
|
|
270
|
+
clamp,
|
|
271
|
+
floorDiv,
|
|
272
|
+
fnv1a,
|
|
273
|
+
hashState,
|
|
274
|
+
ipow,
|
|
275
|
+
isqrt,
|
|
276
|
+
lerpBp,
|
|
277
|
+
runLoop,
|
|
278
|
+
seedFrom
|
|
279
|
+
};
|
|
280
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/version.ts","../src/rng.ts","../src/math.ts","../src/events.ts","../src/loop.ts","../src/hash.ts"],"sourcesContent":["// Mesh2Play — developed by Serot.Dev — MIT License\n\n/** The Mesh2Play release these packages belong to (every package and both hubs share it). */\nexport const VERSION = '0.3.0';\n","// Mesh2Play — developed by Serot.Dev — MIT License\n/**\n * Deterministic pseudo-random number generator (SFC32).\n *\n * Same seed → same sequence on every device and JS engine. This is what makes\n * simulations verifiable: an auditor can replay exactly the same hits and drops.\n *\n * @example\n * ```ts\n * const rng = new Rng(1234);\n * rng.int(1, 6); // dice roll\n * rng.chance(2500); // 25% chance (basis points)\n * ```\n */\nexport class Rng {\n private a: number;\n private b: number;\n private c: number;\n private d: number;\n\n /** @param seed Integer seed (use {@link seedFrom} to combine several values). */\n constructor(seed: number) {\n this.a = 0x9e3779b9;\n this.b = 0x243f6a88;\n this.c = 0xb7e15162;\n this.d = seed >>> 0;\n for (let i = 0; i < 12; i++) this.next(); // warm up the state\n }\n\n /** Unsigned 32-bit integer. */\n next(): number {\n const t = (((this.a + this.b) | 0) + this.d) | 0;\n this.d = (this.d + 1) | 0;\n this.a = this.b ^ (this.b >>> 9);\n this.b = (this.c + (this.c << 3)) | 0;\n this.c = (this.c << 21) | (this.c >>> 11);\n this.c = (this.c + t) | 0;\n return t >>> 0;\n }\n\n /** Float in [0, 1). Deterministic, but prefer {@link int} inside game rules. */\n float(): number {\n return this.next() / 4294967296;\n }\n\n /** Unbiased uniform integer in [min, max] (both inclusive). */\n int(min: number, max: number): number {\n // At most 2^32 values apart (the same rule as the native core): a wider range used to loop for\n // ever. NaN or Infinity throw; a fraction is rounded down (a stat of 1.5 is 1), so the result\n // is always a whole number.\n if (!Number.isFinite(min) || !Number.isFinite(max)) throw new RangeError(`Rng.int: bounds must be finite (${min}, ${max})`);\n min = Math.floor(min);\n max = Math.floor(max);\n if (max < min) [min, max] = [max, min];\n const range = max - min + 1;\n if (range <= 1) return min;\n if (range > 4294967296) throw new RangeError('Rng.int: range larger than 2^32');\n // Rejection sampling avoids modulo bias.\n const limit = 4294967296 - (4294967296 % range);\n let v: number;\n do v = this.next();\n while (v >= limit);\n return min + (v % range);\n }\n\n /** `true` with probability `bp / 10000` (basis points: 10000 = 100%). */\n chance(bp: number): boolean {\n return this.int(0, 9999) < bp;\n }\n\n /** Random element of a non-empty list. */\n pick<T>(list: readonly T[]): T {\n if (list.length === 0) throw new Error('Rng.pick: empty list');\n return list[this.int(0, list.length - 1)]!;\n }\n\n /** Shuffled copy of a list (Fisher–Yates). */\n shuffle<T>(list: readonly T[]): T[] {\n const out = list.slice();\n for (let i = out.length - 1; i > 0; i--) {\n const j = this.int(0, i);\n [out[i], out[j]] = [out[j]!, out[i]!];\n }\n return out;\n }\n\n /** Independent child generator (e.g. one per monster) that does not advance this one. */\n fork(...label: (string | number)[]): Rng {\n return new Rng(seedFrom(this.a, this.b, this.c, this.d, ...label));\n }\n\n /** Serializable state (for snapshots and replays). */\n getState(): [number, number, number, number] {\n return [this.a, this.b, this.c, this.d];\n }\n\n /** Restores a state returned by {@link getState}. */\n setState(s: readonly [number, number, number, number]): void {\n // A state from a save or a peer: four 32-bit integers, not all zero (an all-zero\n // generator returns 0 forever). Anything else would silently break every roll.\n const v: unknown = s;\n if (!Array.isArray(v) || v.length !== 4 || v.some((x) => !Number.isInteger(x) || x < -0x80000000 || x > 0xffffffff) || v.every((x) => x === 0)) {\n throw new RangeError('Rng: bad state');\n }\n [this.a, this.b, this.c, this.d] = s;\n }\n\n /** Creates a generator from a saved state. */\n static fromState(s: readonly [number, number, number, number]): Rng {\n const r = new Rng(0);\n r.setState(s);\n return r;\n }\n}\n\n/**\n * Mixes several values (numbers or strings) into a 32-bit seed.\n * Type and order matter: `seedFrom(1, 2) !== seedFrom(2, 1)`, `seedFrom('1') !== seedFrom(1)`.\n * Useful for sealed randomness: `seedFrom(beacon, monsterId, tick)`.\n */\nexport function seedFrom(...parts: (string | number)[]): number {\n let h = 0x811c9dc5;\n for (const p of parts) {\n const s = typeof p === 'number' ? `n${p}` : `s${p}`;\n for (let i = 0; i < s.length; i++) {\n h ^= s.charCodeAt(i);\n h = Math.imul(h, 0x01000193);\n }\n h ^= 0xff; // part separator\n h = Math.imul(h, 0x01000193);\n }\n // Final avalanche.\n h ^= h >>> 16;\n h = Math.imul(h, 0x85ebca6b);\n h ^= h >>> 13;\n return h >>> 0;\n}\n","// Mesh2Play — developed by Serot.Dev — MIT License\n/**\n * Deterministic integer math.\n *\n * Floating point and functions such as `Math.pow` or `Math.sin` may differ\n * between browsers. Game rules that must be verifiable should only use\n * integers; these helpers make that comfortable.\n */\n\n/** 100% expressed in basis points. `2500` = 25%. */\nexport const BP = 10_000;\n\n/** Clamps `v` to [min, max]. */\nexport function clamp(v: number, min: number, max: number): number {\n return v < min ? min : v > max ? max : v;\n}\n\n/** Integer division rounding down (also for negatives). */\nexport function floorDiv(a: number, b: number): number {\n if (b === 0) throw new RangeError('floorDiv: division by zero');\n return Math.floor(a / b);\n}\n\n/** Applies a percentage in basis points: `applyBp(200, 1500)` → 30. */\nexport function applyBp(value: number, bp: number): number {\n // Split past 2^53 (a price of 10^12 × 10,000 bp is 10^16): the float product was off by one now\n // and then, and every machine must get the same whole number.\n if (Number.isSafeInteger(value * bp)) return floorDiv(value * bp, BP);\n const q = Math.floor(value / BP), r = value - q * BP; // 0 ≤ r < BP, also for negative values\n return q * bp + floorDiv(r * bp, BP);\n}\n\n/** Exact integer square root (floor) for safe integers. */\nexport function isqrt(n: number): number {\n if (!(n >= 0) || !Number.isFinite(n)) throw new RangeError(`isqrt: needs a finite number ≥ 0 (${n})`); // NaN returned NaN\n n = Math.floor(n);\n if (n < 2) return n;\n let x = Math.floor(Math.sqrt(n)); // estimate, corrected below\n while (x * x > n) x--;\n while ((x + 1) * (x + 1) <= n) x++;\n return x;\n}\n\n/** Exact integer power (integer base, exponent >= 0). */\nexport function ipow(base: number, exp: number): number {\n // A negative or fractional exponent returned 1 (or stopped early) without a word.\n if (!Number.isSafeInteger(exp) || exp < 0) throw new RangeError(`ipow: the exponent must be a whole number ≥ 0 (${exp})`);\n let r = 1;\n for (let i = 0; i < exp; i++) r *= base;\n return r;\n}\n\n/** Integer linear interpolation; `t` in basis points (0..10000). */\nexport function lerpBp(a: number, b: number, t: number): number {\n return a + applyBp(b - a, t); // exact past 2^53, as applyBp\n}\n\n/** Throws if `v` is not a safe integer. Handy in debug builds. */\nexport function assertInt(v: number, name = 'value'): number {\n if (!Number.isSafeInteger(v)) throw new TypeError(`${name} must be an integer, got ${v}`);\n return v;\n}\n","// Mesh2Play — developed by Serot.Dev — MIT License\n/**\n * Typed event bus. Listeners run in subscription order (deterministic).\n *\n * @example\n * ```ts\n * type Events = { kill: { killer: number; victim: number } };\n * const bus = new EventBus<Events>();\n * const off = bus.on('kill', (e) => console.log(e.killer));\n * bus.emit('kill', { killer: 1, victim: 2 });\n * off(); // unsubscribe\n * ```\n */\nexport class EventBus<Events extends Record<string, unknown>> {\n private listeners = new Map<keyof Events, Array<(e: never) => void>>();\n\n /** Subscribes a listener. Returns an unsubscribe function. */\n on<K extends keyof Events>(type: K, fn: (e: Events[K]) => void): () => void {\n const list = this.listeners.get(type) ?? [];\n list.push(fn as (e: never) => void);\n this.listeners.set(type, list);\n return () => this.off(type, fn);\n }\n\n /** Subscribes a listener that runs only once. */\n once<K extends keyof Events>(type: K, fn: (e: Events[K]) => void): () => void {\n const off = this.on(type, (e) => {\n off();\n fn(e);\n });\n return off;\n }\n\n /** Removes a listener. */\n off<K extends keyof Events>(type: K, fn: (e: Events[K]) => void): void {\n const list = this.listeners.get(type);\n if (!list) return;\n const i = list.indexOf(fn as (e: never) => void);\n if (i >= 0) list.splice(i, 1);\n }\n\n /** Emits an event to all its listeners. */\n emit<K extends keyof Events>(type: K, event: Events[K]): void {\n const list = this.listeners.get(type);\n if (!list) return;\n for (const fn of list.slice()) (fn as (e: Events[K]) => void)(event);\n }\n\n /** Removes all listeners (of one type, or all). */\n clear(type?: keyof Events): void {\n if (type) this.listeners.delete(type);\n else this.listeners.clear();\n }\n}\n","// Mesh2Play — developed by Serot.Dev — MIT License\n/**\n * Fixed-step loop: the simulation always advances in ticks of the same size,\n * even if the real clock stutters. Essential for determinism.\n */\n\nexport interface FixedLoopOptions {\n /** Ticks per second (default 20). */\n tickRate?: number;\n /** Max ticks to catch up at once after a stall (avoids the \"spiral of death\"). Default 10. */\n maxCatchUp?: number;\n}\n\n/**\n * Accumulates real time and runs `step(tick)` as many times as needed.\n * It owns no timer: you call {@link FixedLoop.advance} with the elapsed time,\n * so it behaves the same on servers, browsers and tests.\n *\n * @example\n * ```ts\n * const loop = new FixedLoop((tick) => world.step(), { tickRate: 20 });\n * loop.advance(50); // runs 1 tick\n * ```\n */\nexport class FixedLoop {\n readonly tickRate: number;\n readonly tickMs: number;\n private readonly maxCatchUp: number;\n private acc = 0;\n /** Number of the next tick to run. */\n tick = 0;\n\n constructor(\n private readonly step: (tick: number) => void,\n opts: FixedLoopOptions = {},\n ) {\n this.tickRate = opts.tickRate ?? 20;\n if (!(this.tickRate > 0) || !Number.isFinite(this.tickRate)) throw new RangeError('FixedLoop: tickRate must be a positive number');\n this.tickMs = 1000 / this.tickRate;\n this.maxCatchUp = opts.maxCatchUp ?? 10;\n }\n\n /**\n * Advances the clock by `elapsedMs`.\n * @returns number of ticks executed.\n */\n advance(elapsedMs: number): number {\n this.acc += Number.isFinite(elapsedMs) ? Math.max(0, elapsedMs) : 0; // NaN would stop the loop for good\n let n = 0;\n while (this.acc >= this.tickMs && n < this.maxCatchUp) {\n this.step(this.tick++);\n this.acc -= this.tickMs;\n n++;\n }\n if (n === this.maxCatchUp) this.acc = 0; // drop unrecoverable lag\n return n;\n }\n\n /** Fraction (0..1) towards the next tick: use it to interpolate rendering. */\n get alpha(): number {\n return this.acc / this.tickMs;\n }\n}\n\n/**\n * Runs a {@link FixedLoop} with a real timer.\n * Uses `setTimeout` by default; in browsers you can pass `requestAnimationFrame`.\n * @returns a function that stops the loop.\n */\nexport function runLoop(\n loop: FixedLoop,\n schedule: (cb: () => void) => unknown = (cb) => setTimeout(cb, loop.tickMs / 2),\n now: () => number = () => performance.now(),\n): () => void {\n let running = true;\n let last = now();\n const frame = () => {\n if (!running) return;\n const t = now();\n loop.advance(t - last);\n last = t;\n schedule(frame);\n };\n schedule(frame);\n return () => {\n running = false;\n };\n}\n","// Mesh2Play — developed by Serot.Dev — MIT License\n/**\n * Canonical serialization and fast state hashing.\n *\n * Two machines holding the same state produce exactly the same bytes (sorted\n * keys), so they can compare 32-bit fingerprints every tick without sending\n * the whole state.\n */\n\n/** Values allowed in a serializable state. */\nexport type Serializable =\n | null\n | boolean\n | number\n | string\n | Serializable[]\n | { [k: string]: Serializable | undefined };\n\n/**\n * Canonical JSON: sorted keys, no `undefined`. Rejects `NaN`/`Infinity`\n * because they have no stable representation.\n */\nexport function canonicalJson(value: unknown): string {\n if (value === null || typeof value === 'boolean' || typeof value === 'string') return JSON.stringify(value);\n if (typeof value === 'number') {\n if (!Number.isFinite(value)) throw new TypeError(`canonicalJson: non-finite number (${value})`);\n return JSON.stringify(value);\n }\n // Holes and undefined in arrays become null, as JSON.stringify does (they used to give `[,1]` or throw).\n if (Array.isArray(value)) return `[${Array.from(value, (v) => (v === undefined ? 'null' : canonicalJson(v))).join(',')}]`;\n if (typeof value === 'object') {\n const obj = value as Record<string, unknown>;\n const keys = Object.keys(obj).filter((k) => obj[k] !== undefined).sort();\n return `{${keys.map((k) => `${JSON.stringify(k)}:${canonicalJson(obj[k])}`).join(',')}}`;\n }\n throw new TypeError(`canonicalJson: unsupported type (${typeof value})`);\n}\n\n/** 32-bit FNV-1a hash of a string. Fast, NOT cryptographic. */\nexport function fnv1a(text: string): number {\n let h = 0x811c9dc5;\n for (let i = 0; i < text.length; i++) {\n h ^= text.charCodeAt(i);\n h = Math.imul(h, 0x01000193);\n }\n return h >>> 0;\n}\n\n/**\n * Fast fingerprint of any serializable state.\n * For cryptographic proofs use `hashValue` from `@mesh2play/trust`.\n */\nexport function hashState(value: unknown): number {\n return fnv1a(canonicalJson(value));\n}\n"],"mappings":";;;AAGO,IAAM,UAAU;;;ACWhB,IAAM,MAAN,MAAM,KAAI;AAAA,EACP;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAGR,YAAY,MAAc;AACxB,SAAK,IAAI;AACT,SAAK,IAAI;AACT,SAAK,IAAI;AACT,SAAK,IAAI,SAAS;AAClB,aAAS,IAAI,GAAG,IAAI,IAAI,IAAK,MAAK,KAAK;AAAA,EACzC;AAAA;AAAA,EAGA,OAAe;AACb,UAAM,KAAO,KAAK,IAAI,KAAK,IAAK,KAAK,KAAK,IAAK;AAC/C,SAAK,IAAK,KAAK,IAAI,IAAK;AACxB,SAAK,IAAI,KAAK,IAAK,KAAK,MAAM;AAC9B,SAAK,IAAK,KAAK,KAAK,KAAK,KAAK,KAAM;AACpC,SAAK,IAAK,KAAK,KAAK,KAAO,KAAK,MAAM;AACtC,SAAK,IAAK,KAAK,IAAI,IAAK;AACxB,WAAO,MAAM;AAAA,EACf;AAAA;AAAA,EAGA,QAAgB;AACd,WAAO,KAAK,KAAK,IAAI;AAAA,EACvB;AAAA;AAAA,EAGA,IAAI,KAAa,KAAqB;AAIpC,QAAI,CAAC,OAAO,SAAS,GAAG,KAAK,CAAC,OAAO,SAAS,GAAG,EAAG,OAAM,IAAI,WAAW,mCAAmC,GAAG,KAAK,GAAG,GAAG;AAC1H,UAAM,KAAK,MAAM,GAAG;AACpB,UAAM,KAAK,MAAM,GAAG;AACpB,QAAI,MAAM,IAAK,EAAC,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG;AACrC,UAAM,QAAQ,MAAM,MAAM;AAC1B,QAAI,SAAS,EAAG,QAAO;AACvB,QAAI,QAAQ,WAAY,OAAM,IAAI,WAAW,iCAAiC;AA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/package.json
CHANGED
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mesh2play/core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Deterministic core of Mesh2Play: seeded RNG, integer math, fixed-step loop, typed events and state hashing.",
|
|
5
|
+
"author": "Serot.Dev",
|
|
6
|
+
"homepage": "https://serot-dev.github.io/mesh2play/packages/core",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/serot-dev/mesh2play.git",
|
|
10
|
+
"directory": "packages/core"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/serot-dev/mesh2play/issues"
|
|
14
|
+
},
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=20"
|
|
18
|
+
},
|
|
19
|
+
"type": "module",
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"README.md"
|
|
32
|
+
],
|
|
33
|
+
"keywords": [
|
|
34
|
+
"gamedev",
|
|
35
|
+
"deterministic",
|
|
36
|
+
"rng",
|
|
37
|
+
"mmo",
|
|
38
|
+
"mesh2play",
|
|
39
|
+
"anchored-mesh",
|
|
40
|
+
"verified-p2p",
|
|
41
|
+
"proof-of-play",
|
|
42
|
+
"p2p",
|
|
43
|
+
"multiplayer",
|
|
44
|
+
"game"
|
|
45
|
+
],
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "tsup --config ../../tsup.config.mjs src/index.ts --format esm --dts --clean --sourcemap",
|
|
48
|
+
"prepack": "node -e \"require('fs').copyFileSync('../../LICENSE','LICENSE')\"",
|
|
49
|
+
"postpack": "node -e \"require('fs').rmSync('LICENSE',{force:true})\""
|
|
50
|
+
}
|
|
51
|
+
}
|