@worldmesh/runtime 0.1.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 +79 -0
- package/dist/abilities/abilities.d.ts +9 -0
- package/dist/abilities/abilities.d.ts.map +1 -0
- package/dist/abilities/abilities.js +25 -0
- package/dist/abilities/abilities.js.map +1 -0
- package/dist/camera/cameraRig.d.ts +39 -0
- package/dist/camera/cameraRig.d.ts.map +1 -0
- package/dist/camera/cameraRig.js +88 -0
- package/dist/camera/cameraRig.js.map +1 -0
- package/dist/controls/input.d.ts +64 -0
- package/dist/controls/input.d.ts.map +1 -0
- package/dist/controls/input.js +236 -0
- package/dist/controls/input.js.map +1 -0
- package/dist/controls/keymap.d.ts +8 -0
- package/dist/controls/keymap.d.ts.map +1 -0
- package/dist/controls/keymap.js +21 -0
- package/dist/controls/keymap.js.map +1 -0
- package/dist/controls/touch.d.ts +43 -0
- package/dist/controls/touch.d.ts.map +1 -0
- package/dist/controls/touch.js +329 -0
- package/dist/controls/touch.js.map +1 -0
- package/dist/core/events.d.ts +9 -0
- package/dist/core/events.d.ts.map +1 -0
- package/dist/core/events.js +27 -0
- package/dist/core/events.js.map +1 -0
- package/dist/core/worldmesh.d.ts +10 -0
- package/dist/core/worldmesh.d.ts.map +1 -0
- package/dist/core/worldmesh.js +283 -0
- package/dist/core/worldmesh.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/movement/collision.d.ts +39 -0
- package/dist/movement/collision.d.ts.map +1 -0
- package/dist/movement/collision.js +93 -0
- package/dist/movement/collision.js.map +1 -0
- package/dist/movement/controller.d.ts +53 -0
- package/dist/movement/controller.d.ts.map +1 -0
- package/dist/movement/controller.js +200 -0
- package/dist/movement/controller.js.map +1 -0
- package/dist/net/adapter.d.ts +22 -0
- package/dist/net/adapter.d.ts.map +1 -0
- package/dist/net/adapter.js +8 -0
- package/dist/net/adapter.js.map +1 -0
- package/dist/player/avatar.d.ts +29 -0
- package/dist/player/avatar.d.ts.map +1 -0
- package/dist/player/avatar.js +420 -0
- package/dist/player/avatar.js.map +1 -0
- package/dist/player/player.d.ts +30 -0
- package/dist/player/player.d.ts.map +1 -0
- package/dist/player/player.js +76 -0
- package/dist/player/player.js.map +1 -0
- package/dist/portals/portals.d.ts +34 -0
- package/dist/portals/portals.d.ts.map +1 -0
- package/dist/portals/portals.js +132 -0
- package/dist/portals/portals.js.map +1 -0
- package/dist/types.d.ts +228 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/ui/overlay.d.ts +19 -0
- package/dist/ui/overlay.d.ts.map +1 -0
- package/dist/ui/overlay.js +370 -0
- package/dist/ui/overlay.js.map +1 -0
- package/package.json +63 -0
- package/src/abilities/abilities.ts +30 -0
- package/src/camera/cameraRig.ts +106 -0
- package/src/controls/input.ts +252 -0
- package/src/controls/keymap.ts +23 -0
- package/src/controls/touch.ts +378 -0
- package/src/core/events.ts +31 -0
- package/src/core/worldmesh.ts +313 -0
- package/src/index.ts +46 -0
- package/src/movement/collision.ts +109 -0
- package/src/movement/controller.ts +248 -0
- package/src/net/adapter.ts +28 -0
- package/src/player/avatar.ts +495 -0
- package/src/player/player.ts +91 -0
- package/src/portals/portals.ts +173 -0
- package/src/types.ts +230 -0
- package/src/ui/overlay.ts +398 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { Vector3 } from 'three';
|
|
2
|
+
export const DEFAULT_TUNING = {
|
|
3
|
+
walkSpeed: 5.2,
|
|
4
|
+
sprintSpeed: 9,
|
|
5
|
+
crouchSpeed: 2.4,
|
|
6
|
+
flySpeed: 12,
|
|
7
|
+
jumpSpeed: 7.6,
|
|
8
|
+
gravity: 24,
|
|
9
|
+
groundAccel: 14,
|
|
10
|
+
airAccel: 4,
|
|
11
|
+
dashSpeed: 18,
|
|
12
|
+
dashCooldown: 1.2,
|
|
13
|
+
maxFallSpeed: 55,
|
|
14
|
+
fallLimit: -60,
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The one movement implementation every WorldMesh world shares.
|
|
18
|
+
* Optional capabilities are branches on `abilities` flags, never subclasses:
|
|
19
|
+
* that is what keeps "declare it in config" honest.
|
|
20
|
+
*/
|
|
21
|
+
export class MovementController {
|
|
22
|
+
/** Player feet position in world space. */
|
|
23
|
+
position = new Vector3();
|
|
24
|
+
velocity = new Vector3();
|
|
25
|
+
onGround = false;
|
|
26
|
+
crouching = false;
|
|
27
|
+
flying = false;
|
|
28
|
+
/** Current standing height, shrinks while crouching. */
|
|
29
|
+
currentHeight;
|
|
30
|
+
tuning;
|
|
31
|
+
input;
|
|
32
|
+
collision;
|
|
33
|
+
abilities;
|
|
34
|
+
baseHeight;
|
|
35
|
+
radius;
|
|
36
|
+
jumpsUsed = 0;
|
|
37
|
+
dashCooldown = 0;
|
|
38
|
+
dashTime = 0;
|
|
39
|
+
dashDirection = new Vector3();
|
|
40
|
+
scratch = new Vector3();
|
|
41
|
+
groundProbe = new Vector3();
|
|
42
|
+
constructor(options) {
|
|
43
|
+
this.input = options.input;
|
|
44
|
+
this.collision = options.collision;
|
|
45
|
+
this.abilities = options.abilities;
|
|
46
|
+
this.tuning = { ...DEFAULT_TUNING, ...options.tuning };
|
|
47
|
+
this.baseHeight = options.height;
|
|
48
|
+
this.currentHeight = options.height;
|
|
49
|
+
this.radius = options.radius;
|
|
50
|
+
this.position.copy(options.spawn);
|
|
51
|
+
}
|
|
52
|
+
get height() {
|
|
53
|
+
return this.currentHeight;
|
|
54
|
+
}
|
|
55
|
+
reset(position) {
|
|
56
|
+
this.position.copy(position);
|
|
57
|
+
this.velocity.set(0, 0, 0);
|
|
58
|
+
this.onGround = false;
|
|
59
|
+
this.flying = false;
|
|
60
|
+
this.crouching = false;
|
|
61
|
+
this.jumpsUsed = 0;
|
|
62
|
+
this.dashTime = 0;
|
|
63
|
+
}
|
|
64
|
+
/** Advance one simulation step. `yaw` is the camera heading in radians. */
|
|
65
|
+
step(dt, yaw, controlsEnabled) {
|
|
66
|
+
const axis = controlsEnabled ? this.input.getMoveAxis() : { x: 0, z: 0 };
|
|
67
|
+
this.updateModes(controlsEnabled);
|
|
68
|
+
// Rotate local input into world space using the camera heading.
|
|
69
|
+
const sin = Math.sin(yaw);
|
|
70
|
+
const cos = Math.cos(yaw);
|
|
71
|
+
const wishX = axis.x * cos + axis.z * sin;
|
|
72
|
+
const wishZ = -axis.x * sin + axis.z * cos;
|
|
73
|
+
const speed = this.currentSpeed();
|
|
74
|
+
const targetX = wishX * speed;
|
|
75
|
+
const targetZ = wishZ * speed;
|
|
76
|
+
if (this.flying) {
|
|
77
|
+
this.stepFlying(dt, targetX, targetZ, controlsEnabled);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
this.stepGrounded(dt, targetX, targetZ, controlsEnabled);
|
|
81
|
+
}
|
|
82
|
+
this.stepDash(dt, controlsEnabled, wishX, wishZ, yaw);
|
|
83
|
+
this.applyMotion(dt);
|
|
84
|
+
}
|
|
85
|
+
updateModes(controlsEnabled) {
|
|
86
|
+
if (this.abilities.flying && controlsEnabled && this.input.consume('fly')) {
|
|
87
|
+
this.flying = !this.flying;
|
|
88
|
+
if (this.flying) {
|
|
89
|
+
this.velocity.y = 0;
|
|
90
|
+
this.onGround = false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const wantsCrouch = this.abilities.crouching && controlsEnabled && this.input.isDown('crouch');
|
|
94
|
+
this.crouching = wantsCrouch && !this.flying;
|
|
95
|
+
const targetHeight = this.crouching ? this.baseHeight * 0.55 : this.baseHeight;
|
|
96
|
+
// Smooth so the camera does not snap between eye heights.
|
|
97
|
+
this.currentHeight += (targetHeight - this.currentHeight) * 0.35;
|
|
98
|
+
}
|
|
99
|
+
currentSpeed() {
|
|
100
|
+
const tuning = this.tuning;
|
|
101
|
+
if (this.flying)
|
|
102
|
+
return tuning.flySpeed;
|
|
103
|
+
if (this.crouching)
|
|
104
|
+
return tuning.crouchSpeed;
|
|
105
|
+
return this.input.isDown('sprint') ? tuning.sprintSpeed : tuning.walkSpeed;
|
|
106
|
+
}
|
|
107
|
+
stepGrounded(dt, targetX, targetZ, controlsEnabled) {
|
|
108
|
+
const tuning = this.tuning;
|
|
109
|
+
const accel = this.onGround ? tuning.groundAccel : tuning.airAccel;
|
|
110
|
+
const blend = 1 - Math.exp(-accel * dt);
|
|
111
|
+
this.velocity.x += (targetX - this.velocity.x) * blend;
|
|
112
|
+
this.velocity.z += (targetZ - this.velocity.z) * blend;
|
|
113
|
+
this.velocity.y -= tuning.gravity * dt;
|
|
114
|
+
if (this.velocity.y < -tuning.maxFallSpeed)
|
|
115
|
+
this.velocity.y = -tuning.maxFallSpeed;
|
|
116
|
+
if (controlsEnabled && this.input.consume('jump')) {
|
|
117
|
+
const maxJumps = this.abilities.doubleJump ? 2 : 1;
|
|
118
|
+
if (this.onGround) {
|
|
119
|
+
this.velocity.y = tuning.jumpSpeed;
|
|
120
|
+
this.jumpsUsed = 1;
|
|
121
|
+
this.onGround = false;
|
|
122
|
+
}
|
|
123
|
+
else if (this.jumpsUsed < maxJumps) {
|
|
124
|
+
this.velocity.y = tuning.jumpSpeed * 0.9;
|
|
125
|
+
this.jumpsUsed++;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
stepFlying(dt, targetX, targetZ, controlsEnabled) {
|
|
130
|
+
const blend = 1 - Math.exp(-this.tuning.groundAccel * dt);
|
|
131
|
+
this.velocity.x += (targetX - this.velocity.x) * blend;
|
|
132
|
+
this.velocity.z += (targetZ - this.velocity.z) * blend;
|
|
133
|
+
const up = controlsEnabled && this.input.isDown('jump') ? 1 : 0;
|
|
134
|
+
const down = controlsEnabled && this.abilities.crouching && this.input.isDown('crouch') ? 1 : 0;
|
|
135
|
+
const targetY = (up - down) * this.tuning.flySpeed;
|
|
136
|
+
this.velocity.y += (targetY - this.velocity.y) * blend;
|
|
137
|
+
this.onGround = false;
|
|
138
|
+
}
|
|
139
|
+
stepDash(dt, controlsEnabled, wishX, wishZ, yaw) {
|
|
140
|
+
if (!this.abilities.dash)
|
|
141
|
+
return;
|
|
142
|
+
this.dashCooldown = Math.max(0, this.dashCooldown - dt);
|
|
143
|
+
if (controlsEnabled && this.input.consume('dash') && this.dashCooldown === 0) {
|
|
144
|
+
// Dash along the input direction, or straight ahead when standing still.
|
|
145
|
+
if (wishX === 0 && wishZ === 0) {
|
|
146
|
+
this.dashDirection.set(-Math.sin(yaw), 0, -Math.cos(yaw));
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
this.dashDirection.set(wishX, 0, wishZ).normalize();
|
|
150
|
+
}
|
|
151
|
+
this.dashTime = 0.18;
|
|
152
|
+
this.dashCooldown = this.tuning.dashCooldown;
|
|
153
|
+
}
|
|
154
|
+
if (this.dashTime > 0) {
|
|
155
|
+
this.dashTime = Math.max(0, this.dashTime - dt);
|
|
156
|
+
this.velocity.x = this.dashDirection.x * this.tuning.dashSpeed;
|
|
157
|
+
this.velocity.z = this.dashDirection.z * this.tuning.dashSpeed;
|
|
158
|
+
if (!this.flying && this.velocity.y < 0)
|
|
159
|
+
this.velocity.y = 0;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
applyMotion(dt) {
|
|
163
|
+
const horizontal = this.scratch.set(this.velocity.x * dt, 0, this.velocity.z * dt);
|
|
164
|
+
const resolved = this.collision.resolveHorizontal(this.position, horizontal, this.radius, this.currentHeight);
|
|
165
|
+
// Feed the resolved slide back into velocity so we do not keep pushing
|
|
166
|
+
// into a wall and accelerating along it.
|
|
167
|
+
if (dt > 0) {
|
|
168
|
+
this.velocity.x = resolved.x / dt;
|
|
169
|
+
this.velocity.z = resolved.z / dt;
|
|
170
|
+
}
|
|
171
|
+
this.position.x += resolved.x;
|
|
172
|
+
this.position.z += resolved.z;
|
|
173
|
+
const previousY = this.position.y;
|
|
174
|
+
this.position.y += this.velocity.y * dt;
|
|
175
|
+
// Sample from where the feet *were*, and look down far enough to cover the
|
|
176
|
+
// distance just fallen. Sampling from the new position would miss the floor
|
|
177
|
+
// on the frame the player crosses it and drop them through the world.
|
|
178
|
+
const fallDistance = Math.max(0, previousY - this.position.y);
|
|
179
|
+
const stepHeight = this.onGround ? 0.6 : 0.05;
|
|
180
|
+
this.groundProbe.set(this.position.x, previousY, this.position.z);
|
|
181
|
+
const ground = this.collision.sampleGround(this.groundProbe, stepHeight, fallDistance + 4);
|
|
182
|
+
if (this.flying) {
|
|
183
|
+
if (this.position.y < ground.y) {
|
|
184
|
+
this.position.y = ground.y;
|
|
185
|
+
this.velocity.y = Math.max(0, this.velocity.y);
|
|
186
|
+
}
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (this.position.y <= ground.y + 1e-3 && this.velocity.y <= 0) {
|
|
190
|
+
this.position.y = ground.y;
|
|
191
|
+
this.velocity.y = 0;
|
|
192
|
+
this.onGround = true;
|
|
193
|
+
this.jumpsUsed = 0;
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
this.onGround = false;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../src/movement/controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAKhC,MAAM,CAAC,MAAM,cAAc,GAAmB;IAC5C,SAAS,EAAE,GAAG;IACd,WAAW,EAAE,CAAC;IACd,WAAW,EAAE,GAAG;IAChB,QAAQ,EAAE,EAAE;IACZ,SAAS,EAAE,GAAG;IACd,OAAO,EAAE,EAAE;IACX,WAAW,EAAE,EAAE;IACf,QAAQ,EAAE,CAAC;IACX,SAAS,EAAE,EAAE;IACb,YAAY,EAAE,GAAG;IACjB,YAAY,E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AAI,CAAC,QAAQ,GAAG,IAAI,CAAC;YACrB,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;QACrB,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACxB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { NetworkAdapter, PlayerState } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Multiplayer is intentionally NOT implemented. This file exists to pin down
|
|
4
|
+
* the seam so the runtime stays easy to network later:
|
|
5
|
+
*
|
|
6
|
+
* - the local player is simulated from serializable `PlayerState`, so a peer's
|
|
7
|
+
* state can drive an identical avatar with no movement-code changes;
|
|
8
|
+
* - the runtime exposes `update(dt)` separately from rendering, so a fixed
|
|
9
|
+
* network tick can drive it;
|
|
10
|
+
* - nothing in movement/camera/portals reaches for a global connection.
|
|
11
|
+
*
|
|
12
|
+
* Expected eventual topologies, in order of how much WorldMesh has to host:
|
|
13
|
+
* 1. peer-to-peer WebRTC, worlds exchange state directly;
|
|
14
|
+
* 2. a multiplayer server run by the world's own creator;
|
|
15
|
+
* 3. optional WorldMesh signaling/discovery only (no game traffic);
|
|
16
|
+
* 4. an optional hosted fallback, last resort.
|
|
17
|
+
*/
|
|
18
|
+
export type { NetworkAdapter, PlayerState };
|
|
19
|
+
/** Round trip a player state over the wire. Kept tiny on purpose. */
|
|
20
|
+
export declare function serializePlayerState(state: PlayerState): string;
|
|
21
|
+
export declare function deserializePlayerState(payload: string): PlayerState;
|
|
22
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/net/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/D;;;;;;;;;;;;;;;GAeG;AACH,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,CAAC;AAE5C,qEAAqE;AACrE,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAE/D;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,CAEnE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Round trip a player state over the wire. Kept tiny on purpose. */
|
|
2
|
+
export function serializePlayerState(state) {
|
|
3
|
+
return JSON.stringify(state);
|
|
4
|
+
}
|
|
5
|
+
export function deserializePlayerState(payload) {
|
|
6
|
+
return JSON.parse(payload);
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../src/net/adapter.ts"],"names":[],"mappings":"AAoBA,qEAAqE;AACrE,MAAM,UAAU,oBAAoB,CAAC,KAAkB;IACrD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,OAAe;IACpD,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAgB,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Group, type Object3D } from 'three';
|
|
2
|
+
/** Faces the default figure can pull, in number-key order (1–9, then 0). */
|
|
3
|
+
export declare const AVATAR_EXPRESSIONS: readonly ["smile", "grin", "laugh", "wink", "love", "surprised", "sad", "angry", "sleepy", "neutral"];
|
|
4
|
+
export type AvatarExpression = (typeof AVATAR_EXPRESSIONS)[number];
|
|
5
|
+
/** The expression bound to a number key: 1 is the first, 0 the tenth. */
|
|
6
|
+
export declare function expressionForDigit(digit: number): AvatarExpression | null;
|
|
7
|
+
export declare function isAvatarExpression(value: unknown): value is AvatarExpression;
|
|
8
|
+
export interface AvatarMotion {
|
|
9
|
+
dt: number;
|
|
10
|
+
/** Horizontal speed in metres per second. */
|
|
11
|
+
speed: number;
|
|
12
|
+
grounded: boolean;
|
|
13
|
+
/** Direction of travel as a yaw, used to turn the body in third person. */
|
|
14
|
+
heading?: number;
|
|
15
|
+
}
|
|
16
|
+
export declare function createDefaultAvatar(height?: number): Group;
|
|
17
|
+
/**
|
|
18
|
+
* Change the face of an avatar made by `createDefaultAvatar`. Unknown names
|
|
19
|
+
* and custom avatars are ignored.
|
|
20
|
+
*/
|
|
21
|
+
export declare function setAvatarExpression(avatar: Object3D, expression: string): void;
|
|
22
|
+
export declare function getAvatarExpression(avatar: Object3D): AvatarExpression | null;
|
|
23
|
+
/**
|
|
24
|
+
* Swing the limbs of an avatar made by `createDefaultAvatar`. Call once per
|
|
25
|
+
* frame with how fast it is moving; anything else is ignored, so it is safe
|
|
26
|
+
* to call on custom avatars too.
|
|
27
|
+
*/
|
|
28
|
+
export declare function animateDefaultAvatar(avatar: Object3D, motion: AvatarMotion): void;
|
|
29
|
+
//# sourceMappingURL=avatar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"avatar.d.ts","sourceRoot":"","sources":["../../src/player/avatar.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,EAYL,KAAK,QAAQ,EACd,MAAM,OAAO,CAAC;AAaf,4EAA4E;AAC5E,eAAO,MAAM,kBAAkB,uGAWrB,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnE,yEAAyE;AACzE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI,CAGzE;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,gBAAgB,CAE5E;AAmBD,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,6CAA6C;IAC7C,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,CAAC;IAClB,2EAA2E;IAC3E,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAOD,wBAAgB,mBAAmB,CAAC,MAAM,SAAM,GAAG,KAAK,CA0FvD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAK9E;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,QAAQ,GAAG,gBAAgB,GAAG,IAAI,CAG7E;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CA6BjF"}
|