@vuer-ai/vuer-rtc 0.0.1
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/dist/client/EditBuffer.d.ts +43 -0
- package/dist/client/EditBuffer.d.ts.map +1 -0
- package/dist/client/EditBuffer.js +96 -0
- package/dist/client/EditBuffer.js.map +1 -0
- package/dist/client/actions.d.ts +66 -0
- package/dist/client/actions.d.ts.map +1 -0
- package/dist/client/actions.js +345 -0
- package/dist/client/actions.js.map +1 -0
- package/dist/client/createGraph.d.ts +30 -0
- package/dist/client/createGraph.d.ts.map +1 -0
- package/dist/client/createGraph.js +91 -0
- package/dist/client/createGraph.js.map +1 -0
- package/dist/client/hooks.d.ts +81 -0
- package/dist/client/hooks.d.ts.map +1 -0
- package/dist/client/hooks.js +161 -0
- package/dist/client/hooks.js.map +1 -0
- package/dist/client/index.d.ts +8 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +10 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/types.d.ts +74 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +11 -0
- package/dist/client/types.js.map +1 -0
- package/dist/hooks.d.ts +8 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +7 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/operations/OperationTypes.d.ts +239 -0
- package/dist/operations/OperationTypes.d.ts.map +1 -0
- package/dist/operations/OperationTypes.js +10 -0
- package/dist/operations/OperationTypes.js.map +1 -0
- package/dist/operations/OperationValidator.d.ts +32 -0
- package/dist/operations/OperationValidator.d.ts.map +1 -0
- package/dist/operations/OperationValidator.js +208 -0
- package/dist/operations/OperationValidator.js.map +1 -0
- package/dist/operations/apply/array.d.ts +22 -0
- package/dist/operations/apply/array.d.ts.map +1 -0
- package/dist/operations/apply/array.js +64 -0
- package/dist/operations/apply/array.js.map +1 -0
- package/dist/operations/apply/boolean.d.ts +18 -0
- package/dist/operations/apply/boolean.d.ts.map +1 -0
- package/dist/operations/apply/boolean.js +34 -0
- package/dist/operations/apply/boolean.js.map +1 -0
- package/dist/operations/apply/color.d.ts +14 -0
- package/dist/operations/apply/color.d.ts.map +1 -0
- package/dist/operations/apply/color.js +46 -0
- package/dist/operations/apply/color.js.map +1 -0
- package/dist/operations/apply/index.d.ts +18 -0
- package/dist/operations/apply/index.d.ts.map +1 -0
- package/dist/operations/apply/index.js +26 -0
- package/dist/operations/apply/index.js.map +1 -0
- package/dist/operations/apply/node.d.ts +24 -0
- package/dist/operations/apply/node.d.ts.map +1 -0
- package/dist/operations/apply/node.js +77 -0
- package/dist/operations/apply/node.js.map +1 -0
- package/dist/operations/apply/number.d.ts +26 -0
- package/dist/operations/apply/number.d.ts.map +1 -0
- package/dist/operations/apply/number.js +54 -0
- package/dist/operations/apply/number.js.map +1 -0
- package/dist/operations/apply/object.d.ts +14 -0
- package/dist/operations/apply/object.d.ts.map +1 -0
- package/dist/operations/apply/object.js +47 -0
- package/dist/operations/apply/object.js.map +1 -0
- package/dist/operations/apply/quaternion.d.ts +15 -0
- package/dist/operations/apply/quaternion.d.ts.map +1 -0
- package/dist/operations/apply/quaternion.js +33 -0
- package/dist/operations/apply/quaternion.js.map +1 -0
- package/dist/operations/apply/string.d.ts +14 -0
- package/dist/operations/apply/string.d.ts.map +1 -0
- package/dist/operations/apply/string.js +26 -0
- package/dist/operations/apply/string.js.map +1 -0
- package/dist/operations/apply/types.d.ts +34 -0
- package/dist/operations/apply/types.d.ts.map +1 -0
- package/dist/operations/apply/types.js +32 -0
- package/dist/operations/apply/types.js.map +1 -0
- package/dist/operations/apply/vector3.d.ts +18 -0
- package/dist/operations/apply/vector3.d.ts.map +1 -0
- package/dist/operations/apply/vector3.js +44 -0
- package/dist/operations/apply/vector3.js.map +1 -0
- package/dist/operations/dispatcher.d.ts +35 -0
- package/dist/operations/dispatcher.d.ts.map +1 -0
- package/dist/operations/dispatcher.js +107 -0
- package/dist/operations/dispatcher.js.map +1 -0
- package/dist/operations/index.d.ts +10 -0
- package/dist/operations/index.d.ts.map +1 -0
- package/dist/operations/index.js +17 -0
- package/dist/operations/index.js.map +1 -0
- package/dist/state/ConflictResolver.d.ts +36 -0
- package/dist/state/ConflictResolver.d.ts.map +1 -0
- package/dist/state/ConflictResolver.js +167 -0
- package/dist/state/ConflictResolver.js.map +1 -0
- package/dist/state/DType.d.ts +160 -0
- package/dist/state/DType.d.ts.map +1 -0
- package/dist/state/DType.js +282 -0
- package/dist/state/DType.js.map +1 -0
- package/dist/state/Schema.d.ts +32 -0
- package/dist/state/Schema.d.ts.map +1 -0
- package/dist/state/Schema.js +175 -0
- package/dist/state/Schema.js.map +1 -0
- package/dist/state/VectorClock.d.ts +42 -0
- package/dist/state/VectorClock.d.ts.map +1 -0
- package/dist/state/VectorClock.js +84 -0
- package/dist/state/VectorClock.js.map +1 -0
- package/dist/state/index.d.ts +11 -0
- package/dist/state/index.d.ts.map +1 -0
- package/dist/state/index.js +13 -0
- package/dist/state/index.js.map +1 -0
- package/docs/OPERATION_HINTS.md +222 -0
- package/docs/SCENE_GRAPH.md +373 -0
- package/docs/TYPE_BEHAVIORS.md +348 -0
- package/examples/01-basic-usage.ts +139 -0
- package/examples/02-concurrent-edits.ts +208 -0
- package/examples/03-scene-building.ts +258 -0
- package/examples/04-conflict-resolution.ts +339 -0
- package/examples/README.md +86 -0
- package/jest.config.js +19 -0
- package/package.json +57 -0
- package/src/client/EditBuffer.ts +105 -0
- package/src/client/actions.ts +397 -0
- package/src/client/createGraph.ts +132 -0
- package/src/client/hooks.tsx +249 -0
- package/src/client/index.ts +35 -0
- package/src/client/types.ts +94 -0
- package/src/hooks.ts +20 -0
- package/src/index.ts +14 -0
- package/src/operations/OperationTypes.ts +340 -0
- package/src/operations/OperationValidator.ts +260 -0
- package/src/operations/apply/array.ts +84 -0
- package/src/operations/apply/boolean.ts +48 -0
- package/src/operations/apply/color.ts +65 -0
- package/src/operations/apply/index.ts +37 -0
- package/src/operations/apply/node.ts +98 -0
- package/src/operations/apply/number.ts +76 -0
- package/src/operations/apply/object.ts +63 -0
- package/src/operations/apply/quaternion.ts +47 -0
- package/src/operations/apply/string.ts +36 -0
- package/src/operations/apply/types.ts +66 -0
- package/src/operations/apply/vector3.ts +60 -0
- package/src/operations/dispatcher.ts +127 -0
- package/src/operations/index.ts +80 -0
- package/src/state/ConflictResolver.ts +205 -0
- package/src/state/DType.ts +333 -0
- package/src/state/Schema.ts +236 -0
- package/src/state/VectorClock.ts +98 -0
- package/src/state/index.ts +14 -0
- package/tests/client/actions.test.ts +371 -0
- package/tests/client/edit-buffer.test.ts +117 -0
- package/tests/fixtures/array-ops.jsonl +6 -0
- package/tests/fixtures/boolean-ops.jsonl +6 -0
- package/tests/fixtures/color-ops.jsonl +4 -0
- package/tests/fixtures/edit-buffer.jsonl +3 -0
- package/tests/fixtures/node-ops.jsonl +6 -0
- package/tests/fixtures/number-ops.jsonl +7 -0
- package/tests/fixtures/object-ops.jsonl +4 -0
- package/tests/fixtures/operations.jsonl +7 -0
- package/tests/fixtures/string-ops.jsonl +4 -0
- package/tests/fixtures/undo-redo.jsonl +3 -0
- package/tests/fixtures/vector-ops.jsonl +9 -0
- package/tests/operations/collections.test.ts +193 -0
- package/tests/operations/nodes.test.ts +228 -0
- package/tests/operations/primitives.test.ts +222 -0
- package/tests/operations/vectors.test.ts +150 -0
- package/tsconfig.json +21 -0
- package/tsconfig.test.json +9 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for vector operations: vector3, quaternion
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it, expect, beforeEach } from '@jest/globals';
|
|
6
|
+
import { readFileSync } from 'fs';
|
|
7
|
+
import { join, dirname } from 'path';
|
|
8
|
+
import { fileURLToPath } from 'url';
|
|
9
|
+
import { createEmptyGraph, applyMessage } from '../../src/index.js';
|
|
10
|
+
import type { SceneGraph, CRDTMessage, Operation } from '../../src/operations/OperationTypes.js';
|
|
11
|
+
|
|
12
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
|
|
14
|
+
interface OpFixture {
|
|
15
|
+
name: string;
|
|
16
|
+
op: Operation;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function loadOps(filename: string): OpFixture[] {
|
|
20
|
+
const filepath = join(__dirname, '../fixtures', filename);
|
|
21
|
+
const content = readFileSync(filepath, 'utf-8');
|
|
22
|
+
return content
|
|
23
|
+
.trim()
|
|
24
|
+
.split('\n')
|
|
25
|
+
.map((line) => JSON.parse(line));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function createMsg(op: Operation, lamport = 1): CRDTMessage {
|
|
29
|
+
return {
|
|
30
|
+
id: `msg-${Math.random().toString(36).slice(2)}`,
|
|
31
|
+
sessionId: 'test-session',
|
|
32
|
+
clock: { 'test-session': lamport },
|
|
33
|
+
lamportTime: lamport,
|
|
34
|
+
timestamp: Date.now(),
|
|
35
|
+
ops: [op],
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function createNodeWithProps(
|
|
40
|
+
graph: SceneGraph,
|
|
41
|
+
key: string,
|
|
42
|
+
props: Record<string, unknown>
|
|
43
|
+
): SceneGraph {
|
|
44
|
+
const nodeOp: Operation = {
|
|
45
|
+
key: '',
|
|
46
|
+
otype: 'node.insert',
|
|
47
|
+
path: 'children',
|
|
48
|
+
value: {
|
|
49
|
+
key,
|
|
50
|
+
id: `uuid-${key}`,
|
|
51
|
+
tag: 'Mesh',
|
|
52
|
+
name: key,
|
|
53
|
+
...props,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
return applyMessage(graph, createMsg(nodeOp, 0));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
describe('Vector3 Operations', () => {
|
|
60
|
+
let vectorOps: OpFixture[];
|
|
61
|
+
let graph: SceneGraph;
|
|
62
|
+
|
|
63
|
+
beforeEach(() => {
|
|
64
|
+
vectorOps = loadOps('vector-ops.jsonl');
|
|
65
|
+
graph = createEmptyGraph();
|
|
66
|
+
graph = createNodeWithProps(graph, 'node-1', {
|
|
67
|
+
position: [0, 0, 0],
|
|
68
|
+
scale: [1, 1, 1],
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('vector3.set should replace value', () => {
|
|
73
|
+
const op = vectorOps.find((f) => f.name === 'vector3_set')!.op;
|
|
74
|
+
const result = applyMessage(graph, createMsg(op));
|
|
75
|
+
expect(result.nodes['node-1'].position).toEqual([1, 2, 3]);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('vector3.set to zero should work', () => {
|
|
79
|
+
graph = createNodeWithProps(createEmptyGraph(), 'node-1', { position: [5, 5, 5] });
|
|
80
|
+
const op = vectorOps.find((f) => f.name === 'vector3_set_zero')!.op;
|
|
81
|
+
const result = applyMessage(graph, createMsg(op));
|
|
82
|
+
expect(result.nodes['node-1'].position).toEqual([0, 0, 0]);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('vector3.add should add components', () => {
|
|
86
|
+
const op = vectorOps.find((f) => f.name === 'vector3_add')!.op;
|
|
87
|
+
const result = applyMessage(graph, createMsg(op));
|
|
88
|
+
expect(result.nodes['node-1'].position).toEqual([0.5, 0.5, 0.5]);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('vector3.add with negative should subtract', () => {
|
|
92
|
+
graph = createNodeWithProps(createEmptyGraph(), 'node-1', { position: [5, 5, 5] });
|
|
93
|
+
const op = vectorOps.find((f) => f.name === 'vector3_add_negative')!.op;
|
|
94
|
+
const result = applyMessage(graph, createMsg(op));
|
|
95
|
+
expect(result.nodes['node-1'].position).toEqual([4, 4, 4]);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('vector3.multiply should multiply components', () => {
|
|
99
|
+
const op = vectorOps.find((f) => f.name === 'vector3_multiply')!.op;
|
|
100
|
+
const result = applyMessage(graph, createMsg(op));
|
|
101
|
+
expect(result.nodes['node-1'].scale).toEqual([2, 2, 2]);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('vector3.multiply non-uniform should scale each component', () => {
|
|
105
|
+
const op = vectorOps.find((f) => f.name === 'vector3_multiply_non_uniform')!.op;
|
|
106
|
+
const result = applyMessage(graph, createMsg(op));
|
|
107
|
+
expect(result.nodes['node-1'].scale).toEqual([1, 2, 3]);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('vector3.add should accumulate multiple operations', () => {
|
|
111
|
+
const op = vectorOps.find((f) => f.name === 'vector3_add')!.op;
|
|
112
|
+
let result = applyMessage(graph, createMsg(op, 1));
|
|
113
|
+
result = applyMessage(result, createMsg(op, 2));
|
|
114
|
+
result = applyMessage(result, createMsg(op, 3));
|
|
115
|
+
expect(result.nodes['node-1'].position).toEqual([1.5, 1.5, 1.5]);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
describe('Quaternion Operations', () => {
|
|
120
|
+
let vectorOps: OpFixture[];
|
|
121
|
+
let graph: SceneGraph;
|
|
122
|
+
|
|
123
|
+
beforeEach(() => {
|
|
124
|
+
vectorOps = loadOps('vector-ops.jsonl');
|
|
125
|
+
graph = createEmptyGraph();
|
|
126
|
+
graph = createNodeWithProps(graph, 'node-1', {
|
|
127
|
+
rotation: [0, 0, 0, 1], // identity quaternion
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('quaternion.set should replace value', () => {
|
|
132
|
+
const op = vectorOps.find((f) => f.name === 'quaternion_set')!.op;
|
|
133
|
+
const result = applyMessage(graph, createMsg(op));
|
|
134
|
+
expect(result.nodes['node-1'].rotation).toEqual([0, 0, 0, 1]);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('quaternion.set with rotation should work', () => {
|
|
138
|
+
const op = vectorOps.find((f) => f.name === 'quaternion_set_rotated')!.op;
|
|
139
|
+
const result = applyMessage(graph, createMsg(op));
|
|
140
|
+
expect(result.nodes['node-1'].rotation).toEqual([0, 0.7071, 0, 0.7071]);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('quaternion.multiply should compose rotations', () => {
|
|
144
|
+
const op = vectorOps.find((f) => f.name === 'quaternion_multiply')!.op;
|
|
145
|
+
const result = applyMessage(graph, createMsg(op));
|
|
146
|
+
// Result is the composed rotation
|
|
147
|
+
expect(result.nodes['node-1'].rotation).toBeDefined();
|
|
148
|
+
expect(Array.isArray(result.nodes['node-1'].rotation)).toBe(true);
|
|
149
|
+
});
|
|
150
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
"lib": ["ES2023", "DOM"],
|
|
7
|
+
"jsx": "react-jsx",
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"declarationMap": true,
|
|
10
|
+
"sourceMap": true,
|
|
11
|
+
"outDir": "./dist",
|
|
12
|
+
"rootDir": "./src",
|
|
13
|
+
"strict": true,
|
|
14
|
+
"esModuleInterop": true,
|
|
15
|
+
"skipLibCheck": true,
|
|
16
|
+
"forceConsistentCasingInFileNames": true,
|
|
17
|
+
"resolveJsonModule": true
|
|
18
|
+
},
|
|
19
|
+
"include": ["src/**/*"],
|
|
20
|
+
"exclude": ["node_modules", "dist"]
|
|
21
|
+
}
|