@mml-io/networked-dom-document 0.17.1 → 0.18.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/build/index.d.ts +1 -1
- package/build/index.js +47 -41
- package/build/index.js.map +3 -3
- package/build/rfc6902/index.d.ts +2 -2
- package/package.json +6 -6
package/build/index.d.ts
CHANGED
package/build/index.js
CHANGED
|
@@ -1,3 +1,38 @@
|
|
|
1
|
+
// src/rfc6902/deepEqual.ts
|
|
2
|
+
function deepEqual(a, b) {
|
|
3
|
+
if (a === b) {
|
|
4
|
+
return true;
|
|
5
|
+
}
|
|
6
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
7
|
+
if (a.length !== b.length) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
return a.every((elem, index) => {
|
|
11
|
+
return deepEqual(elem, b[index]);
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
if (typeof a === "object" && typeof b === "object" && a !== null && b !== null) {
|
|
15
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
const keys1 = Object.keys(a);
|
|
19
|
+
const keys2 = Object.keys(b);
|
|
20
|
+
if (keys1.length !== keys2.length || !keys1.every((key) => keys2.includes(key))) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
for (const key in a) {
|
|
24
|
+
if (!deepEqual(a[key], b[key])) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (keys1.length === 0 && a instanceof Date && b instanceof Date) {
|
|
29
|
+
return a.getTime() === b.getTime();
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
1
36
|
// src/rfc6902/pointer.ts
|
|
2
37
|
function unescape(token) {
|
|
3
38
|
return token.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
@@ -14,8 +49,7 @@ var Pointer = class _Pointer {
|
|
|
14
49
|
*/
|
|
15
50
|
static fromJSON(path) {
|
|
16
51
|
const tokens = path.split("/").map(unescape);
|
|
17
|
-
if (tokens[0] !== "")
|
|
18
|
-
throw new Error(`Invalid JSON Pointer: ${path}`);
|
|
52
|
+
if (tokens[0] !== "") throw new Error(`Invalid JSON Pointer: ${path}`);
|
|
19
53
|
return new _Pointer(tokens);
|
|
20
54
|
}
|
|
21
55
|
toString() {
|
|
@@ -67,41 +101,6 @@ var Pointer = class _Pointer {
|
|
|
67
101
|
}
|
|
68
102
|
};
|
|
69
103
|
|
|
70
|
-
// src/rfc6902/deepEqual.ts
|
|
71
|
-
function deepEqual(a, b) {
|
|
72
|
-
if (a === b) {
|
|
73
|
-
return true;
|
|
74
|
-
}
|
|
75
|
-
if (Array.isArray(a) && Array.isArray(b)) {
|
|
76
|
-
if (a.length !== b.length) {
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
return a.every((elem, index) => {
|
|
80
|
-
return deepEqual(elem, b[index]);
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
if (typeof a === "object" && typeof b === "object" && a !== null && b !== null) {
|
|
84
|
-
if (Array.isArray(a) || Array.isArray(b)) {
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
const keys1 = Object.keys(a);
|
|
88
|
-
const keys2 = Object.keys(b);
|
|
89
|
-
if (keys1.length !== keys2.length || !keys1.every((key) => keys2.includes(key))) {
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
for (const key in a) {
|
|
93
|
-
if (!deepEqual(a[key], b[key])) {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (keys1.length === 0 && a instanceof Date && b instanceof Date) {
|
|
98
|
-
return a.getTime() === b.getTime();
|
|
99
|
-
}
|
|
100
|
-
return true;
|
|
101
|
-
}
|
|
102
|
-
return false;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
104
|
// src/rfc6902/util.ts
|
|
106
105
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
107
106
|
function objectType(object) {
|
|
@@ -231,8 +230,7 @@ function diffArrays(input, output, ptr, diff = diffAny) {
|
|
|
231
230
|
for (let i = 0; i <= input_end; i++) {
|
|
232
231
|
for (let j = 0; j <= output_end; j++) {
|
|
233
232
|
let memoized = memo[i][j];
|
|
234
|
-
if (memoized)
|
|
235
|
-
continue;
|
|
233
|
+
if (memoized) continue;
|
|
236
234
|
const add_prev_key = `${i},${j - 1}`;
|
|
237
235
|
const remove_prev_key = `${i - 1},${j}`;
|
|
238
236
|
const replace_prev_key = `${i - 1},${j - 1}`;
|
|
@@ -762,6 +760,10 @@ function virtualDOMDiffToVirtualDOMMutationRecord(virtualStructure, domDiff) {
|
|
|
762
760
|
const node = nodePointer.get(virtualStructure);
|
|
763
761
|
let previousSibling = null;
|
|
764
762
|
if (lastToken === "-") {
|
|
763
|
+
if (node.childNodes.length > 0) {
|
|
764
|
+
previousSibling = node.childNodes[node.childNodes.length - 1];
|
|
765
|
+
} else {
|
|
766
|
+
}
|
|
765
767
|
} else {
|
|
766
768
|
const index = parseInt(lastToken, 10);
|
|
767
769
|
if (index === 0) {
|
|
@@ -1195,7 +1197,11 @@ var _NetworkedDOM = class _NetworkedDOM {
|
|
|
1195
1197
|
if (parentNodeId === void 0) {
|
|
1196
1198
|
throw new Error("Parent node ID not found");
|
|
1197
1199
|
}
|
|
1198
|
-
|
|
1200
|
+
const node = this.nodeIdToNode.get(parentNodeId);
|
|
1201
|
+
if (!node) {
|
|
1202
|
+
throw new Error("Parent node not found:" + parentNodeId);
|
|
1203
|
+
}
|
|
1204
|
+
return node;
|
|
1199
1205
|
}
|
|
1200
1206
|
registerWebsocket(webSocket, existingConnectionId = null) {
|
|
1201
1207
|
let connectionId;
|
|
@@ -1213,7 +1219,7 @@ var _NetworkedDOM = class _NetworkedDOM {
|
|
|
1213
1219
|
try {
|
|
1214
1220
|
parsed = JSON.parse(string);
|
|
1215
1221
|
} catch (e) {
|
|
1216
|
-
console.error(`Error parsing message from websocket: ${string}
|
|
1222
|
+
console.error(`Error parsing message from websocket: ${string}`, e);
|
|
1217
1223
|
console.trace();
|
|
1218
1224
|
return;
|
|
1219
1225
|
}
|
package/build/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/rfc6902/
|
|
4
|
-
"sourcesContent": ["/**\nUnescape token part of a JSON Pointer string\n\n`token` should *not* contain any '/' characters.\n\n> Evaluation of each reference token begins by decoding any escaped\n> character sequence. This is performed by first transforming any\n> occurrence of the sequence '~1' to '/', and then transforming any\n> occurrence of the sequence '~0' to '~'. By performing the\n> substitutions in this order, an implementation avoids the error of\n> turning '~01' first into '~1' and then into '/', which would be\n> incorrect (the string '~01' correctly becomes '~1' after\n> transformation).\n\nHere's my take:\n\n~1 is unescaped with higher priority than ~0 because it is a lower-order escape character.\nI say \"lower order\" because '/' needs escaping due to the JSON Pointer serialization technique.\nWhereas, '~' is escaped because escaping '/' uses the '~' character.\n*/\nfunction unescape(token: string): string {\n return token.replace(/~1/g, \"/\").replace(/~0/g, \"~\");\n}\n\n/** Escape token part of a JSON Pointer string\n\n> '~' needs to be encoded as '~0' and '/'\n> needs to be encoded as '~1' when these characters appear in a\n> reference token.\n\nThis is the exact inverse of `unescape()`, so the reverse replacements must take place in reverse order.\n*/\nfunction escape(token: string): string {\n return token.replace(/~/g, \"~0\").replace(/\\//g, \"~1\");\n}\n\nexport interface PointerEvaluation {\n parent: any;\n key: string;\n value: any;\n}\n\n/**\nJSON Pointer representation\n*/\nexport class Pointer {\n constructor(public tokens = [\"\"]) {}\n /**\n `path` *must* be a properly escaped string.\n */\n static fromJSON(path: string): Pointer {\n const tokens = path.split(\"/\").map(unescape);\n if (tokens[0] !== \"\") throw new Error(`Invalid JSON Pointer: ${path}`);\n return new Pointer(tokens);\n }\n toString(): string {\n return this.tokens.map(escape).join(\"/\");\n }\n /**\n Returns an object with 'parent', 'key', and 'value' properties.\n In the special case that this Pointer's path == \"\",\n this object will be {parent: null, key: '', value: object}.\n Otherwise, parent and key will have the property such that parent[key] == value.\n */\n evaluate(object: any): PointerEvaluation {\n let parent: any = null;\n let key = \"\";\n let value = object;\n for (let i = 1, l = this.tokens.length; i < l; i++) {\n parent = value;\n key = this.tokens[i];\n if (key === \"__proto__\" || key === \"constructor\" || key === \"prototype\") {\n continue;\n }\n // not sure if this the best way to handle non-existant paths...\n value = (parent || {})[key];\n }\n return { parent, key, value };\n }\n get(object: any): any {\n return this.evaluate(object).value;\n }\n set(object: any, value: any): void {\n let cursor: any = object;\n for (let i = 1, l = this.tokens.length - 1, token = this.tokens[i]; i < l; i++) {\n // not sure if this the best way to handle non-existant paths...\n cursor = (cursor || {})[token];\n }\n if (cursor) {\n cursor[this.tokens[this.tokens.length - 1]] = value;\n }\n }\n push(token: string): void {\n // mutable\n this.tokens.push(token);\n }\n /**\n `token` should be a String. It'll be coerced to one anyway.\n\n immutable (shallowly)\n */\n add(token: string): Pointer {\n const tokens = this.tokens.concat(String(token));\n return new Pointer(tokens);\n }\n}\n", "export function deepEqual(a: any, b: any): boolean {\n if (a === b) {\n return true;\n }\n\n if (Array.isArray(a) && Array.isArray(b)) {\n if (a.length !== b.length) {\n return false;\n }\n\n return a.every((elem, index) => {\n return deepEqual(elem, b[index]);\n });\n }\n\n if (typeof a === \"object\" && typeof b === \"object\" && a !== null && b !== null) {\n if (Array.isArray(a) || Array.isArray(b)) {\n return false;\n }\n\n const keys1 = Object.keys(a);\n const keys2 = Object.keys(b);\n if (keys1.length !== keys2.length || !keys1.every((key) => keys2.includes(key))) {\n return false;\n }\n\n for (const key in a) {\n if (!deepEqual(a[key], b[key])) {\n return false;\n }\n }\n\n if (keys1.length === 0 && a instanceof Date && b instanceof Date) {\n // Only need to check the length of 1 as they are already known to be equal\n return a.getTime() === b.getTime();\n }\n\n return true;\n }\n return false;\n}\n", "export const hasOwnProperty = Object.prototype.hasOwnProperty;\n\nexport function objectType(object: any) {\n if (object === undefined) {\n return \"undefined\";\n }\n if (object === null) {\n return \"null\";\n }\n if (Array.isArray(object)) {\n return \"array\";\n }\n return typeof object;\n}\n\nfunction isNonPrimitive(value: any): value is object {\n // loose-equality checking for null is faster than strict checking for each of null/undefined/true/false\n // checking null first, then calling typeof, is faster than vice-versa\n return value != null && typeof value === \"object\";\n}\n\n/**\nRecursively copy a value.\n\n@param source - should be a JavaScript primitive, Array, Date, or (plain old) Object.\n@returns copy of source where every Array and Object have been recursively\n reconstructed from their constituent elements\n*/\nexport function clone<T>(source: T): T {\n if (!isNonPrimitive(source)) {\n // short-circuiting is faster than a single return\n return source;\n }\n // x.constructor == Array is the fastest way to check if x is an Array\n if (Array.isArray(source)) {\n // construction via imperative for-loop is faster than source.map(arrayVsObject)\n const length = (source as Array<any>).length;\n // setting the Array length during construction is faster than just `[]` or `new Array()`\n const arrayTarget: any = new Array(length);\n for (let i = 0; i < length; i++) {\n arrayTarget[i] = clone(source[i]);\n }\n return arrayTarget;\n }\n // Date\n if (source.constructor === Date) {\n const dateTarget: any = new Date(+source);\n return dateTarget;\n }\n // Object\n const objectTarget: any = {};\n // declaring the variable (with const) inside the loop is faster\n for (const key in source) {\n // hasOwnProperty costs a bit of performance, but it's semantically necessary\n // using a global helper is MUCH faster than calling source.hasOwnProperty(key)\n if (hasOwnProperty.call(source, key)) {\n objectTarget[key] = clone(source[key]);\n }\n }\n return objectTarget;\n}\n", "import { deepEqual } from \"./deepEqual\";\nimport { Pointer } from \"./pointer\"; // we only need this for type inference\nimport { hasOwnProperty, objectType } from \"./util\";\n\n/**\nAll diff* functions should return a list of operations, often empty.\n\nEach operation should be an object with two to four fields:\n* `op`: the name of the operation; one of \"add\", \"remove\", \"replace\", \"move\",\n \"copy\", or \"test\".\n* `path`: a JSON pointer string\n* `from`: a JSON pointer string\n* `value`: a JSON value\n\nThe different operations have different arguments.\n* \"add\": [`path`, `value`]\n* \"remove\": [`path`]\n* \"replace\": [`path`, `value`]\n* \"move\": [`from`, `path`]\n* \"copy\": [`from`, `path`]\n* \"test\": [`path`, `value`]\n\nCurrently this only really differentiates between Arrays, Objects, and\nEverything Else, which is pretty much just what JSON substantially\ndifferentiates between.\n*/\n\nexport interface AddOperation {\n op: \"add\";\n path: string;\n value: any;\n}\nexport interface RemoveOperation {\n op: \"remove\";\n path: string;\n}\nexport interface ReplaceOperation {\n op: \"replace\";\n path: string;\n value: any;\n}\nexport interface MoveOperation {\n op: \"move\";\n from: string;\n path: string;\n}\nexport interface CopyOperation {\n op: \"copy\";\n from: string;\n path: string;\n}\nexport interface TestOperation {\n op: \"test\";\n path: string;\n value: any;\n}\n\nexport type Operation =\n | AddOperation\n | RemoveOperation\n | ReplaceOperation\n | MoveOperation\n | CopyOperation\n | TestOperation;\n\nexport function isDestructive({ op }: Operation): boolean {\n return op === \"remove\" || op === \"replace\" || op === \"copy\" || op === \"move\";\n}\n\nexport type Diff = (input: any, output: any, ptr: Pointer) => Operation[];\n/**\nVoidableDiff exists to allow the user to provide a partial diff(...) function,\nfalling back to the built-in diffAny(...) function if the user-provided function\nreturns void.\n*/\nexport type VoidableDiff = (input: any, output: any, ptr: Pointer) => Operation[] | void;\n\nfunction wrapVoidableDiff(diff: VoidableDiff): Diff {\n function wrappedDiff(input: any, output: any, ptr: Pointer): Operation[] {\n const custom_patch = diff(input, output, ptr);\n // ensure an array is always returned\n return Array.isArray(custom_patch) ? custom_patch : diffAny(input, output, ptr, wrappedDiff);\n }\n return wrappedDiff;\n}\n\n/**\n Create a test operation based on `input`'s current evaluation of the JSON\n Pointer `path`; if such a pointer cannot be resolved, returns undefined.\n */\nfunction createTest(input: any, path: string): TestOperation | undefined {\n const endpoint = Pointer.fromJSON(path).evaluate(input);\n if (endpoint !== undefined) {\n return { op: \"test\", path, value: endpoint.value };\n }\n}\n\n/**\n Produce an 'application/json-patch+json'-type list of tests, to verify that\n existing values in an object are identical to the those captured at some\n checkpoint (whenever this function is called).\n\n This does not alter `input` or `output` unless they have a property getter with\n side-effects (which is not a good idea anyway).\n\n Returns list of test operations.\n */\nexport function createTests(input: any, patch: Operation[]): TestOperation[] {\n const tests = new Array<TestOperation>();\n patch.filter(isDestructive).forEach((operation) => {\n const pathTest = createTest(input, operation.path);\n if (pathTest) tests.push(pathTest);\n if (\"from\" in operation) {\n const fromTest = createTest(input, operation.from);\n if (fromTest) tests.push(fromTest);\n }\n });\n return tests;\n}\n\n/**\n Produce a 'application/json-patch+json'-type patch to get from one object to\n another.\n\n This does not alter `input` or `output` unless they have a property getter with\n side-effects (which is not a good idea anyway).\n\n `diff` is called on each pair of comparable non-primitive nodes in the\n `input`/`output` object trees, producing nested patches. Return `undefined`\n to fall back to default behaviour.\n\n Returns list of operations to perform on `input` to produce `output`.\n */\nexport function createPatch(input: any, output: any, diff?: VoidableDiff): Operation[] {\n const ptr = new Pointer();\n // a new Pointer gets a default path of [''] if not specified\n return (diff ? wrapVoidableDiff(diff) : diffAny)(input, output, ptr);\n}\n\n/**\nList the keys in `minuend` that are not in `subtrahend`.\n\nA key is only considered if it is both 1) an own-property (o.hasOwnProperty(k))\nof the object, and 2) has a value that is not undefined. This is to match JSON\nsemantics, where JSON object serialization drops keys with undefined values.\n\n@param minuend Object of interest\n@param subtrahend Object of comparison\n@returns Array of keys that are in `minuend` but not in `subtrahend`.\n*/\nexport function subtract(\n minuend: { [index: string]: any },\n subtrahend: { [index: string]: any },\n): string[] {\n // initialize empty object; we only care about the keys, the values can be anything\n const obj: { [index: string]: number } = {};\n // build up obj with all the properties of minuend\n for (const add_key in minuend) {\n if (hasOwnProperty.call(minuend, add_key) && minuend[add_key] !== undefined) {\n obj[add_key] = 1;\n }\n }\n // now delete all the properties of subtrahend from obj\n // (deleting a missing key has no effect)\n for (const del_key in subtrahend) {\n if (hasOwnProperty.call(subtrahend, del_key) && subtrahend[del_key] !== undefined) {\n delete obj[del_key];\n }\n }\n // finally, extract whatever keys remain in obj\n return Object.keys(obj);\n}\n\n/**\nList the keys that shared by all `objects`.\n\nThe semantics of what constitutes a \"key\" is described in {@link subtract}.\n\n@param objects Array of objects to compare\n@returns Array of keys that are in (\"own-properties\" of) every object in `objects`.\n*/\nexport function intersection(objects: ArrayLike<{ [index: string]: any }>): string[] {\n const length = objects.length;\n // prepare empty counter to keep track of how many objects each key occurred in\n const counter: { [index: string]: number } = {};\n // go through each object and increment the counter for each key in that object\n for (let i = 0; i < length; i++) {\n const object = objects[i];\n for (const key in object) {\n if (hasOwnProperty.call(object, key) && object[key] !== undefined) {\n counter[key] = (counter[key] || 0) + 1;\n }\n }\n }\n // now delete all keys from the counter that were not seen in every object\n for (const key in counter) {\n if (counter[key] < length) {\n delete counter[key];\n }\n }\n // finally, extract whatever keys remain in the counter\n return Object.keys(counter);\n}\n\ninterface ArrayAdd {\n op: \"add\";\n index: number;\n value: any;\n}\ninterface ArrayRemove {\n op: \"remove\";\n index: number;\n}\ninterface ArrayReplace {\n op: \"replace\";\n index: number;\n original: any;\n value: any;\n}\n/** These are not proper Operation objects, but will be converted into\nOperation objects eventually. {index} indicates the actual target position,\nnever 'end-of-array' */\ntype ArrayOperation = ArrayAdd | ArrayRemove | ArrayReplace;\nfunction isArrayAdd(array_operation: ArrayOperation): array_operation is ArrayAdd {\n return array_operation.op === \"add\";\n}\nfunction isArrayRemove(array_operation: ArrayOperation): array_operation is ArrayRemove {\n return array_operation.op === \"remove\";\n}\n\ninterface DynamicAlternative {\n /**\n * track prev key position for less memory usage\n */\n prev: string | null;\n operation: ArrayOperation | null;\n /**\n cost indicates the total cost of getting to this position.\n */\n cost: number;\n}\n\nfunction buildOperations(memo: Array<Array<DynamicAlternative>>, i: number, j: number) {\n let memoized: DynamicAlternative = memo[i][j];\n if (!memoized) {\n throw new Error(\"invalid memo\");\n }\n const operations: ArrayOperation[] = [];\n while (memoized && memoized.prev && memoized.operation) {\n operations.push(memoized.operation);\n const index = memoized.prev.split(\",\");\n memoized = memo[Number(index[0])][Number(index[1])];\n }\n return operations.reverse();\n}\n\n/**\nCalculate the shortest sequence of operations to get from `input` to `output`,\nusing a dynamic programming implementation of the Levenshtein distance algorithm.\n\nTo get from the input ABC to the output AZ we could just delete all the input\nand say \"insert A, insert Z\" and be done with it. That's what we do if the\ninput is empty. But we can be smarter.\n\n output\n A Z\n - -\n [0] 1 2\ninput A | 1 [0] 1\n B | 2 [1] 1\n C | 3 2 [2]\n\n1) start at 0,0 (+0)\n2) keep A (+0)\n3) remove B (+1)\n4) replace C with Z (+1)\n\nIf the `input` (source) is empty, they'll all be in the top row, resulting in an\narray of 'add' operations.\nIf the `output` (target) is empty, everything will be in the left column,\nresulting in an array of 'remove' operations.\n\n@returns A list of add/remove/replace operations.\n*/\nexport function diffArrays<T>(\n input: T[],\n output: T[],\n ptr: Pointer,\n diff: Diff = diffAny,\n): Operation[] {\n if (diff === void 0) {\n diff = diffAny;\n }\n // set up cost matrix (very simple initialization: just a map)\n const input_length = isNaN(input.length) || input.length <= 0 ? 0 : input.length;\n const output_length = isNaN(output.length) || output.length <= 0 ? 0 : output.length;\n let input_end = input_length;\n let output_end = output_length;\n while (input_end > 0 && output_end > 0) {\n // accelerate same arrays\n if (deepEqual(input[input_end - 1], output[output_end - 1])) {\n input_end--;\n output_end--;\n } else {\n break;\n }\n }\n const memo: Array<Array<DynamicAlternative>> = new Array(input_end + 1);\n for (let i = 0; i <= input_end; i++) {\n memo[i] = new Array(output_end + 1);\n }\n memo[0][0] = { prev: null, operation: null, cost: 0 };\n /**\n Calculate the cheapest sequence of operations required to get from\n input.slice(0, i) to output.slice(0, j).\n There may be other valid sequences with the same cost, but none cheaper.\n\n @param i The row in the layout above\n @param j The column in the layout above\n @returns An object containing a list of operations, along with the total cost\n of applying them (+1 for each add/remove/replace operation)\n */\n // handle weird objects masquerading as Arrays that don't have proper length\n // properties by using 0 for everything but positive numbers\n for (let i = 0; i <= input_end; i++) {\n for (let j = 0; j <= output_end; j++) {\n let memoized = memo[i][j];\n if (memoized) continue;\n const add_prev_key = `${i},${j - 1}`;\n const remove_prev_key = `${i - 1},${j}`;\n const replace_prev_key = `${i - 1},${j - 1}`;\n const remove_operation: ArrayRemove = {\n op: \"remove\",\n index: i - 1,\n };\n const add_operation: ArrayAdd = {\n op: \"add\",\n index: i - 1,\n value: output[j - 1],\n };\n\n if (j === 0) {\n memoized = {\n prev: remove_prev_key,\n operation: remove_operation,\n cost: memo[i - 1][j].cost + 1,\n };\n } else if (i === 0) {\n memoized = { prev: add_prev_key, operation: add_operation, cost: memo[i][j - 1].cost + 1 };\n } else {\n if (deepEqual(input[i - 1], output[j - 1])) {\n memoized = memo[i - 1][j - 1];\n } else {\n const remove_prev = memo[i - 1][j];\n const add_prev = memo[i][j - 1];\n const replace_prev = memo[i - 1][j - 1];\n const min_cost = Math.min(replace_prev.cost, add_prev.cost, remove_prev.cost);\n if (remove_prev.cost === min_cost) {\n memoized = {\n prev: remove_prev_key,\n operation: remove_operation,\n cost: memo[i - 1][j].cost + 1,\n };\n } else if (add_prev.cost === min_cost) {\n memoized = {\n prev: add_prev_key,\n operation: add_operation,\n cost: memo[i][j - 1].cost + 1,\n };\n } else {\n const replace_operation: ArrayReplace = {\n op: \"replace\",\n index: i - 1,\n original: input[i - 1],\n value: output[j - 1],\n };\n memoized = {\n prev: replace_prev_key,\n operation: replace_operation,\n cost: memo[i - 1][j - 1].cost + 1,\n };\n }\n }\n }\n memo[i][j] = memoized;\n }\n }\n const array_operations = buildOperations(memo, input_end, output_end);\n const [padded_operations] = array_operations.reduce<[Operation[], number]>(\n ([operations, padding], array_operation) => {\n if (isArrayAdd(array_operation)) {\n const padded_index = array_operation.index + 1 + padding;\n const index_token = padded_index < input_length + padding ? String(padded_index) : \"-\";\n const operation = {\n op: array_operation.op,\n path: ptr.add(index_token).toString(),\n value: array_operation.value,\n };\n // padding++ // maybe only if array_operation.index > -1 ?\n return [operations.concat(operation), padding + 1];\n } else if (isArrayRemove(array_operation)) {\n const operation = {\n op: array_operation.op,\n path: ptr.add(String(array_operation.index + padding)).toString(),\n };\n // padding--\n return [operations.concat(operation), padding - 1];\n } else {\n // replace\n const replace_ptr = ptr.add(String(array_operation.index + padding));\n const replace_operations = diff(\n array_operation.original,\n array_operation.value,\n replace_ptr,\n );\n return [operations.concat(...replace_operations), padding];\n }\n },\n [[], 0],\n );\n return padded_operations;\n}\n\nexport function diffObjects(\n input: any,\n output: any,\n ptr: Pointer,\n diff: Diff = diffAny,\n): Operation[] {\n // if a key is in input but not output -> remove it\n const operations: Operation[] = [];\n subtract(input, output).forEach((key) => {\n operations.push({ op: \"remove\", path: ptr.add(key).toString() });\n });\n // if a key is in output but not input -> add it\n subtract(output, input).forEach((key) => {\n operations.push({ op: \"add\", path: ptr.add(key).toString(), value: output[key] });\n });\n // if a key is in both, diff it recursively\n intersection([input, output]).forEach((key) => {\n operations.push(...diff(input[key], output[key], ptr.add(key)));\n });\n return operations;\n}\n\n/**\n`diffAny()` returns an empty array if `input` and `output` are materially equal\n(i.e., would produce equivalent JSON); otherwise it produces an array of patches\nthat would transform `input` into `output`.\n\n> Here, \"equal\" means that the value at the target location and the\n> value conveyed by \"value\" are of the same JSON type, and that they\n> are considered equal by the following rules for that type:\n> o strings: are considered equal if they contain the same number of\n> Unicode characters and their code points are byte-by-byte equal.\n> o numbers: are considered equal if their values are numerically\n> equal.\n> o arrays: are considered equal if they contain the same number of\n> values, and if each value can be considered equal to the value at\n> the corresponding position in the other array, using this list of\n> type-specific rules.\n> o objects: are considered equal if they contain the same number of\n> members, and if each member can be considered equal to a member in\n> the other object, by comparing their keys (as strings) and their\n> values (using this list of type-specific rules).\n> o literals (false, true, and null): are considered equal if they are\n> the same.\n*/\nexport function diffAny(input: any, output: any, ptr: Pointer, diff: Diff = diffAny): Operation[] {\n // strict equality handles literals, numbers, and strings (a sufficient but not necessary cause)\n if (input === output) {\n return [];\n }\n const input_type = objectType(input);\n const output_type = objectType(output);\n if (input_type === \"array\" && output_type === \"array\") {\n return diffArrays(input, output, ptr, diff);\n }\n if (input_type === \"object\" && output_type === \"object\") {\n return diffObjects(input, output, ptr, diff);\n }\n // at this point we know that input and output are materially different;\n // could be array -> object, object -> array, boolean -> undefined,\n // number -> string, or some other combination, but nothing that can be split\n // up into multiple patches: so `output` must replace `input` wholesale.\n return [{ op: \"replace\", path: ptr.toString(), value: output }];\n}\n", "import {\n AddOperation,\n CopyOperation,\n diffAny,\n MoveOperation,\n Operation,\n RemoveOperation,\n ReplaceOperation,\n TestOperation,\n} from \"./diff\";\nimport { Pointer } from \"./pointer\";\nimport { clone } from \"./util\";\n\nexport class MissingError extends Error {\n constructor(public path: string) {\n super(`Value required at path: ${path}`);\n this.name = \"MissingError\";\n }\n}\n\nexport class TestError extends Error {\n constructor(\n public actual: any,\n public expected: any,\n ) {\n super(`Test failed: ${actual} != ${expected}`);\n this.name = \"TestError\";\n }\n}\n\n/**\n Apply a 'application/json-patch+json'-type patch to an object.\n\n `patch` *must* be an array of operations.\n\n > Operation objects MUST have exactly one \"op\" member, whose value\n > indicates the operation to perform. Its value MUST be one of \"add\",\n > \"remove\", \"replace\", \"move\", \"copy\", or \"test\"; other values are\n > errors.\n\n This method mutates the target object in-place.\n\n @returns list of results, one for each operation: `null` indicated success,\n otherwise, the result will be an instance of one of the Error classes:\n MissingError, InvalidOperationError, or TestError.\n */\nexport function applyPatch(object: any, patch: Operation[]) {\n return patch.map((operation) => apply(object, operation));\n}\n\nfunction _add(object: any, key: string, value: any): void {\n if (Array.isArray(object)) {\n // `key` must be an index\n if (key === \"-\") {\n object.push(value);\n } else {\n const index = parseInt(key, 10);\n object.splice(index, 0, value);\n }\n } else {\n object[key] = value;\n }\n}\n\nfunction _remove(object: any, key: string): void {\n if (Array.isArray(object)) {\n // '-' syntax doesn't make sense when removing\n const index = parseInt(key, 10);\n object.splice(index, 1);\n } else {\n // not sure what the proper behavior is when path = ''\n delete object[key];\n }\n}\n\n/**\n> o If the target location specifies an array index, a new value is\n> inserted into the array at the specified index.\n> o If the target location specifies an object member that does not\n> already exist, a new member is added to the object.\n> o If the target location specifies an object member that does exist,\n> that member's value is replaced.\n*/\nexport function add(object: any, operation: AddOperation): MissingError | null {\n const endpoint = Pointer.fromJSON(operation.path).evaluate(object);\n // it's not exactly a \"MissingError\" in the same way that `remove` is -- more like a MissingParent, or something\n if (endpoint.parent === undefined) {\n return new MissingError(operation.path);\n }\n _add(endpoint.parent, endpoint.key, clone(operation.value));\n return null;\n}\n\n/**\n> The \"remove\" operation removes the value at the target location.\n> The target location MUST exist for the operation to be successful.\n*/\nexport function remove(object: any, operation: RemoveOperation): MissingError | null {\n // endpoint has parent, key, and value properties\n const endpoint = Pointer.fromJSON(operation.path).evaluate(object);\n if (endpoint.value === undefined) {\n return new MissingError(operation.path);\n }\n // not sure what the proper behavior is when path = ''\n _remove(endpoint.parent, endpoint.key);\n return null;\n}\n\n/**\n> The \"replace\" operation replaces the value at the target location\n> with a new value. The operation object MUST contain a \"value\" member\n> whose content specifies the replacement value.\n> The target location MUST exist for the operation to be successful.\n\n> This operation is functionally identical to a \"remove\" operation for\n> a value, followed immediately by an \"add\" operation at the same\n> location with the replacement value.\n\nEven more simply, it's like the add operation with an existence check.\n*/\nexport function replace(object: any, operation: ReplaceOperation): MissingError | null {\n const endpoint = Pointer.fromJSON(operation.path).evaluate(object);\n if (endpoint.parent === null) {\n return new MissingError(operation.path);\n }\n // this existence check treats arrays as a special case\n if (Array.isArray(endpoint.parent)) {\n if (parseInt(endpoint.key, 10) >= endpoint.parent.length) {\n return new MissingError(operation.path);\n }\n } else if (endpoint.value === undefined) {\n return new MissingError(operation.path);\n }\n endpoint.parent[endpoint.key] = operation.value;\n return null;\n}\n\n/**\n> The \"move\" operation removes the value at a specified location and\n> adds it to the target location.\n> The operation object MUST contain a \"from\" member, which is a string\n> containing a JSON Pointer value that references the location in the\n> target document to move the value from.\n> This operation is functionally identical to a \"remove\" operation on\n> the \"from\" location, followed immediately by an \"add\" operation at\n> the target location with the value that was just removed.\n\n> The \"from\" location MUST NOT be a proper prefix of the \"path\"\n> location; i.e., a location cannot be moved into one of its children.\n\nTODO: throw if the check described in the previous paragraph fails.\n*/\nexport function move(object: any, operation: MoveOperation): MissingError | null {\n const from_endpoint = Pointer.fromJSON(operation.from).evaluate(object);\n if (from_endpoint.value === undefined) {\n return new MissingError(operation.from);\n }\n const endpoint = Pointer.fromJSON(operation.path).evaluate(object);\n if (endpoint.parent === undefined) {\n return new MissingError(operation.path);\n }\n _remove(from_endpoint.parent, from_endpoint.key);\n _add(endpoint.parent, endpoint.key, from_endpoint.value);\n return null;\n}\n\n/**\n> The \"copy\" operation copies the value at a specified location to the\n> target location.\n> The operation object MUST contain a \"from\" member, which is a string\n> containing a JSON Pointer value that references the location in the\n> target document to copy the value from.\n> The \"from\" location MUST exist for the operation to be successful.\n\n> This operation is functionally identical to an \"add\" operation at the\n> target location using the value specified in the \"from\" member.\n\nAlternatively, it's like 'move' without the 'remove'.\n*/\nexport function copy(object: any, operation: CopyOperation): MissingError | null {\n const from_endpoint = Pointer.fromJSON(operation.from).evaluate(object);\n if (from_endpoint.value === undefined) {\n return new MissingError(operation.from);\n }\n const endpoint = Pointer.fromJSON(operation.path).evaluate(object);\n if (endpoint.parent === undefined) {\n return new MissingError(operation.path);\n }\n _add(endpoint.parent, endpoint.key, clone(from_endpoint.value));\n return null;\n}\n\n/**\n> The \"test\" operation tests that a value at the target location is\n> equal to a specified value.\n> The operation object MUST contain a \"value\" member that conveys the\n> value to be compared to the target location's value.\n> The target location MUST be equal to the \"value\" value for the\n> operation to be considered successful.\n*/\nexport function test(object: any, operation: TestOperation): TestError | null {\n const endpoint = Pointer.fromJSON(operation.path).evaluate(object);\n // TODO: this diffAny(...).length usage could/should be lazy\n if (diffAny(endpoint.value, operation.value, new Pointer()).length) {\n return new TestError(endpoint.value, operation.value);\n }\n return null;\n}\n\nexport class InvalidOperationError extends Error {\n constructor(public operation: Operation) {\n super(`Invalid operation: ${operation.op}`);\n this.name = \"InvalidOperationError\";\n }\n}\n\n/**\nSwitch on `operation.op`, applying the corresponding patch function for each\ncase to `object`.\n*/\nexport function apply(\n object: any,\n operation: Operation,\n): MissingError | InvalidOperationError | TestError | null {\n // not sure why TypeScript can't infer typesafety of:\n // {add, remove, replace, move, copy, test}[operation.op](object, operation)\n // (seems like a bug)\n switch (operation.op) {\n case \"add\":\n return add(object, operation);\n case \"remove\":\n return remove(object, operation);\n case \"replace\":\n return replace(object, operation);\n case \"move\":\n return move(object, operation);\n case \"copy\":\n return copy(object, operation);\n case \"test\":\n return test(object, operation);\n }\n return new InvalidOperationError(operation);\n}\n", "import {\n AttributeChangedDiff,\n ChildrenChangedDiff,\n Diff,\n ElementNodeDescription,\n NodeDescription,\n SnapshotMessage,\n TextChangedDiff,\n TextNodeDescription,\n} from \"@mml-io/networked-dom-protocol\";\nimport { StaticVirtualDOMElement } from \"@mml-io/observable-dom-common\";\n\nimport { NodeMapping, StaticVirtualDOMMutationRecord, VirtualDOMDiffStruct } from \"./common\";\nimport * as rfc6902 from \"./rfc6902\";\n\nexport const visibleToAttrName = \"visible-to\";\nexport const hiddenFromAttrName = \"hidden-from\";\n\n/**\n * This function does a lot of heavy lifting - it takes a mutation and applies it to the connection's view (affecting\n * which nodes are visible based on attributes etc.)\n *\n * As a result of the application it generates a diff for the particular connection's view of the DOM.\n */\nexport function diffFromApplicationOfStaticVirtualDOMMutationRecordToConnection(\n mutation: StaticVirtualDOMMutationRecord,\n parentNode: StaticVirtualDOMElement | null,\n connectionId: number,\n visibleNodesForConnection: Set<number>,\n): Diff | null {\n const virtualDOMElement = mutation.target;\n\n switch (mutation.type) {\n case \"snapshot\": {\n const nodeDescription = describeNodeWithChildrenForConnectionId(\n virtualDOMElement,\n connectionId,\n visibleNodesForConnection,\n );\n if (!nodeDescription) {\n return null;\n }\n const diff: SnapshotMessage = {\n type: \"snapshot\",\n snapshot: nodeDescription,\n documentTime: 0,\n };\n return diff;\n }\n case \"attributes\": {\n const visible = visibleNodesForConnection.has(virtualDOMElement.nodeId);\n\n if (!parentNode) {\n throw new Error(\"Node has no parent\");\n }\n const parentNodeId = parentNode.nodeId;\n const shouldBeVisible =\n shouldShowNodeToConnectionId(virtualDOMElement, connectionId) &&\n visibleNodesForConnection.has(parentNodeId);\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const attributeName = mutation.attributeName!;\n\n if (visible && shouldBeVisible) {\n let newValue = null; // null indicates deleted\n if (virtualDOMElement.attributes[attributeName] !== undefined) {\n newValue = virtualDOMElement.attributes[attributeName];\n }\n const diff: AttributeChangedDiff = {\n type: \"attributeChange\",\n nodeId: virtualDOMElement.nodeId,\n attribute: attributeName,\n newValue,\n };\n return diff;\n } else if (!visible && shouldBeVisible) {\n // Need to add this child to the connection's view now\n visibleNodesForConnection.add(virtualDOMElement.nodeId);\n\n const index = parentNode.childNodes.indexOf(virtualDOMElement);\n if (index === -1) {\n throw new Error(\"Node not found in parent's children\");\n }\n\n let previousNodeId = null;\n if (index > 0) {\n previousNodeId = getNodeIdOfPreviousVisibleSibling(\n parentNode,\n index - 1,\n visibleNodesForConnection,\n );\n }\n\n const nodeDescription = describeNodeWithChildrenForConnectionId(\n virtualDOMElement,\n connectionId,\n visibleNodesForConnection,\n );\n if (!nodeDescription) {\n throw new Error(\"Node description not found\");\n }\n const diff: ChildrenChangedDiff = {\n type: \"childrenChanged\",\n nodeId: parentNodeId,\n previousNodeId,\n addedNodes: [nodeDescription],\n removedNodes: [],\n };\n return diff;\n } else if (visible && !shouldBeVisible) {\n removeNodeAndChildrenFromVisibleNodes(virtualDOMElement, visibleNodesForConnection);\n const diff: ChildrenChangedDiff = {\n type: \"childrenChanged\",\n nodeId: parentNodeId,\n previousNodeId: null,\n addedNodes: [],\n removedNodes: [virtualDOMElement.nodeId],\n };\n return diff;\n } else if (!visible && !shouldBeVisible) {\n return null;\n }\n break;\n }\n case \"characterData\": {\n const visible = visibleNodesForConnection.has(virtualDOMElement.nodeId);\n if (!visible) {\n return null;\n }\n const diff: TextChangedDiff = {\n type: \"textChanged\",\n nodeId: virtualDOMElement.nodeId,\n text: virtualDOMElement.textContent || \"\",\n };\n return diff;\n }\n case \"childList\": {\n const visible = visibleNodesForConnection.has(virtualDOMElement.nodeId);\n if (!visible) {\n return null;\n }\n let previousSibling = mutation.previousSibling;\n let previousNodeId: number | null = null;\n if (previousSibling) {\n let previousIndex = virtualDOMElement.childNodes.indexOf(previousSibling);\n while (previousIndex !== -1) {\n previousSibling = virtualDOMElement.childNodes[previousIndex];\n if (visibleNodesForConnection.has(previousSibling.nodeId)) {\n previousNodeId = previousSibling.nodeId;\n break;\n }\n previousIndex--;\n }\n }\n\n const diff: ChildrenChangedDiff = {\n type: \"childrenChanged\",\n nodeId: virtualDOMElement.nodeId,\n previousNodeId,\n addedNodes: [],\n removedNodes: [],\n };\n\n mutation.addedNodes.forEach((childVirtualDOMElement: StaticVirtualDOMElement) => {\n const describedNode = describeNodeWithChildrenForConnectionId(\n childVirtualDOMElement,\n connectionId,\n visibleNodesForConnection,\n );\n if (!describedNode) {\n return;\n }\n diff.addedNodes.push(describedNode);\n });\n mutation.removedNodes.forEach((childVirtualDOMElement: StaticVirtualDOMElement) => {\n if (visibleNodesForConnection.has(childVirtualDOMElement.nodeId)) {\n removeNodeAndChildrenFromVisibleNodes(childVirtualDOMElement, visibleNodesForConnection);\n diff.removedNodes.push(childVirtualDOMElement.nodeId);\n }\n });\n\n if (diff.addedNodes.length > 0 || diff.removedNodes.length > 0) {\n return diff;\n }\n return null;\n }\n default:\n console.error(\"Unknown mutation type: \" + mutation.type);\n break;\n }\n return null;\n}\n\nfunction getNodeIdOfPreviousVisibleSibling(\n parentVirtualElement: StaticVirtualDOMElement,\n candidateIndex: number,\n visibleNodesForConnection: Set<number>,\n): number | null {\n if (candidateIndex > 0) {\n let previousSiblingIndex = candidateIndex;\n while (previousSiblingIndex >= 0) {\n const previousSibling = parentVirtualElement.childNodes[previousSiblingIndex];\n if (visibleNodesForConnection.has(previousSibling.nodeId)) {\n return previousSibling.nodeId;\n }\n previousSiblingIndex--;\n }\n }\n return null;\n}\n\nfunction shouldShowNodeToConnectionId(\n virtualDOMElement: StaticVirtualDOMElement,\n connectionId: number,\n): boolean {\n const visibleToAttr = virtualDOMElement.attributes[visibleToAttrName];\n const hiddenFromAttr = virtualDOMElement.attributes[hiddenFromAttrName];\n const connectionIdString = connectionId.toString();\n if (visibleToAttr !== undefined) {\n const visibleToList = visibleToAttr.split(\" \");\n const explicityVisible = visibleToList.includes(connectionIdString);\n if (!explicityVisible) {\n return false;\n }\n }\n if (hiddenFromAttr !== undefined) {\n const hiddenFromList = hiddenFromAttr.split(\" \");\n const explicityHidden = hiddenFromList.includes(connectionIdString);\n if (explicityHidden) {\n return false;\n }\n }\n return true;\n}\n\nexport function describeNodeWithChildrenForConnectionId(\n virtualDOMElement: StaticVirtualDOMElement,\n connectionId: number,\n visibleNodesForConnection: Set<number>,\n): NodeDescription | null {\n if (!shouldShowNodeToConnectionId(virtualDOMElement, connectionId)) {\n return null;\n }\n\n let emittedTagName = virtualDOMElement.tag;\n if (emittedTagName === \"#document\") {\n emittedTagName = \"DIV\";\n }\n if (emittedTagName === \"#text\") {\n const textNode: TextNodeDescription = {\n type: \"text\",\n nodeId: virtualDOMElement.nodeId,\n text: virtualDOMElement.textContent || \"\",\n };\n visibleNodesForConnection.add(textNode.nodeId);\n return textNode;\n } else {\n const node: ElementNodeDescription = {\n type: \"element\",\n nodeId: virtualDOMElement.nodeId,\n tag: emittedTagName,\n attributes: virtualDOMElement.attributes,\n children: [],\n text: virtualDOMElement.textContent,\n };\n visibleNodesForConnection.add(node.nodeId);\n\n for (const child of virtualDOMElement.childNodes) {\n const childNodeDescription = describeNodeWithChildrenForConnectionId(\n child,\n connectionId,\n visibleNodesForConnection,\n );\n if (childNodeDescription) {\n node.children.push(childNodeDescription);\n }\n }\n return node;\n }\n}\n\nfunction removeNodeAndChildrenFromVisibleNodes(\n virtualDOMElement: StaticVirtualDOMElement,\n visibleNodesForConnection: Set<number>,\n): void {\n visibleNodesForConnection.delete(virtualDOMElement.nodeId);\n for (const child of virtualDOMElement.childNodes) {\n if (!visibleNodesForConnection.has(child.nodeId)) {\n console.error(\"Inner child of removed element was not visible\", child.nodeId);\n }\n removeNodeAndChildrenFromVisibleNodes(child, visibleNodesForConnection);\n }\n}\n\nexport function findParentNodeOfNodeId(\n virtualDOMElement: StaticVirtualDOMElement,\n targetNodeId: number,\n): StaticVirtualDOMElement | null {\n // TODO - avoid a search of the whole tree for the node's parent\n // depth-first search of the whole virtual dom structure to find the node's parent\n for (const child of virtualDOMElement.childNodes) {\n if (child.nodeId === targetNodeId) {\n return virtualDOMElement;\n } else {\n const foundParentId = findParentNodeOfNodeId(child, targetNodeId);\n if (foundParentId) {\n return foundParentId;\n }\n }\n }\n return null;\n}\n\nexport function virtualDOMDiffToVirtualDOMMutationRecord(\n virtualStructure: StaticVirtualDOMElement,\n domDiff: rfc6902.Operation,\n): Array<StaticVirtualDOMMutationRecord> {\n const pointer = rfc6902.Pointer.fromJSON(domDiff.path);\n const grandParentTokens = pointer.tokens.slice(0, pointer.tokens.length - 2);\n const lastToken = pointer.tokens[pointer.tokens.length - 1];\n const secondLastToken = pointer.tokens[pointer.tokens.length - 2];\n\n if (lastToken === \"textContent\") {\n const nodePointer = new rfc6902.Pointer(pointer.tokens.slice(0, pointer.tokens.length - 1));\n const node = nodePointer.get(virtualStructure) as StaticVirtualDOMElement;\n return [\n {\n type: \"characterData\",\n target: node,\n addedNodes: [],\n removedNodes: [],\n attributeName: null,\n previousSibling: null,\n },\n ];\n }\n\n if (secondLastToken === \"attributes\") {\n // This handles attribute additions, changes, and removals\n const nodePointer = new rfc6902.Pointer(grandParentTokens);\n const node = nodePointer.get(virtualStructure) as StaticVirtualDOMElement;\n return [\n {\n type: \"attributes\",\n target: node,\n addedNodes: [],\n removedNodes: [],\n attributeName: lastToken,\n previousSibling: null,\n },\n ];\n }\n\n // Child changes\n\n if (secondLastToken === \"childNodes\") {\n const nodePointer = new rfc6902.Pointer(grandParentTokens);\n const node = nodePointer.get(virtualStructure) as StaticVirtualDOMElement;\n\n let previousSibling: StaticVirtualDOMElement | null = null;\n if (lastToken === \"-\") {\n // Append to the end of the children\n } else {\n const index = parseInt(lastToken, 10);\n if (index === 0) {\n previousSibling = null;\n } else {\n previousSibling = node.childNodes[index - 1];\n }\n }\n const addedNodes: Array<StaticVirtualDOMElement> = [];\n const removedNodes: Array<StaticVirtualDOMElement> = [];\n switch (domDiff.op) {\n case \"add\": {\n addedNodes.push(domDiff.value);\n return [\n {\n type: \"childList\",\n target: node,\n addedNodes,\n removedNodes,\n previousSibling,\n attributeName: null,\n },\n ];\n }\n case \"remove\": {\n const removedNode = pointer.get(virtualStructure) as StaticVirtualDOMElement;\n removedNodes.push(removedNode);\n return [\n {\n type: \"childList\",\n target: node,\n addedNodes,\n removedNodes,\n previousSibling,\n attributeName: null,\n },\n ];\n }\n case \"replace\": {\n // This is a replacement of a single node\n const removedNode = pointer.get(virtualStructure) as StaticVirtualDOMElement;\n removedNodes.push(removedNode);\n addedNodes.push(domDiff.value);\n return [\n {\n type: \"childList\",\n target: node,\n addedNodes: [],\n removedNodes,\n previousSibling,\n attributeName: null,\n },\n {\n type: \"childList\",\n target: node,\n addedNodes,\n removedNodes: [],\n previousSibling,\n attributeName: null,\n },\n ];\n }\n }\n }\n\n if (domDiff.op === \"replace\" && domDiff.path === \"\") {\n const node = domDiff.value as StaticVirtualDOMElement;\n return [\n {\n type: \"snapshot\",\n target: node,\n addedNodes: [],\n removedNodes: [],\n previousSibling: null,\n attributeName: null,\n },\n ];\n }\n\n console.error(\"Unhandled JSON diff:\", JSON.stringify(domDiff, null, 2));\n throw new Error(\"Unhandled diff type\");\n}\n\nexport function calculateStaticVirtualDOMDiff(\n originalState: StaticVirtualDOMElement,\n latestState: StaticVirtualDOMElement,\n): VirtualDOMDiffStruct {\n const jsonPatchDiffs = rfc6902.createPatch(\n originalState,\n latestState,\n (a, b, ptr: rfc6902.Pointer) => {\n if (a.tag !== b.tag) {\n return [{ op: \"replace\", path: ptr.toString(), value: b }];\n }\n return;\n },\n );\n\n const nodeIdRemappings: Array<NodeMapping> = [];\n const virtualDOMDiffs: Array<rfc6902.Operation> = [];\n for (const diff of jsonPatchDiffs) {\n if (diff.op === \"replace\" && diff.path.endsWith(\"/nodeId\")) {\n const pointer = rfc6902.Pointer.fromJSON(diff.path);\n const originalValue = pointer.get(originalState);\n nodeIdRemappings.push({\n internalNodeId: diff.value,\n clientFacingNodeId: originalValue,\n });\n } else {\n virtualDOMDiffs.push(diff);\n }\n }\n\n return remapDuplicatedNodeIdsInOperations(\n {\n originalState,\n nodeIdRemappings,\n virtualDOMDiffs,\n },\n latestState,\n );\n}\n\nfunction getHighestNodeId(node: StaticVirtualDOMElement) {\n let highest = node.nodeId;\n for (const child of node.childNodes) {\n highest = Math.max(highest, getHighestNodeId(child));\n }\n return highest;\n}\n\nfunction getRemovedNodeIds(before: StaticVirtualDOMElement, diff: rfc6902.Operation) {\n const removedIds = new Set<number>();\n function addNode(node: StaticVirtualDOMElement) {\n removedIds.add(node.nodeId);\n for (const child of node.childNodes) {\n addNode(child);\n }\n }\n if (diff.op === \"replace\" || diff.op === \"remove\") {\n const removedNode = rfc6902.Pointer.fromJSON(diff.path).get(before);\n addNode(removedNode);\n }\n return removedIds;\n}\n\nfunction getNodeIdsFromNodeAndChildren(node: StaticVirtualDOMElement) {\n const nodeIds = new Set<number>();\n function addNode(node: StaticVirtualDOMElement) {\n nodeIds.add(node.nodeId);\n for (const child of node.childNodes) {\n addNode(child);\n }\n }\n addNode(node);\n return nodeIds;\n}\n\n// To avoid duplicate node ids at any point in the sequence of operations, apply the operations and determine if any node ids are duplicated at any point. If so, remap the node ids to be unique.\nfunction remapDuplicatedNodeIdsInOperations(\n virtualDOMDiffStruct: VirtualDOMDiffStruct,\n latestState: StaticVirtualDOMElement,\n): VirtualDOMDiffStruct {\n const { originalState, nodeIdRemappings, virtualDOMDiffs } = virtualDOMDiffStruct;\n\n const highestNodeIdAcrossStartAndEnd = Math.max(\n getHighestNodeId(originalState),\n getHighestNodeId(latestState),\n );\n let nextNodeId = highestNodeIdAcrossStartAndEnd + 1;\n\n const before = JSON.parse(JSON.stringify(originalState));\n\n function checkAndReplaceNodeIdsIfAlreadyInUse(\n node: StaticVirtualDOMElement,\n addingNodeIds: Set<number>,\n removedIds: Set<number>,\n ) {\n if (existingNodeIds.has(node.nodeId) && removedIds && !removedIds.has(node.nodeId)) {\n // This node id is already present so it must be replaced\n const newNodeId = nextNodeId++;\n nodeIdRemappings.push({\n internalNodeId: node.nodeId,\n clientFacingNodeId: newNodeId,\n });\n node.nodeId = newNodeId;\n addingNodeIds.add(newNodeId);\n } else {\n addingNodeIds.add(node.nodeId);\n }\n for (const child of node.childNodes) {\n checkAndReplaceNodeIdsIfAlreadyInUse(child, addingNodeIds, removedIds);\n }\n }\n\n const existingNodeIds = getNodeIdsFromNodeAndChildren(before);\n\n for (const diff of virtualDOMDiffs) {\n const pointer = rfc6902.Pointer.fromJSON(diff.path);\n const secondLastToken = pointer.tokens[pointer.tokens.length - 2];\n if (secondLastToken !== \"childNodes\") {\n continue;\n }\n const removedIds = getRemovedNodeIds(before, diff);\n const addingNodeIds = new Set<number>();\n if (diff.op === \"replace\" || diff.op === \"add\") {\n // The added node can use removed node ids, but it must not use any node ids that are still in use.\n checkAndReplaceNodeIdsIfAlreadyInUse(diff.value, addingNodeIds, removedIds);\n }\n removedIds.forEach((removedId) => {\n existingNodeIds.delete(removedId);\n });\n addingNodeIds.forEach((addingNodeId) => {\n existingNodeIds.add(addingNodeId);\n });\n\n const patchErrors = rfc6902.applyPatch(before, [diff]);\n if (patchErrors.length !== 1 || patchErrors[0] !== null) {\n throw new Error(\"Patch failed\");\n }\n }\n\n return virtualDOMDiffStruct;\n}\n", "import {\n ClientMessage,\n Diff,\n NodeDescription,\n PongMessage,\n RemoteEvent,\n ServerMessage,\n SnapshotMessage,\n} from \"@mml-io/networked-dom-protocol\";\nimport {\n LogMessage,\n ObservableDOMInterface,\n ObservableDOMMessage,\n ObservableDOMParameters,\n StaticVirtualDOMElement,\n StaticVirtualDOMMutationIdsRecord,\n} from \"@mml-io/observable-dom-common\";\n\nimport { StaticVirtualDOMMutationRecord, VirtualDOMDiffStruct } from \"./common\";\nimport {\n calculateStaticVirtualDOMDiff,\n describeNodeWithChildrenForConnectionId,\n diffFromApplicationOfStaticVirtualDOMMutationRecordToConnection,\n findParentNodeOfNodeId,\n virtualDOMDiffToVirtualDOMMutationRecord,\n} from \"./diffing\";\nimport { applyPatch } from \"./rfc6902\";\n\nexport const networkedDOMProtocolSubProtocol_v0_1 = \"networked-dom-v0.1\";\nexport const defaultWebsocketSubProtocol = networkedDOMProtocolSubProtocol_v0_1;\n\nexport type ObservableDOMFactory = (\n observableDOMParameters: ObservableDOMParameters,\n callback: (message: ObservableDOMMessage, observableDOM: ObservableDOMInterface) => void,\n) => ObservableDOMInterface;\n\n/**\n * NetworkedDOM is the main class for the networked-dom-document package. It is responsible for managing the state of\n * the document and the connections to the clients.\n *\n * It is constructed with an ObservableDOMFactory, which is responsible for creating the ObservableDOMInterface\n * implementation that is used to run the document.\n */\nexport class NetworkedDOM {\n // First to last in order of preference\n public static SupportedWebsocketSubProtocolsPreferenceOrder = [\n networkedDOMProtocolSubProtocol_v0_1,\n ];\n\n // Map from the node ids that the DOM uses internally to the node ids that clients refer to.\n private internalNodeIdToClientNodeId = new Map<number, number>();\n\n // Map from the node ids that clients refer to to the node ids that the DOM uses internally.\n private clientNodeIdToInternalNodeId = new Map<number, number>();\n\n private currentConnectionId = 1;\n private connectionIdToWebSocketContext = new Map<\n number,\n { webSocket: WebSocket; messageListener: (messageEvent: MessageEvent) => void }\n >();\n private webSocketToConnectionId = new Map<WebSocket, number>();\n private visibleNodeIdsByConnectionId = new Map<number, Set<number>>();\n private initialLoad = true;\n private readonly htmlPath: string;\n\n private disposed = false;\n private ignoreTextNodes: boolean;\n\n private documentRoot!: StaticVirtualDOMElement;\n private nodeIdToNode = new Map<number, StaticVirtualDOMElement>();\n private nodeIdToParentNodeId = new Map<number, number>();\n\n private observableDOM: ObservableDOMInterface;\n\n private documentEffectiveStartTime = Date.now();\n private latestDocumentTime = 0;\n private pingCounter = 1;\n private maximumNodeId = 0;\n\n private logCallback?: (message: LogMessage) => void;\n\n constructor(\n observableDOMFactory: ObservableDOMFactory,\n htmlPath: string,\n htmlContents: string,\n oldInstanceDocumentRoot: StaticVirtualDOMElement | null,\n onLoad: (domDiff: VirtualDOMDiffStruct | null, networkedDOM: NetworkedDOM) => void,\n params = {},\n ignoreTextNodes = true,\n logCallback?: (message: LogMessage) => void,\n ) {\n this.htmlPath = htmlPath;\n this.ignoreTextNodes = ignoreTextNodes;\n\n this.logCallback = logCallback || this.defaultLogCallback;\n\n this.observableDOM = observableDOMFactory(\n {\n htmlPath,\n htmlContents,\n params,\n ignoreTextNodes,\n pingIntervalMilliseconds: 5000,\n },\n (message: ObservableDOMMessage, observableDOM: ObservableDOMInterface) => {\n this.observableDOM = observableDOM;\n if (message.documentTime) {\n this.documentEffectiveStartTime = Date.now() - message.documentTime;\n this.latestDocumentTime = message.documentTime;\n }\n if (message.snapshot) {\n this.documentRoot = message.snapshot;\n const clonedSnapshot = JSON.parse(JSON.stringify(message.snapshot));\n\n if (!this.initialLoad) {\n throw new Error(\"Received snapshot after initial load\");\n }\n this.initialLoad = false;\n\n let domDiff: VirtualDOMDiffStruct | null = null;\n if (oldInstanceDocumentRoot) {\n domDiff = calculateStaticVirtualDOMDiff(oldInstanceDocumentRoot, clonedSnapshot);\n for (const remapping of domDiff.nodeIdRemappings) {\n this.addRemappedNodeId(remapping.clientFacingNodeId, remapping.internalNodeId);\n }\n }\n\n this.addAndRemapNodeFromInstance(this.documentRoot, -1);\n\n onLoad(domDiff, this);\n } else if (message.mutation) {\n if (this.initialLoad) {\n throw new Error(\"Received mutation before initial load\");\n }\n const mutation = this.addKnownNodesInMutation(message.mutation);\n this.processModification(mutation);\n this.removeKnownNodesInMutation(mutation);\n } else if (message.logMessage) {\n if (this.logCallback) {\n this.logCallback(message.logMessage);\n }\n } else {\n if (message.documentTime) {\n // This is just a regular ping message to update the document time - send the document time to all connected clients\n this.sendPings();\n return;\n }\n console.error(\"Unknown message type from observableDOM\", message);\n }\n },\n );\n }\n\n private defaultLogCallback(message: LogMessage) {\n const getLogFn = (level: string) => {\n switch (level) {\n case \"system\":\n return console.error;\n case \"error\":\n return console.error;\n case \"warn\":\n return console.warn;\n case \"log\":\n return console.log;\n case \"info\":\n return console.info;\n default:\n return console.log;\n }\n };\n\n const logFn = getLogFn(message.level);\n logFn(`${message.level.toUpperCase()} (${this.htmlPath}):`, ...message.content);\n }\n\n private addRemappedNodeId(clientFacingNodeId: number, internalNodeId: number) {\n this.internalNodeIdToClientNodeId.set(internalNodeId, clientFacingNodeId);\n this.clientNodeIdToInternalNodeId.set(clientFacingNodeId, internalNodeId);\n this.maximumNodeId = Math.max(this.maximumNodeId, Math.max(clientFacingNodeId, internalNodeId));\n }\n\n private sendPings() {\n const ping = this.pingCounter++;\n if (this.pingCounter > 1000) {\n this.pingCounter = 1;\n }\n const pingMessage: Array<ServerMessage> = [\n {\n type: \"ping\",\n ping,\n documentTime: this.getDocumentTime(),\n },\n ];\n const stringified = JSON.stringify(pingMessage);\n this.connectionIdToWebSocketContext.forEach((webSocketContext) => {\n webSocketContext.webSocket.send(stringified);\n });\n }\n\n private getInitialSnapshot(\n connectionId: number,\n documentVirtualDOMElement: StaticVirtualDOMElement,\n ): SnapshotMessage {\n const visibleNodesForConnection = this.visibleNodeIdsByConnectionId.get(connectionId);\n if (!visibleNodesForConnection) {\n const err = new Error(\n `visibleNodesForConnection not found for connectionId in getInitialSnapshot: ${connectionId}`,\n );\n console.error(err);\n throw err;\n }\n const domSnapshot: NodeDescription | null = describeNodeWithChildrenForConnectionId(\n documentVirtualDOMElement,\n connectionId,\n visibleNodesForConnection,\n );\n if (!domSnapshot) {\n throw new Error(`domSnapshot was not generated`);\n }\n return {\n type: \"snapshot\",\n snapshot: domSnapshot,\n documentTime: Date.now() - this.documentEffectiveStartTime,\n };\n }\n\n public getDocumentTime(): number {\n return this.latestDocumentTime;\n }\n\n public addExistingWebsockets(\n websockets: Array<WebSocket>,\n existingWebsocketMap: Map<WebSocket, number> | null,\n domDiff: VirtualDOMDiffStruct | null,\n ) {\n const connectionIds = [];\n for (const websocket of websockets) {\n let existingId = null;\n if (existingWebsocketMap !== null) {\n existingId = existingWebsocketMap.get(websocket);\n }\n const { connectionId } = this.registerWebsocket(websocket, existingId);\n connectionIds.push(connectionId);\n }\n\n if (domDiff) {\n const diffsByConnectionId = new Map<number, Array<Diff>>(\n connectionIds.map((connectionId) => [connectionId, []]),\n );\n\n // Each of the websockets needs to have the original state of the document re-applied to it to determine visible\n // nodes, but not sent (they already have the old version of the document as their state).\n for (const connectionId of connectionIds) {\n // Ignore the return value - the side effect is that the visible nodes for the connection are set\n this.getInitialSnapshot(connectionId, domDiff.originalState);\n }\n\n for (const virtualDOMDiff of domDiff.virtualDOMDiffs) {\n // Convert the diff of the virtual dom data structure to a MutationRecord-like diff and then handle it as if it were a MutationRecord\n // The difficulty here is that the JSON diff is typed by add/remove/replace of elements of a hierarchy specified by paths, but MutationRecords are specified by type of operation and nodeIds\n\n const mutationRecordLikes = virtualDOMDiffToVirtualDOMMutationRecord(\n domDiff.originalState,\n virtualDOMDiff,\n );\n\n if (virtualDOMDiff.path === \"\" && virtualDOMDiff.op === \"replace\") {\n // The patch is a snapshot replacement - no need to check the patch validity\n } else {\n const patchResults = applyPatch(domDiff.originalState, [virtualDOMDiff]);\n for (const patchResult of patchResults) {\n if (patchResult !== null) {\n console.error(\"Patching virtual dom structure resulted in error\", patchResult);\n throw patchResult;\n }\n }\n }\n\n for (const mutationRecordLike of mutationRecordLikes) {\n const targetNodeId = mutationRecordLike.target.nodeId;\n const virtualElementParent = findParentNodeOfNodeId(domDiff.originalState, targetNodeId);\n diffsByConnectionId.forEach((diffs, connectionId) => {\n const mutationDiff = diffFromApplicationOfStaticVirtualDOMMutationRecordToConnection(\n mutationRecordLike,\n virtualElementParent,\n connectionId,\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.visibleNodeIdsByConnectionId.get(connectionId)!,\n );\n if (mutationDiff) {\n diffs.push(mutationDiff);\n }\n });\n }\n }\n\n diffsByConnectionId.forEach((diffs, connectionId) => {\n if (diffs.length === 0) {\n // Need to add an \"empty\" message to allow passing the document time to the client\n diffs.push({\n type: \"childrenChanged\",\n nodeId: this.documentRoot.nodeId,\n previousNodeId: null,\n addedNodes: [],\n removedNodes: [],\n });\n }\n const asServerMessages: Array<ServerMessage> = diffs;\n const firstDiff = diffs[0];\n firstDiff.documentTime = this.getDocumentTime();\n const serializedDiffs = JSON.stringify(asServerMessages);\n const webSocketContext = this.connectionIdToWebSocketContext.get(connectionId);\n if (!webSocketContext) {\n throw new Error(`webSocketContext not found in addExistingWebsockets`);\n }\n webSocketContext.webSocket.send(serializedDiffs);\n });\n } else {\n const documentVirtualDOMElement = this.documentRoot;\n if (!documentVirtualDOMElement) {\n throw new Error(`documentVirtualDOMElement not found in getInitialSnapshot`);\n }\n for (const connectionId of connectionIds) {\n const webSocketContext = this.connectionIdToWebSocketContext.get(connectionId);\n if (!webSocketContext) {\n throw new Error(`webSocketContext not found in addExistingWebsockets`);\n }\n const asServerMessages: Array<ServerMessage> = [\n this.getInitialSnapshot(connectionId, documentVirtualDOMElement),\n ];\n const serializedSnapshotMessage = JSON.stringify(asServerMessages);\n webSocketContext.webSocket.send(serializedSnapshotMessage);\n }\n }\n\n for (const connectionId of connectionIds) {\n this.observableDOM.addConnectedUserId(connectionId);\n }\n }\n\n private findParentNodeOfNodeId(targetNodeId: number): StaticVirtualDOMElement | null {\n const parentNodeId = this.nodeIdToParentNodeId.get(targetNodeId);\n if (parentNodeId === undefined) {\n throw new Error(\"Parent node ID not found\");\n }\n return this.getStaticVirtualDOMElementByInternalNodeIdOrThrow(parentNodeId);\n }\n\n private registerWebsocket(\n webSocket: WebSocket,\n existingConnectionId: number | null = null,\n ): { connectionId: number } {\n let connectionId: number;\n if (existingConnectionId !== null) {\n connectionId = existingConnectionId;\n this.currentConnectionId = Math.max(this.currentConnectionId, connectionId + 1);\n } else {\n connectionId = this.currentConnectionId++;\n }\n const webSocketContext = {\n webSocket,\n messageListener: (messageEvent: MessageEvent) => {\n const string = String(messageEvent.data);\n let parsed;\n try {\n parsed = JSON.parse(string) as ClientMessage;\n } catch (e) {\n console.error(`Error parsing message from websocket: ${string}`);\n console.trace();\n return;\n }\n\n if (NetworkedDOM.IsPongMessage(parsed)) {\n // Ignore pongs for now\n return;\n }\n\n this.dispatchRemoteEvent(webSocket, parsed);\n },\n };\n this.connectionIdToWebSocketContext.set(connectionId, webSocketContext);\n this.visibleNodeIdsByConnectionId.set(connectionId, new Set());\n this.webSocketToConnectionId.set(webSocket, connectionId);\n webSocket.addEventListener(\"message\", webSocketContext.messageListener);\n return { connectionId };\n }\n\n public static handleWebsocketSubprotocol(protocols: Set<string> | Array<string>): string | false {\n const protocolsSet = new Set(protocols);\n // Find highest priority (first in the array) protocol that is supported\n for (const protocol of NetworkedDOM.SupportedWebsocketSubProtocolsPreferenceOrder) {\n if (protocolsSet.has(protocol)) {\n return protocol;\n }\n }\n return false;\n }\n\n public addWebSocket(webSocket: WebSocket): void {\n if (this.initialLoad) {\n throw new Error(\"addWebSocket called before initial load - unsupported at this time\");\n }\n if (this.disposed) {\n console.error(\"addWebSocket called on disposed NetworkedDOM\");\n throw new Error(\"This NetworkedDOM has been disposed\");\n }\n\n if (webSocket.protocol) {\n if (\n NetworkedDOM.SupportedWebsocketSubProtocolsPreferenceOrder.indexOf(webSocket.protocol) ===\n -1\n ) {\n const errorMessageString = `Unsupported websocket subprotocol: ${webSocket.protocol}`;\n const errorMessage: Array<ServerMessage> = [\n {\n type: \"error\",\n message: errorMessageString,\n },\n ];\n webSocket.send(JSON.stringify(errorMessage));\n webSocket.close();\n return;\n }\n } else {\n // TODO - Revisit the default handling of non-protocol websockets. It is easier to debug if a lack of protocol results in an error.\n // Assume for now that this client is a legacy MML client that doesn't send a protocol, but send a warning to the client to encourage specifying a protocol\n const warningMessageString = `No websocket subprotocol specified. Please specify a subprotocol to ensure compatibility with networked-dom servers. Assuming subprotocol \"${defaultWebsocketSubProtocol}\" for this connection.`;\n const warningMessage: Array<ServerMessage> = [\n {\n type: \"warning\",\n message: warningMessageString,\n },\n ];\n webSocket.send(JSON.stringify(warningMessage));\n }\n\n const { connectionId } = this.registerWebsocket(webSocket);\n const documentVirtualDOMElement = this.documentRoot;\n if (!documentVirtualDOMElement) {\n throw new Error(`documentVirtualDOMElement not found in getInitialSnapshot`);\n }\n const asServerMessages: Array<ServerMessage> = [\n this.getInitialSnapshot(connectionId, documentVirtualDOMElement),\n ];\n const serializedSnapshotMessage = JSON.stringify(asServerMessages);\n webSocket.send(serializedSnapshotMessage);\n this.observableDOM.addConnectedUserId(connectionId);\n }\n\n public removeWebSocket(webSocket: WebSocket): void {\n const connectionId = this.webSocketToConnectionId.get(webSocket);\n if (!connectionId) {\n return;\n }\n this.observableDOM.removeConnectedUserId(connectionId);\n const webSocketContext = this.connectionIdToWebSocketContext.get(connectionId);\n if (!webSocketContext) {\n throw new Error(\"Missing context for websocket\");\n }\n webSocket.removeEventListener(\"message\", webSocketContext.messageListener);\n this.connectionIdToWebSocketContext.delete(connectionId);\n this.visibleNodeIdsByConnectionId.delete(connectionId);\n this.webSocketToConnectionId.delete(webSocket);\n }\n\n public dispose(): void {\n this.disposed = true;\n\n // Handle all of the remaining mutations that the disconnections could have caused\n this.observableDOM.dispose();\n\n for (const [webSocket, connectionId] of this.webSocketToConnectionId) {\n const webSocketContext = this.connectionIdToWebSocketContext.get(connectionId);\n if (!webSocketContext) {\n throw new Error(\"Missing context for websocket\");\n }\n webSocket.removeEventListener(\"message\", webSocketContext.messageListener);\n this.connectionIdToWebSocketContext.delete(connectionId);\n this.visibleNodeIdsByConnectionId.delete(connectionId);\n this.webSocketToConnectionId.delete(webSocket);\n }\n }\n\n private processModification(mutationRecord: StaticVirtualDOMMutationRecord): void {\n const documentVirtualDOMElement = this.documentRoot;\n if (!documentVirtualDOMElement) {\n throw new Error(`document not created in processModification`);\n }\n\n for (const [, visibleNodesForConnection] of this.visibleNodeIdsByConnectionId) {\n visibleNodesForConnection.add(documentVirtualDOMElement.nodeId);\n }\n\n const diffsByConnectionId = new Map<number, Array<Diff>>(\n Array.from(this.connectionIdToWebSocketContext.keys()).map((connectionId) => [\n connectionId,\n [],\n ]),\n );\n\n diffsByConnectionId.forEach((diffs, connectionId) => {\n const parentNode = this.findParentNodeOfNodeId(mutationRecord.target.nodeId);\n if (mutationRecord.type === \"attributes\" && !parentNode) {\n console.error(\"parentNode not found for attribute mutationRecord\", mutationRecord);\n console.error(\"this.documentRoot\", JSON.stringify(this.documentRoot, null, 2));\n }\n const diff = diffFromApplicationOfStaticVirtualDOMMutationRecordToConnection(\n mutationRecord,\n parentNode,\n connectionId,\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.visibleNodeIdsByConnectionId.get(connectionId)!,\n );\n if (diff) {\n diffs.push(diff);\n }\n });\n\n diffsByConnectionId.forEach((diffs, connectionId) => {\n if (diffs.length > 0) {\n const asServerMessages: Array<ServerMessage> = diffs;\n const serializedDiffs = JSON.stringify(asServerMessages);\n const webSocketContext = this.connectionIdToWebSocketContext.get(connectionId);\n if (!webSocketContext) {\n throw new Error(`webSocketContext not found in processModificationList`);\n }\n webSocketContext.webSocket.send(serializedDiffs);\n }\n });\n }\n\n private removeKnownNodesInMutation(mutation: StaticVirtualDOMMutationRecord): void {\n const virtualDOMElement = mutation.target;\n if (mutation.type === \"childList\") {\n mutation.removedNodes.forEach((childDOMElement: StaticVirtualDOMElement) => {\n this.removeVirtualDOMElement(childDOMElement);\n const index = virtualDOMElement.childNodes.indexOf(childDOMElement);\n virtualDOMElement.childNodes.splice(index, 1);\n });\n return;\n }\n }\n\n private removeVirtualDOMElement(virtualDOMElement: StaticVirtualDOMElement): void {\n this.nodeIdToNode.delete(virtualDOMElement.nodeId);\n this.nodeIdToParentNodeId.delete(virtualDOMElement.nodeId);\n for (const child of virtualDOMElement.childNodes) {\n this.removeVirtualDOMElement(child);\n }\n }\n\n static IsPongMessage(message: ClientMessage): message is PongMessage {\n return (message as PongMessage).type === \"pong\";\n }\n\n private dispatchRemoteEvent(webSocket: WebSocket, remoteEvent: RemoteEvent): void {\n if (this.disposed) {\n console.error(\"Cannot dispatch remote event after dispose\");\n throw new Error(\"This NetworkedDOM has been disposed\");\n }\n\n const connectionId = this.webSocketToConnectionId.get(webSocket);\n if (!connectionId) {\n console.error(\"Unknown web socket dispatched event:\", webSocket);\n return;\n }\n\n const visibleNodes = this.visibleNodeIdsByConnectionId.get(connectionId);\n if (!visibleNodes) {\n console.error(\"No visible nodes for connection: \" + connectionId);\n return;\n }\n\n if (!visibleNodes.has(remoteEvent.nodeId)) {\n // TODO - do a pass through the hierarchy to determine if this node should be visible to this connection id to prevent clients submitting events for nodes they can't (currently) see\n console.error(\"Node not visible for connection: \" + remoteEvent.nodeId);\n return;\n }\n\n const remappedNode = this.clientNodeIdToInternalNodeId.get(remoteEvent.nodeId);\n if (remappedNode) {\n remoteEvent.nodeId = remappedNode;\n }\n\n this.observableDOM.dispatchRemoteEventFromConnectionId(connectionId, remoteEvent);\n }\n\n private getStaticVirtualDOMElementByInternalNodeIdOrThrow(\n internalNodeId: number,\n ): StaticVirtualDOMElement {\n const remappedId = this.internalNodeIdToClientNodeId.get(internalNodeId);\n if (remappedId !== undefined) {\n const node = this.nodeIdToNode.get(remappedId);\n if (!node) {\n throw new Error(\"Remapped node not found with nodeId \" + remappedId);\n }\n return node;\n }\n const node = this.nodeIdToNode.get(internalNodeId);\n if (!node) {\n throw new Error(\"Node not found with nodeId:\" + internalNodeId);\n }\n return node;\n }\n\n private addKnownNodesInMutation(\n mutation: StaticVirtualDOMMutationIdsRecord,\n ): StaticVirtualDOMMutationRecord {\n const target = this.getStaticVirtualDOMElementByInternalNodeIdOrThrow(mutation.targetId);\n\n // TODO - avoid mutation in this conversion - use the attribute pair in the handling (would require changing StaticVirtualDOMMutationRecord.attributeName to be the key/value pair).\n if (mutation.attribute) {\n if (mutation.attribute.value !== null) {\n target.attributes[mutation.attribute.attributeName] = mutation.attribute.value;\n } else {\n delete target.attributes[mutation.attribute.attributeName];\n }\n }\n\n const previousSibling = mutation.previousSiblingId\n ? this.getStaticVirtualDOMElementByInternalNodeIdOrThrow(mutation.previousSiblingId)\n : null;\n\n if (mutation.type === \"childList\") {\n let index = 0;\n if (previousSibling) {\n index = target.childNodes.indexOf(previousSibling);\n if (index === -1) {\n throw new Error(\"Previous sibling is not currently a child of the parent element\");\n }\n index += 1;\n }\n mutation.addedNodes.forEach((childVirtualDOMElement: StaticVirtualDOMElement) => {\n this.addAndRemapNodeFromInstance(childVirtualDOMElement, target.nodeId);\n\n if (target.childNodes.indexOf(childVirtualDOMElement) === -1) {\n target.childNodes.splice(index, 0, childVirtualDOMElement);\n index++;\n }\n });\n } else if (mutation.type === \"attributes\") {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const attributePair = mutation.attribute!;\n if (attributePair.value === null) {\n delete target.attributes[attributePair.attributeName];\n } else {\n target.attributes[attributePair.attributeName] = attributePair.value;\n }\n } else if (mutation.type === \"characterData\") {\n // TODO - reimplement characterData\n throw new Error(\"characterData not supported\");\n // virtualDOMElement.textContent = targetNode.textContent ? targetNode.textContent : undefined;\n }\n\n const record: StaticVirtualDOMMutationRecord = {\n type: mutation.type,\n target,\n addedNodes: mutation.addedNodes,\n removedNodes: mutation.removedNodeIds.map((nodeId) => {\n return this.getStaticVirtualDOMElementByInternalNodeIdOrThrow(nodeId);\n }),\n previousSibling: mutation.previousSiblingId\n ? this.getStaticVirtualDOMElementByInternalNodeIdOrThrow(mutation.previousSiblingId)\n : null,\n attributeName: mutation.attribute ? mutation.attribute.attributeName : null,\n };\n\n return record;\n }\n\n getSnapshot(): StaticVirtualDOMElement {\n return this.documentRoot;\n }\n\n private addAndRemapNodeFromInstance(node: StaticVirtualDOMElement, parentNodeId: number) {\n const remappedNodeId = this.internalNodeIdToClientNodeId.get(node.nodeId);\n if (remappedNodeId !== undefined) {\n node.nodeId = remappedNodeId;\n } else {\n // This id might already refer to a node in this client's view. If so, we need to remap it to a new id.\n const existingClientReference = this.clientNodeIdToInternalNodeId.get(node.nodeId);\n if (existingClientReference) {\n const newNodeId = ++this.maximumNodeId;\n this.addRemappedNodeId(newNodeId, node.nodeId);\n node.nodeId = newNodeId;\n }\n }\n\n if (this.nodeIdToNode.has(node.nodeId)) {\n throw new Error(\"Node already exists with id \" + node.nodeId);\n }\n\n this.nodeIdToNode.set(node.nodeId, node);\n this.nodeIdToParentNodeId.set(node.nodeId, parentNodeId);\n this.maximumNodeId = Math.max(this.maximumNodeId, node.nodeId);\n\n for (const childNode of node.childNodes) {\n this.addAndRemapNodeFromInstance(childNode, node.nodeId);\n }\n }\n\n public getWebsocketConnectionIdMap() {\n // return a clone of the map\n return new Map(this.webSocketToConnectionId);\n }\n}\n", "import { LogMessage, StaticVirtualDOMElement } from \"@mml-io/observable-dom-common\";\n\nimport { VirtualDOMDiffStruct } from \"./common\";\nimport { NetworkedDOM, ObservableDOMFactory } from \"./NetworkedDOM\";\n\ntype LoadedState = {\n htmlContents: string;\n networkedDOM: NetworkedDOM;\n loaded: boolean;\n};\n\n/**\n * EditableNetworkedDOM wraps NetworkedDOM instances and presents them as a single document that can iterate through\n * revisions by being loaded multiple times with different contents. The connected clients receive deltas between the\n * revisions rather than a complete refresh.\n */\nexport class EditableNetworkedDOM {\n private htmlPath: string;\n private params: object = {};\n\n private websockets = new Set<WebSocket>();\n private loadedState: LoadedState | null = null;\n\n private observableDOMFactory: ObservableDOMFactory;\n private ignoreTextNodes: boolean;\n\n private logCallback?: (message: LogMessage) => void;\n\n constructor(\n htmlPath: string,\n observableDOMFactory: ObservableDOMFactory,\n ignoreTextNodes = true,\n logCallback?: (message: LogMessage) => void,\n ) {\n this.htmlPath = htmlPath;\n this.observableDOMFactory = observableDOMFactory;\n this.ignoreTextNodes = ignoreTextNodes;\n this.logCallback = logCallback;\n }\n\n public isLoaded() {\n return this.loadedState !== null;\n }\n\n public load(htmlContents: string, params?: object) {\n if (params !== undefined) {\n this.params = params;\n }\n\n let oldInstanceRoot: StaticVirtualDOMElement | null = null;\n let existingWebsocketMap: Map<WebSocket, number> | null = null;\n if (this.loadedState) {\n const oldInstance = this.loadedState.networkedDOM;\n existingWebsocketMap = oldInstance.getWebsocketConnectionIdMap();\n oldInstance.dispose();\n oldInstanceRoot = oldInstance.getSnapshot();\n }\n this.loadedState = null;\n\n let didLoad = false;\n const networkedDOM = new NetworkedDOM(\n this.observableDOMFactory,\n this.htmlPath,\n htmlContents,\n oldInstanceRoot,\n (domDiff: VirtualDOMDiffStruct | null, networkedDOM: NetworkedDOM) => {\n didLoad = true;\n if (this.loadedState) {\n this.loadedState.loaded = true;\n }\n networkedDOM.addExistingWebsockets(\n Array.from(this.websockets),\n existingWebsocketMap,\n domDiff,\n );\n },\n this.params,\n this.ignoreTextNodes,\n this.logCallback,\n );\n this.loadedState = {\n htmlContents,\n networkedDOM,\n loaded: didLoad,\n };\n }\n\n public reload() {\n if (this.loadedState) {\n this.load(this.loadedState.htmlContents, this.params);\n } else {\n console.warn(\"EditableNetworkedDOM.reload called whilst not loaded\");\n }\n }\n\n public dispose() {\n for (const ws of this.websockets) {\n ws.close();\n }\n this.websockets.clear();\n if (this.loadedState) {\n this.loadedState.networkedDOM.dispose();\n }\n this.loadedState = null;\n }\n\n public addWebSocket(webSocket: WebSocket) {\n this.websockets.add(webSocket);\n if (this.loadedState && this.loadedState.loaded) {\n this.loadedState.networkedDOM.addWebSocket(webSocket);\n }\n }\n\n public removeWebSocket(webSocket: WebSocket) {\n this.websockets.delete(webSocket);\n if (this.loadedState && this.loadedState.loaded) {\n this.loadedState.networkedDOM.removeWebSocket(webSocket);\n }\n }\n}\n"],
|
|
5
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V;AAAA,EACF;AAAA,EAEO,SAAS;AACd,QAAI,KAAK,aAAa;AACpB,WAAK,KAAK,KAAK,YAAY,cAAc,KAAK,MAAM;AAAA,IACtD,OAAO;AACL,cAAQ,KAAK,sDAAsD;AAAA,IACrE;AAAA,EACF;AAAA,EAEO,UAAU;AACf,eAAW,MAAM,KAAK,YAAY;AAChC,SAAG,MAAM;AAAA,IACX;AACA,SAAK,WAAW,MAAM;AACtB,QAAI,KAAK,aAAa;AACpB,WAAK,YAAY,aAAa,QAAQ;AAAA,IACxC;AACA,SAAK,cAAc;AAAA,EACrB;AAAA,EAEO,aAAa,WAAsB;AACxC,SAAK,WAAW,IAAI,SAAS;AAC7B,QAAI,KAAK,eAAe,KAAK,YAAY,QAAQ;AAC/C,WAAK,YAAY,aAAa,aAAa,SAAS;AAAA,IACtD;AAAA,EACF;AAAA,EAEO,gBAAgB,WAAsB;AAC3C,SAAK,WAAW,OAAO,SAAS;AAChC,QAAI,KAAK,eAAe,KAAK,YAAY,QAAQ;AAC/C,WAAK,YAAY,aAAa,gBAAgB,SAAS;AAAA,IACzD;AAAA,EACF;AACF;",
|
|
3
|
+
"sources": ["../src/rfc6902/deepEqual.ts", "../src/rfc6902/pointer.ts", "../src/rfc6902/util.ts", "../src/rfc6902/diff.ts", "../src/rfc6902/patch.ts", "../src/diffing.ts", "../src/NetworkedDOM.ts", "../src/EditableNetworkedDOM.ts"],
|
|
4
|
+
"sourcesContent": ["export function deepEqual(a: any, b: any): boolean {\n if (a === b) {\n return true;\n }\n\n if (Array.isArray(a) && Array.isArray(b)) {\n if (a.length !== b.length) {\n return false;\n }\n\n return a.every((elem, index) => {\n return deepEqual(elem, b[index]);\n });\n }\n\n if (typeof a === \"object\" && typeof b === \"object\" && a !== null && b !== null) {\n if (Array.isArray(a) || Array.isArray(b)) {\n return false;\n }\n\n const keys1 = Object.keys(a);\n const keys2 = Object.keys(b);\n if (keys1.length !== keys2.length || !keys1.every((key) => keys2.includes(key))) {\n return false;\n }\n\n for (const key in a) {\n if (!deepEqual(a[key], b[key])) {\n return false;\n }\n }\n\n if (keys1.length === 0 && a instanceof Date && b instanceof Date) {\n // Only need to check the length of 1 as they are already known to be equal\n return a.getTime() === b.getTime();\n }\n\n return true;\n }\n return false;\n}\n", "/**\nUnescape token part of a JSON Pointer string\n\n`token` should *not* contain any '/' characters.\n\n> Evaluation of each reference token begins by decoding any escaped\n> character sequence. This is performed by first transforming any\n> occurrence of the sequence '~1' to '/', and then transforming any\n> occurrence of the sequence '~0' to '~'. By performing the\n> substitutions in this order, an implementation avoids the error of\n> turning '~01' first into '~1' and then into '/', which would be\n> incorrect (the string '~01' correctly becomes '~1' after\n> transformation).\n\nHere's my take:\n\n~1 is unescaped with higher priority than ~0 because it is a lower-order escape character.\nI say \"lower order\" because '/' needs escaping due to the JSON Pointer serialization technique.\nWhereas, '~' is escaped because escaping '/' uses the '~' character.\n*/\nfunction unescape(token: string): string {\n return token.replace(/~1/g, \"/\").replace(/~0/g, \"~\");\n}\n\n/** Escape token part of a JSON Pointer string\n\n> '~' needs to be encoded as '~0' and '/'\n> needs to be encoded as '~1' when these characters appear in a\n> reference token.\n\nThis is the exact inverse of `unescape()`, so the reverse replacements must take place in reverse order.\n*/\nfunction escape(token: string): string {\n return token.replace(/~/g, \"~0\").replace(/\\//g, \"~1\");\n}\n\nexport interface PointerEvaluation {\n parent: any;\n key: string;\n value: any;\n}\n\n/**\nJSON Pointer representation\n*/\nexport class Pointer {\n constructor(public tokens = [\"\"]) {}\n /**\n `path` *must* be a properly escaped string.\n */\n static fromJSON(path: string): Pointer {\n const tokens = path.split(\"/\").map(unescape);\n if (tokens[0] !== \"\") throw new Error(`Invalid JSON Pointer: ${path}`);\n return new Pointer(tokens);\n }\n toString(): string {\n return this.tokens.map(escape).join(\"/\");\n }\n /**\n Returns an object with 'parent', 'key', and 'value' properties.\n In the special case that this Pointer's path == \"\",\n this object will be {parent: null, key: '', value: object}.\n Otherwise, parent and key will have the property such that parent[key] == value.\n */\n evaluate(object: any): PointerEvaluation {\n let parent: any = null;\n let key = \"\";\n let value = object;\n for (let i = 1, l = this.tokens.length; i < l; i++) {\n parent = value;\n key = this.tokens[i];\n if (key === \"__proto__\" || key === \"constructor\" || key === \"prototype\") {\n continue;\n }\n // not sure if this the best way to handle non-existant paths...\n value = (parent || {})[key];\n }\n return { parent, key, value };\n }\n get(object: any): any {\n return this.evaluate(object).value;\n }\n set(object: any, value: any): void {\n let cursor: any = object;\n for (let i = 1, l = this.tokens.length - 1, token = this.tokens[i]; i < l; i++) {\n // not sure if this the best way to handle non-existant paths...\n cursor = (cursor || {})[token];\n }\n if (cursor) {\n cursor[this.tokens[this.tokens.length - 1]] = value;\n }\n }\n push(token: string): void {\n // mutable\n this.tokens.push(token);\n }\n /**\n `token` should be a String. It'll be coerced to one anyway.\n\n immutable (shallowly)\n */\n add(token: string): Pointer {\n const tokens = this.tokens.concat(String(token));\n return new Pointer(tokens);\n }\n}\n", "export const hasOwnProperty = Object.prototype.hasOwnProperty;\n\nexport function objectType(object: any) {\n if (object === undefined) {\n return \"undefined\";\n }\n if (object === null) {\n return \"null\";\n }\n if (Array.isArray(object)) {\n return \"array\";\n }\n return typeof object;\n}\n\nfunction isNonPrimitive(value: any): value is object {\n // loose-equality checking for null is faster than strict checking for each of null/undefined/true/false\n // checking null first, then calling typeof, is faster than vice-versa\n return value != null && typeof value === \"object\";\n}\n\n/**\nRecursively copy a value.\n\n@param source - should be a JavaScript primitive, Array, Date, or (plain old) Object.\n@returns copy of source where every Array and Object have been recursively\n reconstructed from their constituent elements\n*/\nexport function clone<T>(source: T): T {\n if (!isNonPrimitive(source)) {\n // short-circuiting is faster than a single return\n return source;\n }\n // x.constructor == Array is the fastest way to check if x is an Array\n if (Array.isArray(source)) {\n // construction via imperative for-loop is faster than source.map(arrayVsObject)\n const length = (source as Array<any>).length;\n // setting the Array length during construction is faster than just `[]` or `new Array()`\n const arrayTarget: any = new Array(length);\n for (let i = 0; i < length; i++) {\n arrayTarget[i] = clone(source[i]);\n }\n return arrayTarget;\n }\n // Date\n if (source.constructor === Date) {\n const dateTarget: any = new Date(+source);\n return dateTarget;\n }\n // Object\n const objectTarget: any = {};\n // declaring the variable (with const) inside the loop is faster\n for (const key in source) {\n // hasOwnProperty costs a bit of performance, but it's semantically necessary\n // using a global helper is MUCH faster than calling source.hasOwnProperty(key)\n if (hasOwnProperty.call(source, key)) {\n objectTarget[key] = clone(source[key]);\n }\n }\n return objectTarget;\n}\n", "import { deepEqual } from \"./deepEqual\";\nimport { Pointer } from \"./pointer\"; // we only need this for type inference\nimport { hasOwnProperty, objectType } from \"./util\";\n\n/**\nAll diff* functions should return a list of operations, often empty.\n\nEach operation should be an object with two to four fields:\n* `op`: the name of the operation; one of \"add\", \"remove\", \"replace\", \"move\",\n \"copy\", or \"test\".\n* `path`: a JSON pointer string\n* `from`: a JSON pointer string\n* `value`: a JSON value\n\nThe different operations have different arguments.\n* \"add\": [`path`, `value`]\n* \"remove\": [`path`]\n* \"replace\": [`path`, `value`]\n* \"move\": [`from`, `path`]\n* \"copy\": [`from`, `path`]\n* \"test\": [`path`, `value`]\n\nCurrently this only really differentiates between Arrays, Objects, and\nEverything Else, which is pretty much just what JSON substantially\ndifferentiates between.\n*/\n\nexport interface AddOperation {\n op: \"add\";\n path: string;\n value: any;\n}\nexport interface RemoveOperation {\n op: \"remove\";\n path: string;\n}\nexport interface ReplaceOperation {\n op: \"replace\";\n path: string;\n value: any;\n}\nexport interface MoveOperation {\n op: \"move\";\n from: string;\n path: string;\n}\nexport interface CopyOperation {\n op: \"copy\";\n from: string;\n path: string;\n}\nexport interface TestOperation {\n op: \"test\";\n path: string;\n value: any;\n}\n\nexport type Operation =\n | AddOperation\n | RemoveOperation\n | ReplaceOperation\n | MoveOperation\n | CopyOperation\n | TestOperation;\n\nexport function isDestructive({ op }: Operation): boolean {\n return op === \"remove\" || op === \"replace\" || op === \"copy\" || op === \"move\";\n}\n\nexport type Diff = (input: any, output: any, ptr: Pointer) => Operation[];\n/**\nVoidableDiff exists to allow the user to provide a partial diff(...) function,\nfalling back to the built-in diffAny(...) function if the user-provided function\nreturns void.\n*/\nexport type VoidableDiff = (input: any, output: any, ptr: Pointer) => Operation[] | void;\n\nfunction wrapVoidableDiff(diff: VoidableDiff): Diff {\n function wrappedDiff(input: any, output: any, ptr: Pointer): Operation[] {\n const custom_patch = diff(input, output, ptr);\n // ensure an array is always returned\n return Array.isArray(custom_patch) ? custom_patch : diffAny(input, output, ptr, wrappedDiff);\n }\n return wrappedDiff;\n}\n\n/**\n Create a test operation based on `input`'s current evaluation of the JSON\n Pointer `path`; if such a pointer cannot be resolved, returns undefined.\n */\nfunction createTest(input: any, path: string): TestOperation | undefined {\n const endpoint = Pointer.fromJSON(path).evaluate(input);\n if (endpoint !== undefined) {\n return { op: \"test\", path, value: endpoint.value };\n }\n}\n\n/**\n Produce an 'application/json-patch+json'-type list of tests, to verify that\n existing values in an object are identical to the those captured at some\n checkpoint (whenever this function is called).\n\n This does not alter `input` or `output` unless they have a property getter with\n side-effects (which is not a good idea anyway).\n\n Returns list of test operations.\n */\nexport function createTests(input: any, patch: Operation[]): TestOperation[] {\n const tests = new Array<TestOperation>();\n patch.filter(isDestructive).forEach((operation) => {\n const pathTest = createTest(input, operation.path);\n if (pathTest) tests.push(pathTest);\n if (\"from\" in operation) {\n const fromTest = createTest(input, operation.from);\n if (fromTest) tests.push(fromTest);\n }\n });\n return tests;\n}\n\n/**\n Produce a 'application/json-patch+json'-type patch to get from one object to\n another.\n\n This does not alter `input` or `output` unless they have a property getter with\n side-effects (which is not a good idea anyway).\n\n `diff` is called on each pair of comparable non-primitive nodes in the\n `input`/`output` object trees, producing nested patches. Return `undefined`\n to fall back to default behaviour.\n\n Returns list of operations to perform on `input` to produce `output`.\n */\nexport function createPatch(input: any, output: any, diff?: VoidableDiff): Operation[] {\n const ptr = new Pointer();\n // a new Pointer gets a default path of [''] if not specified\n return (diff ? wrapVoidableDiff(diff) : diffAny)(input, output, ptr);\n}\n\n/**\nList the keys in `minuend` that are not in `subtrahend`.\n\nA key is only considered if it is both 1) an own-property (o.hasOwnProperty(k))\nof the object, and 2) has a value that is not undefined. This is to match JSON\nsemantics, where JSON object serialization drops keys with undefined values.\n\n@param minuend Object of interest\n@param subtrahend Object of comparison\n@returns Array of keys that are in `minuend` but not in `subtrahend`.\n*/\nexport function subtract(\n minuend: { [index: string]: any },\n subtrahend: { [index: string]: any },\n): string[] {\n // initialize empty object; we only care about the keys, the values can be anything\n const obj: { [index: string]: number } = {};\n // build up obj with all the properties of minuend\n for (const add_key in minuend) {\n if (hasOwnProperty.call(minuend, add_key) && minuend[add_key] !== undefined) {\n obj[add_key] = 1;\n }\n }\n // now delete all the properties of subtrahend from obj\n // (deleting a missing key has no effect)\n for (const del_key in subtrahend) {\n if (hasOwnProperty.call(subtrahend, del_key) && subtrahend[del_key] !== undefined) {\n delete obj[del_key];\n }\n }\n // finally, extract whatever keys remain in obj\n return Object.keys(obj);\n}\n\n/**\nList the keys that shared by all `objects`.\n\nThe semantics of what constitutes a \"key\" is described in {@link subtract}.\n\n@param objects Array of objects to compare\n@returns Array of keys that are in (\"own-properties\" of) every object in `objects`.\n*/\nexport function intersection(objects: ArrayLike<{ [index: string]: any }>): string[] {\n const length = objects.length;\n // prepare empty counter to keep track of how many objects each key occurred in\n const counter: { [index: string]: number } = {};\n // go through each object and increment the counter for each key in that object\n for (let i = 0; i < length; i++) {\n const object = objects[i];\n for (const key in object) {\n if (hasOwnProperty.call(object, key) && object[key] !== undefined) {\n counter[key] = (counter[key] || 0) + 1;\n }\n }\n }\n // now delete all keys from the counter that were not seen in every object\n for (const key in counter) {\n if (counter[key] < length) {\n delete counter[key];\n }\n }\n // finally, extract whatever keys remain in the counter\n return Object.keys(counter);\n}\n\ninterface ArrayAdd {\n op: \"add\";\n index: number;\n value: any;\n}\ninterface ArrayRemove {\n op: \"remove\";\n index: number;\n}\ninterface ArrayReplace {\n op: \"replace\";\n index: number;\n original: any;\n value: any;\n}\n/** These are not proper Operation objects, but will be converted into\nOperation objects eventually. {index} indicates the actual target position,\nnever 'end-of-array' */\ntype ArrayOperation = ArrayAdd | ArrayRemove | ArrayReplace;\nfunction isArrayAdd(array_operation: ArrayOperation): array_operation is ArrayAdd {\n return array_operation.op === \"add\";\n}\nfunction isArrayRemove(array_operation: ArrayOperation): array_operation is ArrayRemove {\n return array_operation.op === \"remove\";\n}\n\ninterface DynamicAlternative {\n /**\n * track prev key position for less memory usage\n */\n prev: string | null;\n operation: ArrayOperation | null;\n /**\n cost indicates the total cost of getting to this position.\n */\n cost: number;\n}\n\nfunction buildOperations(memo: Array<Array<DynamicAlternative>>, i: number, j: number) {\n let memoized: DynamicAlternative = memo[i][j];\n if (!memoized) {\n throw new Error(\"invalid memo\");\n }\n const operations: ArrayOperation[] = [];\n while (memoized && memoized.prev && memoized.operation) {\n operations.push(memoized.operation);\n const index = memoized.prev.split(\",\");\n memoized = memo[Number(index[0])][Number(index[1])];\n }\n return operations.reverse();\n}\n\n/**\nCalculate the shortest sequence of operations to get from `input` to `output`,\nusing a dynamic programming implementation of the Levenshtein distance algorithm.\n\nTo get from the input ABC to the output AZ we could just delete all the input\nand say \"insert A, insert Z\" and be done with it. That's what we do if the\ninput is empty. But we can be smarter.\n\n output\n A Z\n - -\n [0] 1 2\ninput A | 1 [0] 1\n B | 2 [1] 1\n C | 3 2 [2]\n\n1) start at 0,0 (+0)\n2) keep A (+0)\n3) remove B (+1)\n4) replace C with Z (+1)\n\nIf the `input` (source) is empty, they'll all be in the top row, resulting in an\narray of 'add' operations.\nIf the `output` (target) is empty, everything will be in the left column,\nresulting in an array of 'remove' operations.\n\n@returns A list of add/remove/replace operations.\n*/\nexport function diffArrays<T>(\n input: T[],\n output: T[],\n ptr: Pointer,\n diff: Diff = diffAny,\n): Operation[] {\n if (diff === void 0) {\n diff = diffAny;\n }\n // set up cost matrix (very simple initialization: just a map)\n const input_length = isNaN(input.length) || input.length <= 0 ? 0 : input.length;\n const output_length = isNaN(output.length) || output.length <= 0 ? 0 : output.length;\n let input_end = input_length;\n let output_end = output_length;\n while (input_end > 0 && output_end > 0) {\n // accelerate same arrays\n if (deepEqual(input[input_end - 1], output[output_end - 1])) {\n input_end--;\n output_end--;\n } else {\n break;\n }\n }\n const memo: Array<Array<DynamicAlternative>> = new Array(input_end + 1);\n for (let i = 0; i <= input_end; i++) {\n memo[i] = new Array(output_end + 1);\n }\n memo[0][0] = { prev: null, operation: null, cost: 0 };\n /**\n Calculate the cheapest sequence of operations required to get from\n input.slice(0, i) to output.slice(0, j).\n There may be other valid sequences with the same cost, but none cheaper.\n\n @param i The row in the layout above\n @param j The column in the layout above\n @returns An object containing a list of operations, along with the total cost\n of applying them (+1 for each add/remove/replace operation)\n */\n // handle weird objects masquerading as Arrays that don't have proper length\n // properties by using 0 for everything but positive numbers\n for (let i = 0; i <= input_end; i++) {\n for (let j = 0; j <= output_end; j++) {\n let memoized = memo[i][j];\n if (memoized) continue;\n const add_prev_key = `${i},${j - 1}`;\n const remove_prev_key = `${i - 1},${j}`;\n const replace_prev_key = `${i - 1},${j - 1}`;\n const remove_operation: ArrayRemove = {\n op: \"remove\",\n index: i - 1,\n };\n const add_operation: ArrayAdd = {\n op: \"add\",\n index: i - 1,\n value: output[j - 1],\n };\n\n if (j === 0) {\n memoized = {\n prev: remove_prev_key,\n operation: remove_operation,\n cost: memo[i - 1][j].cost + 1,\n };\n } else if (i === 0) {\n memoized = { prev: add_prev_key, operation: add_operation, cost: memo[i][j - 1].cost + 1 };\n } else {\n if (deepEqual(input[i - 1], output[j - 1])) {\n memoized = memo[i - 1][j - 1];\n } else {\n const remove_prev = memo[i - 1][j];\n const add_prev = memo[i][j - 1];\n const replace_prev = memo[i - 1][j - 1];\n const min_cost = Math.min(replace_prev.cost, add_prev.cost, remove_prev.cost);\n if (remove_prev.cost === min_cost) {\n memoized = {\n prev: remove_prev_key,\n operation: remove_operation,\n cost: memo[i - 1][j].cost + 1,\n };\n } else if (add_prev.cost === min_cost) {\n memoized = {\n prev: add_prev_key,\n operation: add_operation,\n cost: memo[i][j - 1].cost + 1,\n };\n } else {\n const replace_operation: ArrayReplace = {\n op: \"replace\",\n index: i - 1,\n original: input[i - 1],\n value: output[j - 1],\n };\n memoized = {\n prev: replace_prev_key,\n operation: replace_operation,\n cost: memo[i - 1][j - 1].cost + 1,\n };\n }\n }\n }\n memo[i][j] = memoized;\n }\n }\n const array_operations = buildOperations(memo, input_end, output_end);\n const [padded_operations] = array_operations.reduce<[Operation[], number]>(\n ([operations, padding], array_operation) => {\n if (isArrayAdd(array_operation)) {\n const padded_index = array_operation.index + 1 + padding;\n const index_token = padded_index < input_length + padding ? String(padded_index) : \"-\";\n const operation = {\n op: array_operation.op,\n path: ptr.add(index_token).toString(),\n value: array_operation.value,\n };\n // padding++ // maybe only if array_operation.index > -1 ?\n return [operations.concat(operation), padding + 1];\n } else if (isArrayRemove(array_operation)) {\n const operation = {\n op: array_operation.op,\n path: ptr.add(String(array_operation.index + padding)).toString(),\n };\n // padding--\n return [operations.concat(operation), padding - 1];\n } else {\n // replace\n const replace_ptr = ptr.add(String(array_operation.index + padding));\n const replace_operations = diff(\n array_operation.original,\n array_operation.value,\n replace_ptr,\n );\n return [operations.concat(...replace_operations), padding];\n }\n },\n [[], 0],\n );\n return padded_operations;\n}\n\nexport function diffObjects(\n input: any,\n output: any,\n ptr: Pointer,\n diff: Diff = diffAny,\n): Operation[] {\n // if a key is in input but not output -> remove it\n const operations: Operation[] = [];\n subtract(input, output).forEach((key) => {\n operations.push({ op: \"remove\", path: ptr.add(key).toString() });\n });\n // if a key is in output but not input -> add it\n subtract(output, input).forEach((key) => {\n operations.push({ op: \"add\", path: ptr.add(key).toString(), value: output[key] });\n });\n // if a key is in both, diff it recursively\n intersection([input, output]).forEach((key) => {\n operations.push(...diff(input[key], output[key], ptr.add(key)));\n });\n return operations;\n}\n\n/**\n`diffAny()` returns an empty array if `input` and `output` are materially equal\n(i.e., would produce equivalent JSON); otherwise it produces an array of patches\nthat would transform `input` into `output`.\n\n> Here, \"equal\" means that the value at the target location and the\n> value conveyed by \"value\" are of the same JSON type, and that they\n> are considered equal by the following rules for that type:\n> o strings: are considered equal if they contain the same number of\n> Unicode characters and their code points are byte-by-byte equal.\n> o numbers: are considered equal if their values are numerically\n> equal.\n> o arrays: are considered equal if they contain the same number of\n> values, and if each value can be considered equal to the value at\n> the corresponding position in the other array, using this list of\n> type-specific rules.\n> o objects: are considered equal if they contain the same number of\n> members, and if each member can be considered equal to a member in\n> the other object, by comparing their keys (as strings) and their\n> values (using this list of type-specific rules).\n> o literals (false, true, and null): are considered equal if they are\n> the same.\n*/\nexport function diffAny(input: any, output: any, ptr: Pointer, diff: Diff = diffAny): Operation[] {\n // strict equality handles literals, numbers, and strings (a sufficient but not necessary cause)\n if (input === output) {\n return [];\n }\n const input_type = objectType(input);\n const output_type = objectType(output);\n if (input_type === \"array\" && output_type === \"array\") {\n return diffArrays(input, output, ptr, diff);\n }\n if (input_type === \"object\" && output_type === \"object\") {\n return diffObjects(input, output, ptr, diff);\n }\n // at this point we know that input and output are materially different;\n // could be array -> object, object -> array, boolean -> undefined,\n // number -> string, or some other combination, but nothing that can be split\n // up into multiple patches: so `output` must replace `input` wholesale.\n return [{ op: \"replace\", path: ptr.toString(), value: output }];\n}\n", "import {\n AddOperation,\n CopyOperation,\n diffAny,\n MoveOperation,\n Operation,\n RemoveOperation,\n ReplaceOperation,\n TestOperation,\n} from \"./diff\";\nimport { Pointer } from \"./pointer\";\nimport { clone } from \"./util\";\n\nexport class MissingError extends Error {\n constructor(public path: string) {\n super(`Value required at path: ${path}`);\n this.name = \"MissingError\";\n }\n}\n\nexport class TestError extends Error {\n constructor(\n public actual: any,\n public expected: any,\n ) {\n super(`Test failed: ${actual} != ${expected}`);\n this.name = \"TestError\";\n }\n}\n\n/**\n Apply a 'application/json-patch+json'-type patch to an object.\n\n `patch` *must* be an array of operations.\n\n > Operation objects MUST have exactly one \"op\" member, whose value\n > indicates the operation to perform. Its value MUST be one of \"add\",\n > \"remove\", \"replace\", \"move\", \"copy\", or \"test\"; other values are\n > errors.\n\n This method mutates the target object in-place.\n\n @returns list of results, one for each operation: `null` indicated success,\n otherwise, the result will be an instance of one of the Error classes:\n MissingError, InvalidOperationError, or TestError.\n */\nexport function applyPatch(object: any, patch: Operation[]) {\n return patch.map((operation) => apply(object, operation));\n}\n\nfunction _add(object: any, key: string, value: any): void {\n if (Array.isArray(object)) {\n // `key` must be an index\n if (key === \"-\") {\n object.push(value);\n } else {\n const index = parseInt(key, 10);\n object.splice(index, 0, value);\n }\n } else {\n object[key] = value;\n }\n}\n\nfunction _remove(object: any, key: string): void {\n if (Array.isArray(object)) {\n // '-' syntax doesn't make sense when removing\n const index = parseInt(key, 10);\n object.splice(index, 1);\n } else {\n // not sure what the proper behavior is when path = ''\n delete object[key];\n }\n}\n\n/**\n> o If the target location specifies an array index, a new value is\n> inserted into the array at the specified index.\n> o If the target location specifies an object member that does not\n> already exist, a new member is added to the object.\n> o If the target location specifies an object member that does exist,\n> that member's value is replaced.\n*/\nexport function add(object: any, operation: AddOperation): MissingError | null {\n const endpoint = Pointer.fromJSON(operation.path).evaluate(object);\n // it's not exactly a \"MissingError\" in the same way that `remove` is -- more like a MissingParent, or something\n if (endpoint.parent === undefined) {\n return new MissingError(operation.path);\n }\n _add(endpoint.parent, endpoint.key, clone(operation.value));\n return null;\n}\n\n/**\n> The \"remove\" operation removes the value at the target location.\n> The target location MUST exist for the operation to be successful.\n*/\nexport function remove(object: any, operation: RemoveOperation): MissingError | null {\n // endpoint has parent, key, and value properties\n const endpoint = Pointer.fromJSON(operation.path).evaluate(object);\n if (endpoint.value === undefined) {\n return new MissingError(operation.path);\n }\n // not sure what the proper behavior is when path = ''\n _remove(endpoint.parent, endpoint.key);\n return null;\n}\n\n/**\n> The \"replace\" operation replaces the value at the target location\n> with a new value. The operation object MUST contain a \"value\" member\n> whose content specifies the replacement value.\n> The target location MUST exist for the operation to be successful.\n\n> This operation is functionally identical to a \"remove\" operation for\n> a value, followed immediately by an \"add\" operation at the same\n> location with the replacement value.\n\nEven more simply, it's like the add operation with an existence check.\n*/\nexport function replace(object: any, operation: ReplaceOperation): MissingError | null {\n const endpoint = Pointer.fromJSON(operation.path).evaluate(object);\n if (endpoint.parent === null) {\n return new MissingError(operation.path);\n }\n // this existence check treats arrays as a special case\n if (Array.isArray(endpoint.parent)) {\n if (parseInt(endpoint.key, 10) >= endpoint.parent.length) {\n return new MissingError(operation.path);\n }\n } else if (endpoint.value === undefined) {\n return new MissingError(operation.path);\n }\n endpoint.parent[endpoint.key] = operation.value;\n return null;\n}\n\n/**\n> The \"move\" operation removes the value at a specified location and\n> adds it to the target location.\n> The operation object MUST contain a \"from\" member, which is a string\n> containing a JSON Pointer value that references the location in the\n> target document to move the value from.\n> This operation is functionally identical to a \"remove\" operation on\n> the \"from\" location, followed immediately by an \"add\" operation at\n> the target location with the value that was just removed.\n\n> The \"from\" location MUST NOT be a proper prefix of the \"path\"\n> location; i.e., a location cannot be moved into one of its children.\n\nTODO: throw if the check described in the previous paragraph fails.\n*/\nexport function move(object: any, operation: MoveOperation): MissingError | null {\n const from_endpoint = Pointer.fromJSON(operation.from).evaluate(object);\n if (from_endpoint.value === undefined) {\n return new MissingError(operation.from);\n }\n const endpoint = Pointer.fromJSON(operation.path).evaluate(object);\n if (endpoint.parent === undefined) {\n return new MissingError(operation.path);\n }\n _remove(from_endpoint.parent, from_endpoint.key);\n _add(endpoint.parent, endpoint.key, from_endpoint.value);\n return null;\n}\n\n/**\n> The \"copy\" operation copies the value at a specified location to the\n> target location.\n> The operation object MUST contain a \"from\" member, which is a string\n> containing a JSON Pointer value that references the location in the\n> target document to copy the value from.\n> The \"from\" location MUST exist for the operation to be successful.\n\n> This operation is functionally identical to an \"add\" operation at the\n> target location using the value specified in the \"from\" member.\n\nAlternatively, it's like 'move' without the 'remove'.\n*/\nexport function copy(object: any, operation: CopyOperation): MissingError | null {\n const from_endpoint = Pointer.fromJSON(operation.from).evaluate(object);\n if (from_endpoint.value === undefined) {\n return new MissingError(operation.from);\n }\n const endpoint = Pointer.fromJSON(operation.path).evaluate(object);\n if (endpoint.parent === undefined) {\n return new MissingError(operation.path);\n }\n _add(endpoint.parent, endpoint.key, clone(from_endpoint.value));\n return null;\n}\n\n/**\n> The \"test\" operation tests that a value at the target location is\n> equal to a specified value.\n> The operation object MUST contain a \"value\" member that conveys the\n> value to be compared to the target location's value.\n> The target location MUST be equal to the \"value\" value for the\n> operation to be considered successful.\n*/\nexport function test(object: any, operation: TestOperation): TestError | null {\n const endpoint = Pointer.fromJSON(operation.path).evaluate(object);\n // TODO: this diffAny(...).length usage could/should be lazy\n if (diffAny(endpoint.value, operation.value, new Pointer()).length) {\n return new TestError(endpoint.value, operation.value);\n }\n return null;\n}\n\nexport class InvalidOperationError extends Error {\n constructor(public operation: Operation) {\n super(`Invalid operation: ${operation.op}`);\n this.name = \"InvalidOperationError\";\n }\n}\n\n/**\nSwitch on `operation.op`, applying the corresponding patch function for each\ncase to `object`.\n*/\nexport function apply(\n object: any,\n operation: Operation,\n): MissingError | InvalidOperationError | TestError | null {\n // not sure why TypeScript can't infer typesafety of:\n // {add, remove, replace, move, copy, test}[operation.op](object, operation)\n // (seems like a bug)\n switch (operation.op) {\n case \"add\":\n return add(object, operation);\n case \"remove\":\n return remove(object, operation);\n case \"replace\":\n return replace(object, operation);\n case \"move\":\n return move(object, operation);\n case \"copy\":\n return copy(object, operation);\n case \"test\":\n return test(object, operation);\n }\n return new InvalidOperationError(operation);\n}\n", "import {\n AttributeChangedDiff,\n ChildrenChangedDiff,\n Diff,\n ElementNodeDescription,\n NodeDescription,\n SnapshotMessage,\n TextChangedDiff,\n TextNodeDescription,\n} from \"@mml-io/networked-dom-protocol\";\nimport { StaticVirtualDOMElement } from \"@mml-io/observable-dom-common\";\n\nimport { NodeMapping, StaticVirtualDOMMutationRecord, VirtualDOMDiffStruct } from \"./common\";\nimport * as rfc6902 from \"./rfc6902\";\n\nexport const visibleToAttrName = \"visible-to\";\nexport const hiddenFromAttrName = \"hidden-from\";\n\n/**\n * This function does a lot of heavy lifting - it takes a mutation and applies it to the connection's view (affecting\n * which nodes are visible based on attributes etc.)\n *\n * As a result of the application it generates a diff for the particular connection's view of the DOM.\n */\nexport function diffFromApplicationOfStaticVirtualDOMMutationRecordToConnection(\n mutation: StaticVirtualDOMMutationRecord,\n parentNode: StaticVirtualDOMElement | null,\n connectionId: number,\n visibleNodesForConnection: Set<number>,\n): Diff | null {\n const virtualDOMElement = mutation.target;\n\n switch (mutation.type) {\n case \"snapshot\": {\n const nodeDescription = describeNodeWithChildrenForConnectionId(\n virtualDOMElement,\n connectionId,\n visibleNodesForConnection,\n );\n if (!nodeDescription) {\n return null;\n }\n const diff: SnapshotMessage = {\n type: \"snapshot\",\n snapshot: nodeDescription,\n documentTime: 0,\n };\n return diff;\n }\n case \"attributes\": {\n const visible = visibleNodesForConnection.has(virtualDOMElement.nodeId);\n\n if (!parentNode) {\n throw new Error(\"Node has no parent\");\n }\n const parentNodeId = parentNode.nodeId;\n const shouldBeVisible =\n shouldShowNodeToConnectionId(virtualDOMElement, connectionId) &&\n visibleNodesForConnection.has(parentNodeId);\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const attributeName = mutation.attributeName!;\n\n if (visible && shouldBeVisible) {\n let newValue = null; // null indicates deleted\n if (virtualDOMElement.attributes[attributeName] !== undefined) {\n newValue = virtualDOMElement.attributes[attributeName];\n }\n const diff: AttributeChangedDiff = {\n type: \"attributeChange\",\n nodeId: virtualDOMElement.nodeId,\n attribute: attributeName,\n newValue,\n };\n return diff;\n } else if (!visible && shouldBeVisible) {\n // Need to add this child to the connection's view now\n visibleNodesForConnection.add(virtualDOMElement.nodeId);\n\n const index = parentNode.childNodes.indexOf(virtualDOMElement);\n if (index === -1) {\n throw new Error(\"Node not found in parent's children\");\n }\n\n let previousNodeId = null;\n if (index > 0) {\n previousNodeId = getNodeIdOfPreviousVisibleSibling(\n parentNode,\n index - 1,\n visibleNodesForConnection,\n );\n }\n\n const nodeDescription = describeNodeWithChildrenForConnectionId(\n virtualDOMElement,\n connectionId,\n visibleNodesForConnection,\n );\n if (!nodeDescription) {\n throw new Error(\"Node description not found\");\n }\n const diff: ChildrenChangedDiff = {\n type: \"childrenChanged\",\n nodeId: parentNodeId,\n previousNodeId,\n addedNodes: [nodeDescription],\n removedNodes: [],\n };\n return diff;\n } else if (visible && !shouldBeVisible) {\n removeNodeAndChildrenFromVisibleNodes(virtualDOMElement, visibleNodesForConnection);\n const diff: ChildrenChangedDiff = {\n type: \"childrenChanged\",\n nodeId: parentNodeId,\n previousNodeId: null,\n addedNodes: [],\n removedNodes: [virtualDOMElement.nodeId],\n };\n return diff;\n } else if (!visible && !shouldBeVisible) {\n return null;\n }\n break;\n }\n case \"characterData\": {\n const visible = visibleNodesForConnection.has(virtualDOMElement.nodeId);\n if (!visible) {\n return null;\n }\n const diff: TextChangedDiff = {\n type: \"textChanged\",\n nodeId: virtualDOMElement.nodeId,\n text: virtualDOMElement.textContent || \"\",\n };\n return diff;\n }\n case \"childList\": {\n const visible = visibleNodesForConnection.has(virtualDOMElement.nodeId);\n if (!visible) {\n return null;\n }\n let previousSibling = mutation.previousSibling;\n let previousNodeId: number | null = null;\n if (previousSibling) {\n let previousIndex = virtualDOMElement.childNodes.indexOf(previousSibling);\n while (previousIndex !== -1) {\n previousSibling = virtualDOMElement.childNodes[previousIndex];\n if (visibleNodesForConnection.has(previousSibling.nodeId)) {\n previousNodeId = previousSibling.nodeId;\n break;\n }\n previousIndex--;\n }\n }\n\n const diff: ChildrenChangedDiff = {\n type: \"childrenChanged\",\n nodeId: virtualDOMElement.nodeId,\n previousNodeId,\n addedNodes: [],\n removedNodes: [],\n };\n\n mutation.addedNodes.forEach((childVirtualDOMElement: StaticVirtualDOMElement) => {\n const describedNode = describeNodeWithChildrenForConnectionId(\n childVirtualDOMElement,\n connectionId,\n visibleNodesForConnection,\n );\n if (!describedNode) {\n return;\n }\n diff.addedNodes.push(describedNode);\n });\n mutation.removedNodes.forEach((childVirtualDOMElement: StaticVirtualDOMElement) => {\n if (visibleNodesForConnection.has(childVirtualDOMElement.nodeId)) {\n removeNodeAndChildrenFromVisibleNodes(childVirtualDOMElement, visibleNodesForConnection);\n diff.removedNodes.push(childVirtualDOMElement.nodeId);\n }\n });\n\n if (diff.addedNodes.length > 0 || diff.removedNodes.length > 0) {\n return diff;\n }\n return null;\n }\n default:\n console.error(\"Unknown mutation type: \" + mutation.type);\n break;\n }\n return null;\n}\n\nfunction getNodeIdOfPreviousVisibleSibling(\n parentVirtualElement: StaticVirtualDOMElement,\n candidateIndex: number,\n visibleNodesForConnection: Set<number>,\n): number | null {\n if (candidateIndex > 0) {\n let previousSiblingIndex = candidateIndex;\n while (previousSiblingIndex >= 0) {\n const previousSibling = parentVirtualElement.childNodes[previousSiblingIndex];\n if (visibleNodesForConnection.has(previousSibling.nodeId)) {\n return previousSibling.nodeId;\n }\n previousSiblingIndex--;\n }\n }\n return null;\n}\n\nfunction shouldShowNodeToConnectionId(\n virtualDOMElement: StaticVirtualDOMElement,\n connectionId: number,\n): boolean {\n const visibleToAttr = virtualDOMElement.attributes[visibleToAttrName];\n const hiddenFromAttr = virtualDOMElement.attributes[hiddenFromAttrName];\n const connectionIdString = connectionId.toString();\n if (visibleToAttr !== undefined) {\n const visibleToList = visibleToAttr.split(\" \");\n const explicityVisible = visibleToList.includes(connectionIdString);\n if (!explicityVisible) {\n return false;\n }\n }\n if (hiddenFromAttr !== undefined) {\n const hiddenFromList = hiddenFromAttr.split(\" \");\n const explicityHidden = hiddenFromList.includes(connectionIdString);\n if (explicityHidden) {\n return false;\n }\n }\n return true;\n}\n\nexport function describeNodeWithChildrenForConnectionId(\n virtualDOMElement: StaticVirtualDOMElement,\n connectionId: number,\n visibleNodesForConnection: Set<number>,\n): NodeDescription | null {\n if (!shouldShowNodeToConnectionId(virtualDOMElement, connectionId)) {\n return null;\n }\n\n let emittedTagName = virtualDOMElement.tag;\n if (emittedTagName === \"#document\") {\n emittedTagName = \"DIV\";\n }\n if (emittedTagName === \"#text\") {\n const textNode: TextNodeDescription = {\n type: \"text\",\n nodeId: virtualDOMElement.nodeId,\n text: virtualDOMElement.textContent || \"\",\n };\n visibleNodesForConnection.add(textNode.nodeId);\n return textNode;\n } else {\n const node: ElementNodeDescription = {\n type: \"element\",\n nodeId: virtualDOMElement.nodeId,\n tag: emittedTagName,\n attributes: virtualDOMElement.attributes,\n children: [],\n text: virtualDOMElement.textContent,\n };\n visibleNodesForConnection.add(node.nodeId);\n\n for (const child of virtualDOMElement.childNodes) {\n const childNodeDescription = describeNodeWithChildrenForConnectionId(\n child,\n connectionId,\n visibleNodesForConnection,\n );\n if (childNodeDescription) {\n node.children.push(childNodeDescription);\n }\n }\n return node;\n }\n}\n\nfunction removeNodeAndChildrenFromVisibleNodes(\n virtualDOMElement: StaticVirtualDOMElement,\n visibleNodesForConnection: Set<number>,\n): void {\n visibleNodesForConnection.delete(virtualDOMElement.nodeId);\n for (const child of virtualDOMElement.childNodes) {\n if (!visibleNodesForConnection.has(child.nodeId)) {\n console.error(\"Inner child of removed element was not visible\", child.nodeId);\n }\n removeNodeAndChildrenFromVisibleNodes(child, visibleNodesForConnection);\n }\n}\n\nexport function findParentNodeOfNodeId(\n virtualDOMElement: StaticVirtualDOMElement,\n targetNodeId: number,\n): StaticVirtualDOMElement | null {\n // TODO - avoid a search of the whole tree for the node's parent\n // depth-first search of the whole virtual dom structure to find the node's parent\n for (const child of virtualDOMElement.childNodes) {\n if (child.nodeId === targetNodeId) {\n return virtualDOMElement;\n } else {\n const foundParentId = findParentNodeOfNodeId(child, targetNodeId);\n if (foundParentId) {\n return foundParentId;\n }\n }\n }\n return null;\n}\n\nexport function virtualDOMDiffToVirtualDOMMutationRecord(\n virtualStructure: StaticVirtualDOMElement,\n domDiff: rfc6902.Operation,\n): Array<StaticVirtualDOMMutationRecord> {\n const pointer = rfc6902.Pointer.fromJSON(domDiff.path);\n const grandParentTokens = pointer.tokens.slice(0, pointer.tokens.length - 2);\n const lastToken = pointer.tokens[pointer.tokens.length - 1];\n const secondLastToken = pointer.tokens[pointer.tokens.length - 2];\n\n if (lastToken === \"textContent\") {\n const nodePointer = new rfc6902.Pointer(pointer.tokens.slice(0, pointer.tokens.length - 1));\n const node = nodePointer.get(virtualStructure) as StaticVirtualDOMElement;\n return [\n {\n type: \"characterData\",\n target: node,\n addedNodes: [],\n removedNodes: [],\n attributeName: null,\n previousSibling: null,\n },\n ];\n }\n\n if (secondLastToken === \"attributes\") {\n // This handles attribute additions, changes, and removals\n const nodePointer = new rfc6902.Pointer(grandParentTokens);\n const node = nodePointer.get(virtualStructure) as StaticVirtualDOMElement;\n return [\n {\n type: \"attributes\",\n target: node,\n addedNodes: [],\n removedNodes: [],\n attributeName: lastToken,\n previousSibling: null,\n },\n ];\n }\n\n // Child changes\n\n if (secondLastToken === \"childNodes\") {\n const nodePointer = new rfc6902.Pointer(grandParentTokens);\n const node = nodePointer.get(virtualStructure) as StaticVirtualDOMElement;\n\n let previousSibling: StaticVirtualDOMElement | null = null;\n if (lastToken === \"-\") {\n if (node.childNodes.length > 0) {\n previousSibling = node.childNodes[node.childNodes.length - 1];\n } else {\n // There are no siblings to account for\n }\n } else {\n const index = parseInt(lastToken, 10);\n if (index === 0) {\n previousSibling = null;\n } else {\n previousSibling = node.childNodes[index - 1];\n }\n }\n const addedNodes: Array<StaticVirtualDOMElement> = [];\n const removedNodes: Array<StaticVirtualDOMElement> = [];\n switch (domDiff.op) {\n case \"add\": {\n addedNodes.push(domDiff.value);\n return [\n {\n type: \"childList\",\n target: node,\n addedNodes,\n removedNodes,\n previousSibling,\n attributeName: null,\n },\n ];\n }\n case \"remove\": {\n const removedNode = pointer.get(virtualStructure) as StaticVirtualDOMElement;\n removedNodes.push(removedNode);\n return [\n {\n type: \"childList\",\n target: node,\n addedNodes,\n removedNodes,\n previousSibling,\n attributeName: null,\n },\n ];\n }\n case \"replace\": {\n // This is a replacement of a single node\n const removedNode = pointer.get(virtualStructure) as StaticVirtualDOMElement;\n removedNodes.push(removedNode);\n addedNodes.push(domDiff.value);\n return [\n {\n type: \"childList\",\n target: node,\n addedNodes: [],\n removedNodes,\n previousSibling,\n attributeName: null,\n },\n {\n type: \"childList\",\n target: node,\n addedNodes,\n removedNodes: [],\n previousSibling,\n attributeName: null,\n },\n ];\n }\n }\n }\n\n if (domDiff.op === \"replace\" && domDiff.path === \"\") {\n const node = domDiff.value as StaticVirtualDOMElement;\n return [\n {\n type: \"snapshot\",\n target: node,\n addedNodes: [],\n removedNodes: [],\n previousSibling: null,\n attributeName: null,\n },\n ];\n }\n\n console.error(\"Unhandled JSON diff:\", JSON.stringify(domDiff, null, 2));\n throw new Error(\"Unhandled diff type\");\n}\n\nexport function calculateStaticVirtualDOMDiff(\n originalState: StaticVirtualDOMElement,\n latestState: StaticVirtualDOMElement,\n): VirtualDOMDiffStruct {\n const jsonPatchDiffs = rfc6902.createPatch(\n originalState,\n latestState,\n (a, b, ptr: rfc6902.Pointer) => {\n if (a.tag !== b.tag) {\n return [{ op: \"replace\", path: ptr.toString(), value: b }];\n }\n return;\n },\n );\n\n const nodeIdRemappings: Array<NodeMapping> = [];\n const virtualDOMDiffs: Array<rfc6902.Operation> = [];\n for (const diff of jsonPatchDiffs) {\n if (diff.op === \"replace\" && diff.path.endsWith(\"/nodeId\")) {\n const pointer = rfc6902.Pointer.fromJSON(diff.path);\n const originalValue = pointer.get(originalState);\n nodeIdRemappings.push({\n internalNodeId: diff.value,\n clientFacingNodeId: originalValue,\n });\n } else {\n virtualDOMDiffs.push(diff);\n }\n }\n\n return remapDuplicatedNodeIdsInOperations(\n {\n originalState,\n nodeIdRemappings,\n virtualDOMDiffs,\n },\n latestState,\n );\n}\n\nfunction getHighestNodeId(node: StaticVirtualDOMElement) {\n let highest = node.nodeId;\n for (const child of node.childNodes) {\n highest = Math.max(highest, getHighestNodeId(child));\n }\n return highest;\n}\n\nfunction getRemovedNodeIds(before: StaticVirtualDOMElement, diff: rfc6902.Operation) {\n const removedIds = new Set<number>();\n function addNode(node: StaticVirtualDOMElement) {\n removedIds.add(node.nodeId);\n for (const child of node.childNodes) {\n addNode(child);\n }\n }\n if (diff.op === \"replace\" || diff.op === \"remove\") {\n const removedNode = rfc6902.Pointer.fromJSON(diff.path).get(before);\n addNode(removedNode);\n }\n return removedIds;\n}\n\nfunction getNodeIdsFromNodeAndChildren(node: StaticVirtualDOMElement) {\n const nodeIds = new Set<number>();\n function addNode(node: StaticVirtualDOMElement) {\n nodeIds.add(node.nodeId);\n for (const child of node.childNodes) {\n addNode(child);\n }\n }\n addNode(node);\n return nodeIds;\n}\n\n// To avoid duplicate node ids at any point in the sequence of operations, apply the operations and determine if any node ids are duplicated at any point. If so, remap the node ids to be unique.\nfunction remapDuplicatedNodeIdsInOperations(\n virtualDOMDiffStruct: VirtualDOMDiffStruct,\n latestState: StaticVirtualDOMElement,\n): VirtualDOMDiffStruct {\n const { originalState, nodeIdRemappings, virtualDOMDiffs } = virtualDOMDiffStruct;\n\n const highestNodeIdAcrossStartAndEnd = Math.max(\n getHighestNodeId(originalState),\n getHighestNodeId(latestState),\n );\n let nextNodeId = highestNodeIdAcrossStartAndEnd + 1;\n\n const before = JSON.parse(JSON.stringify(originalState));\n\n function checkAndReplaceNodeIdsIfAlreadyInUse(\n node: StaticVirtualDOMElement,\n addingNodeIds: Set<number>,\n removedIds: Set<number>,\n ) {\n if (existingNodeIds.has(node.nodeId) && removedIds && !removedIds.has(node.nodeId)) {\n // This node id is already present so it must be replaced\n const newNodeId = nextNodeId++;\n nodeIdRemappings.push({\n internalNodeId: node.nodeId,\n clientFacingNodeId: newNodeId,\n });\n node.nodeId = newNodeId;\n addingNodeIds.add(newNodeId);\n } else {\n addingNodeIds.add(node.nodeId);\n }\n for (const child of node.childNodes) {\n checkAndReplaceNodeIdsIfAlreadyInUse(child, addingNodeIds, removedIds);\n }\n }\n\n const existingNodeIds = getNodeIdsFromNodeAndChildren(before);\n\n for (const diff of virtualDOMDiffs) {\n const pointer = rfc6902.Pointer.fromJSON(diff.path);\n const secondLastToken = pointer.tokens[pointer.tokens.length - 2];\n if (secondLastToken !== \"childNodes\") {\n continue;\n }\n const removedIds = getRemovedNodeIds(before, diff);\n const addingNodeIds = new Set<number>();\n if (diff.op === \"replace\" || diff.op === \"add\") {\n // The added node can use removed node ids, but it must not use any node ids that are still in use.\n checkAndReplaceNodeIdsIfAlreadyInUse(diff.value, addingNodeIds, removedIds);\n }\n removedIds.forEach((removedId) => {\n existingNodeIds.delete(removedId);\n });\n addingNodeIds.forEach((addingNodeId) => {\n existingNodeIds.add(addingNodeId);\n });\n\n const patchErrors = rfc6902.applyPatch(before, [diff]);\n if (patchErrors.length !== 1 || patchErrors[0] !== null) {\n throw new Error(\"Patch failed\");\n }\n }\n\n return virtualDOMDiffStruct;\n}\n", "import {\n ClientMessage,\n Diff,\n NodeDescription,\n PongMessage,\n RemoteEvent,\n ServerMessage,\n SnapshotMessage,\n} from \"@mml-io/networked-dom-protocol\";\nimport {\n LogMessage,\n ObservableDOMInterface,\n ObservableDOMMessage,\n ObservableDOMParameters,\n StaticVirtualDOMElement,\n StaticVirtualDOMMutationIdsRecord,\n} from \"@mml-io/observable-dom-common\";\n\nimport { StaticVirtualDOMMutationRecord, VirtualDOMDiffStruct } from \"./common\";\nimport {\n calculateStaticVirtualDOMDiff,\n describeNodeWithChildrenForConnectionId,\n diffFromApplicationOfStaticVirtualDOMMutationRecordToConnection,\n findParentNodeOfNodeId,\n virtualDOMDiffToVirtualDOMMutationRecord,\n} from \"./diffing\";\nimport { applyPatch } from \"./rfc6902\";\n\nexport const networkedDOMProtocolSubProtocol_v0_1 = \"networked-dom-v0.1\";\nexport const defaultWebsocketSubProtocol = networkedDOMProtocolSubProtocol_v0_1;\n\nexport type ObservableDOMFactory = (\n observableDOMParameters: ObservableDOMParameters,\n callback: (message: ObservableDOMMessage, observableDOM: ObservableDOMInterface) => void,\n) => ObservableDOMInterface;\n\n/**\n * NetworkedDOM is the main class for the networked-dom-document package. It is responsible for managing the state of\n * the document and the connections to the clients.\n *\n * It is constructed with an ObservableDOMFactory, which is responsible for creating the ObservableDOMInterface\n * implementation that is used to run the document.\n */\nexport class NetworkedDOM {\n // First to last in order of preference\n public static SupportedWebsocketSubProtocolsPreferenceOrder = [\n networkedDOMProtocolSubProtocol_v0_1,\n ];\n\n // Map from the node ids that the DOM uses internally to the node ids that clients refer to.\n private internalNodeIdToClientNodeId = new Map<number, number>();\n\n // Map from the node ids that clients refer to to the node ids that the DOM uses internally.\n private clientNodeIdToInternalNodeId = new Map<number, number>();\n\n private currentConnectionId = 1;\n private connectionIdToWebSocketContext = new Map<\n number,\n { webSocket: WebSocket; messageListener: (messageEvent: MessageEvent) => void }\n >();\n private webSocketToConnectionId = new Map<WebSocket, number>();\n private visibleNodeIdsByConnectionId = new Map<number, Set<number>>();\n private initialLoad = true;\n private readonly htmlPath: string;\n\n private disposed = false;\n private ignoreTextNodes: boolean;\n\n private documentRoot!: StaticVirtualDOMElement;\n private nodeIdToNode = new Map<number, StaticVirtualDOMElement>();\n private nodeIdToParentNodeId = new Map<number, number>();\n\n private observableDOM: ObservableDOMInterface;\n\n private documentEffectiveStartTime = Date.now();\n private latestDocumentTime = 0;\n private pingCounter = 1;\n private maximumNodeId = 0;\n\n private logCallback?: (message: LogMessage) => void;\n\n constructor(\n observableDOMFactory: ObservableDOMFactory,\n htmlPath: string,\n htmlContents: string,\n oldInstanceDocumentRoot: StaticVirtualDOMElement | null,\n onLoad: (domDiff: VirtualDOMDiffStruct | null, networkedDOM: NetworkedDOM) => void,\n params = {},\n ignoreTextNodes = true,\n logCallback?: (message: LogMessage) => void,\n ) {\n this.htmlPath = htmlPath;\n this.ignoreTextNodes = ignoreTextNodes;\n\n this.logCallback = logCallback || this.defaultLogCallback;\n\n this.observableDOM = observableDOMFactory(\n {\n htmlPath,\n htmlContents,\n params,\n ignoreTextNodes,\n pingIntervalMilliseconds: 5000,\n },\n (message: ObservableDOMMessage, observableDOM: ObservableDOMInterface) => {\n this.observableDOM = observableDOM;\n if (message.documentTime) {\n this.documentEffectiveStartTime = Date.now() - message.documentTime;\n this.latestDocumentTime = message.documentTime;\n }\n if (message.snapshot) {\n this.documentRoot = message.snapshot;\n const clonedSnapshot = JSON.parse(JSON.stringify(message.snapshot));\n\n if (!this.initialLoad) {\n throw new Error(\"Received snapshot after initial load\");\n }\n this.initialLoad = false;\n\n let domDiff: VirtualDOMDiffStruct | null = null;\n if (oldInstanceDocumentRoot) {\n domDiff = calculateStaticVirtualDOMDiff(oldInstanceDocumentRoot, clonedSnapshot);\n for (const remapping of domDiff.nodeIdRemappings) {\n this.addRemappedNodeId(remapping.clientFacingNodeId, remapping.internalNodeId);\n }\n }\n\n this.addAndRemapNodeFromInstance(this.documentRoot, -1);\n\n onLoad(domDiff, this);\n } else if (message.mutation) {\n if (this.initialLoad) {\n throw new Error(\"Received mutation before initial load\");\n }\n const mutation = this.addKnownNodesInMutation(message.mutation);\n this.processModification(mutation);\n this.removeKnownNodesInMutation(mutation);\n } else if (message.logMessage) {\n if (this.logCallback) {\n this.logCallback(message.logMessage);\n }\n } else {\n if (message.documentTime) {\n // This is just a regular ping message to update the document time - send the document time to all connected clients\n this.sendPings();\n return;\n }\n console.error(\"Unknown message type from observableDOM\", message);\n }\n },\n );\n }\n\n private defaultLogCallback(message: LogMessage) {\n const getLogFn = (level: string) => {\n switch (level) {\n case \"system\":\n return console.error;\n case \"error\":\n return console.error;\n case \"warn\":\n return console.warn;\n case \"log\":\n return console.log;\n case \"info\":\n return console.info;\n default:\n return console.log;\n }\n };\n\n const logFn = getLogFn(message.level);\n logFn(`${message.level.toUpperCase()} (${this.htmlPath}):`, ...message.content);\n }\n\n private addRemappedNodeId(clientFacingNodeId: number, internalNodeId: number) {\n this.internalNodeIdToClientNodeId.set(internalNodeId, clientFacingNodeId);\n this.clientNodeIdToInternalNodeId.set(clientFacingNodeId, internalNodeId);\n this.maximumNodeId = Math.max(this.maximumNodeId, Math.max(clientFacingNodeId, internalNodeId));\n }\n\n private sendPings() {\n const ping = this.pingCounter++;\n if (this.pingCounter > 1000) {\n this.pingCounter = 1;\n }\n const pingMessage: Array<ServerMessage> = [\n {\n type: \"ping\",\n ping,\n documentTime: this.getDocumentTime(),\n },\n ];\n const stringified = JSON.stringify(pingMessage);\n this.connectionIdToWebSocketContext.forEach((webSocketContext) => {\n webSocketContext.webSocket.send(stringified);\n });\n }\n\n private getInitialSnapshot(\n connectionId: number,\n documentVirtualDOMElement: StaticVirtualDOMElement,\n ): SnapshotMessage {\n const visibleNodesForConnection = this.visibleNodeIdsByConnectionId.get(connectionId);\n if (!visibleNodesForConnection) {\n const err = new Error(\n `visibleNodesForConnection not found for connectionId in getInitialSnapshot: ${connectionId}`,\n );\n console.error(err);\n throw err;\n }\n const domSnapshot: NodeDescription | null = describeNodeWithChildrenForConnectionId(\n documentVirtualDOMElement,\n connectionId,\n visibleNodesForConnection,\n );\n if (!domSnapshot) {\n throw new Error(`domSnapshot was not generated`);\n }\n return {\n type: \"snapshot\",\n snapshot: domSnapshot,\n documentTime: Date.now() - this.documentEffectiveStartTime,\n };\n }\n\n public getDocumentTime(): number {\n return this.latestDocumentTime;\n }\n\n public addExistingWebsockets(\n websockets: Array<WebSocket>,\n existingWebsocketMap: Map<WebSocket, number> | null,\n domDiff: VirtualDOMDiffStruct | null,\n ) {\n const connectionIds = [];\n for (const websocket of websockets) {\n let existingId = null;\n if (existingWebsocketMap !== null) {\n existingId = existingWebsocketMap.get(websocket);\n }\n const { connectionId } = this.registerWebsocket(websocket, existingId);\n connectionIds.push(connectionId);\n }\n\n if (domDiff) {\n const diffsByConnectionId = new Map<number, Array<Diff>>(\n connectionIds.map((connectionId) => [connectionId, []]),\n );\n\n // Each of the websockets needs to have the original state of the document re-applied to it to determine visible\n // nodes, but not sent (they already have the old version of the document as their state).\n for (const connectionId of connectionIds) {\n // Ignore the return value - the side effect is that the visible nodes for the connection are set\n this.getInitialSnapshot(connectionId, domDiff.originalState);\n }\n\n for (const virtualDOMDiff of domDiff.virtualDOMDiffs) {\n // Convert the diff of the virtual dom data structure to a MutationRecord-like diff and then handle it as if it were a MutationRecord\n // The difficulty here is that the JSON diff is typed by add/remove/replace of elements of a hierarchy specified by paths, but MutationRecords are specified by type of operation and nodeIds\n\n const mutationRecordLikes = virtualDOMDiffToVirtualDOMMutationRecord(\n domDiff.originalState,\n virtualDOMDiff,\n );\n\n if (virtualDOMDiff.path === \"\" && virtualDOMDiff.op === \"replace\") {\n // The patch is a snapshot replacement - no need to check the patch validity\n } else {\n const patchResults = applyPatch(domDiff.originalState, [virtualDOMDiff]);\n for (const patchResult of patchResults) {\n if (patchResult !== null) {\n console.error(\"Patching virtual dom structure resulted in error\", patchResult);\n throw patchResult;\n }\n }\n }\n\n for (const mutationRecordLike of mutationRecordLikes) {\n const targetNodeId = mutationRecordLike.target.nodeId;\n const virtualElementParent = findParentNodeOfNodeId(domDiff.originalState, targetNodeId);\n diffsByConnectionId.forEach((diffs, connectionId) => {\n const mutationDiff = diffFromApplicationOfStaticVirtualDOMMutationRecordToConnection(\n mutationRecordLike,\n virtualElementParent,\n connectionId,\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.visibleNodeIdsByConnectionId.get(connectionId)!,\n );\n if (mutationDiff) {\n diffs.push(mutationDiff);\n }\n });\n }\n }\n\n diffsByConnectionId.forEach((diffs, connectionId) => {\n if (diffs.length === 0) {\n // Need to add an \"empty\" message to allow passing the document time to the client\n diffs.push({\n type: \"childrenChanged\",\n nodeId: this.documentRoot.nodeId,\n previousNodeId: null,\n addedNodes: [],\n removedNodes: [],\n });\n }\n const asServerMessages: Array<ServerMessage> = diffs;\n const firstDiff = diffs[0];\n firstDiff.documentTime = this.getDocumentTime();\n const serializedDiffs = JSON.stringify(asServerMessages);\n const webSocketContext = this.connectionIdToWebSocketContext.get(connectionId);\n if (!webSocketContext) {\n throw new Error(`webSocketContext not found in addExistingWebsockets`);\n }\n webSocketContext.webSocket.send(serializedDiffs);\n });\n } else {\n const documentVirtualDOMElement = this.documentRoot;\n if (!documentVirtualDOMElement) {\n throw new Error(`documentVirtualDOMElement not found in getInitialSnapshot`);\n }\n for (const connectionId of connectionIds) {\n const webSocketContext = this.connectionIdToWebSocketContext.get(connectionId);\n if (!webSocketContext) {\n throw new Error(`webSocketContext not found in addExistingWebsockets`);\n }\n const asServerMessages: Array<ServerMessage> = [\n this.getInitialSnapshot(connectionId, documentVirtualDOMElement),\n ];\n const serializedSnapshotMessage = JSON.stringify(asServerMessages);\n webSocketContext.webSocket.send(serializedSnapshotMessage);\n }\n }\n\n for (const connectionId of connectionIds) {\n this.observableDOM.addConnectedUserId(connectionId);\n }\n }\n\n private findParentNodeOfNodeId(targetNodeId: number): StaticVirtualDOMElement | null {\n const parentNodeId = this.nodeIdToParentNodeId.get(targetNodeId);\n if (parentNodeId === undefined) {\n throw new Error(\"Parent node ID not found\");\n }\n const node = this.nodeIdToNode.get(parentNodeId);\n if (!node) {\n throw new Error(\"Parent node not found:\" + parentNodeId);\n }\n return node;\n }\n\n private registerWebsocket(\n webSocket: WebSocket,\n existingConnectionId: number | null = null,\n ): { connectionId: number } {\n let connectionId: number;\n if (existingConnectionId !== null) {\n connectionId = existingConnectionId;\n this.currentConnectionId = Math.max(this.currentConnectionId, connectionId + 1);\n } else {\n connectionId = this.currentConnectionId++;\n }\n const webSocketContext = {\n webSocket,\n messageListener: (messageEvent: MessageEvent) => {\n const string = String(messageEvent.data);\n let parsed;\n try {\n parsed = JSON.parse(string) as ClientMessage;\n } catch (e) {\n console.error(`Error parsing message from websocket: ${string}`, e);\n console.trace();\n return;\n }\n\n if (NetworkedDOM.IsPongMessage(parsed)) {\n // Ignore pongs for now\n return;\n }\n\n this.dispatchRemoteEvent(webSocket, parsed);\n },\n };\n this.connectionIdToWebSocketContext.set(connectionId, webSocketContext);\n this.visibleNodeIdsByConnectionId.set(connectionId, new Set());\n this.webSocketToConnectionId.set(webSocket, connectionId);\n webSocket.addEventListener(\"message\", webSocketContext.messageListener);\n return { connectionId };\n }\n\n public static handleWebsocketSubprotocol(protocols: Set<string> | Array<string>): string | false {\n const protocolsSet = new Set(protocols);\n // Find highest priority (first in the array) protocol that is supported\n for (const protocol of NetworkedDOM.SupportedWebsocketSubProtocolsPreferenceOrder) {\n if (protocolsSet.has(protocol)) {\n return protocol;\n }\n }\n return false;\n }\n\n public addWebSocket(webSocket: WebSocket): void {\n if (this.initialLoad) {\n throw new Error(\"addWebSocket called before initial load - unsupported at this time\");\n }\n if (this.disposed) {\n console.error(\"addWebSocket called on disposed NetworkedDOM\");\n throw new Error(\"This NetworkedDOM has been disposed\");\n }\n\n if (webSocket.protocol) {\n if (\n NetworkedDOM.SupportedWebsocketSubProtocolsPreferenceOrder.indexOf(webSocket.protocol) ===\n -1\n ) {\n const errorMessageString = `Unsupported websocket subprotocol: ${webSocket.protocol}`;\n const errorMessage: Array<ServerMessage> = [\n {\n type: \"error\",\n message: errorMessageString,\n },\n ];\n webSocket.send(JSON.stringify(errorMessage));\n webSocket.close();\n return;\n }\n } else {\n // TODO - Revisit the default handling of non-protocol websockets. It is easier to debug if a lack of protocol results in an error.\n // Assume for now that this client is a legacy MML client that doesn't send a protocol, but send a warning to the client to encourage specifying a protocol\n const warningMessageString = `No websocket subprotocol specified. Please specify a subprotocol to ensure compatibility with networked-dom servers. Assuming subprotocol \"${defaultWebsocketSubProtocol}\" for this connection.`;\n const warningMessage: Array<ServerMessage> = [\n {\n type: \"warning\",\n message: warningMessageString,\n },\n ];\n webSocket.send(JSON.stringify(warningMessage));\n }\n\n const { connectionId } = this.registerWebsocket(webSocket);\n const documentVirtualDOMElement = this.documentRoot;\n if (!documentVirtualDOMElement) {\n throw new Error(`documentVirtualDOMElement not found in getInitialSnapshot`);\n }\n const asServerMessages: Array<ServerMessage> = [\n this.getInitialSnapshot(connectionId, documentVirtualDOMElement),\n ];\n const serializedSnapshotMessage = JSON.stringify(asServerMessages);\n webSocket.send(serializedSnapshotMessage);\n this.observableDOM.addConnectedUserId(connectionId);\n }\n\n public removeWebSocket(webSocket: WebSocket): void {\n const connectionId = this.webSocketToConnectionId.get(webSocket);\n if (!connectionId) {\n return;\n }\n this.observableDOM.removeConnectedUserId(connectionId);\n const webSocketContext = this.connectionIdToWebSocketContext.get(connectionId);\n if (!webSocketContext) {\n throw new Error(\"Missing context for websocket\");\n }\n webSocket.removeEventListener(\"message\", webSocketContext.messageListener);\n this.connectionIdToWebSocketContext.delete(connectionId);\n this.visibleNodeIdsByConnectionId.delete(connectionId);\n this.webSocketToConnectionId.delete(webSocket);\n }\n\n public dispose(): void {\n this.disposed = true;\n\n // Handle all of the remaining mutations that the disconnections could have caused\n this.observableDOM.dispose();\n\n for (const [webSocket, connectionId] of this.webSocketToConnectionId) {\n const webSocketContext = this.connectionIdToWebSocketContext.get(connectionId);\n if (!webSocketContext) {\n throw new Error(\"Missing context for websocket\");\n }\n webSocket.removeEventListener(\"message\", webSocketContext.messageListener);\n this.connectionIdToWebSocketContext.delete(connectionId);\n this.visibleNodeIdsByConnectionId.delete(connectionId);\n this.webSocketToConnectionId.delete(webSocket);\n }\n }\n\n private processModification(mutationRecord: StaticVirtualDOMMutationRecord): void {\n const documentVirtualDOMElement = this.documentRoot;\n if (!documentVirtualDOMElement) {\n throw new Error(`document not created in processModification`);\n }\n\n for (const [, visibleNodesForConnection] of this.visibleNodeIdsByConnectionId) {\n visibleNodesForConnection.add(documentVirtualDOMElement.nodeId);\n }\n\n const diffsByConnectionId = new Map<number, Array<Diff>>(\n Array.from(this.connectionIdToWebSocketContext.keys()).map((connectionId) => [\n connectionId,\n [],\n ]),\n );\n\n diffsByConnectionId.forEach((diffs, connectionId) => {\n const parentNode = this.findParentNodeOfNodeId(mutationRecord.target.nodeId);\n if (mutationRecord.type === \"attributes\" && !parentNode) {\n console.error(\"parentNode not found for attribute mutationRecord\", mutationRecord);\n console.error(\"this.documentRoot\", JSON.stringify(this.documentRoot, null, 2));\n }\n const diff = diffFromApplicationOfStaticVirtualDOMMutationRecordToConnection(\n mutationRecord,\n parentNode,\n connectionId,\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.visibleNodeIdsByConnectionId.get(connectionId)!,\n );\n if (diff) {\n diffs.push(diff);\n }\n });\n\n diffsByConnectionId.forEach((diffs, connectionId) => {\n if (diffs.length > 0) {\n const asServerMessages: Array<ServerMessage> = diffs;\n const serializedDiffs = JSON.stringify(asServerMessages);\n const webSocketContext = this.connectionIdToWebSocketContext.get(connectionId);\n if (!webSocketContext) {\n throw new Error(`webSocketContext not found in processModificationList`);\n }\n webSocketContext.webSocket.send(serializedDiffs);\n }\n });\n }\n\n private removeKnownNodesInMutation(mutation: StaticVirtualDOMMutationRecord): void {\n const virtualDOMElement = mutation.target;\n if (mutation.type === \"childList\") {\n mutation.removedNodes.forEach((childDOMElement: StaticVirtualDOMElement) => {\n this.removeVirtualDOMElement(childDOMElement);\n const index = virtualDOMElement.childNodes.indexOf(childDOMElement);\n virtualDOMElement.childNodes.splice(index, 1);\n });\n return;\n }\n }\n\n private removeVirtualDOMElement(virtualDOMElement: StaticVirtualDOMElement): void {\n this.nodeIdToNode.delete(virtualDOMElement.nodeId);\n this.nodeIdToParentNodeId.delete(virtualDOMElement.nodeId);\n for (const child of virtualDOMElement.childNodes) {\n this.removeVirtualDOMElement(child);\n }\n }\n\n static IsPongMessage(message: ClientMessage): message is PongMessage {\n return (message as PongMessage).type === \"pong\";\n }\n\n private dispatchRemoteEvent(webSocket: WebSocket, remoteEvent: RemoteEvent): void {\n if (this.disposed) {\n console.error(\"Cannot dispatch remote event after dispose\");\n throw new Error(\"This NetworkedDOM has been disposed\");\n }\n\n const connectionId = this.webSocketToConnectionId.get(webSocket);\n if (!connectionId) {\n console.error(\"Unknown web socket dispatched event:\", webSocket);\n return;\n }\n\n const visibleNodes = this.visibleNodeIdsByConnectionId.get(connectionId);\n if (!visibleNodes) {\n console.error(\"No visible nodes for connection: \" + connectionId);\n return;\n }\n\n if (!visibleNodes.has(remoteEvent.nodeId)) {\n // TODO - do a pass through the hierarchy to determine if this node should be visible to this connection id to prevent clients submitting events for nodes they can't (currently) see\n console.error(\"Node not visible for connection: \" + remoteEvent.nodeId);\n return;\n }\n\n const remappedNode = this.clientNodeIdToInternalNodeId.get(remoteEvent.nodeId);\n if (remappedNode) {\n remoteEvent.nodeId = remappedNode;\n }\n\n this.observableDOM.dispatchRemoteEventFromConnectionId(connectionId, remoteEvent);\n }\n\n private getStaticVirtualDOMElementByInternalNodeIdOrThrow(\n internalNodeId: number,\n ): StaticVirtualDOMElement {\n const remappedId = this.internalNodeIdToClientNodeId.get(internalNodeId);\n if (remappedId !== undefined) {\n const node = this.nodeIdToNode.get(remappedId);\n if (!node) {\n throw new Error(\"Remapped node not found with nodeId \" + remappedId);\n }\n return node;\n }\n const node = this.nodeIdToNode.get(internalNodeId);\n if (!node) {\n throw new Error(\"Node not found with nodeId:\" + internalNodeId);\n }\n return node;\n }\n\n private addKnownNodesInMutation(\n mutation: StaticVirtualDOMMutationIdsRecord,\n ): StaticVirtualDOMMutationRecord {\n const target = this.getStaticVirtualDOMElementByInternalNodeIdOrThrow(mutation.targetId);\n\n // TODO - avoid mutation in this conversion - use the attribute pair in the handling (would require changing StaticVirtualDOMMutationRecord.attributeName to be the key/value pair).\n if (mutation.attribute) {\n if (mutation.attribute.value !== null) {\n target.attributes[mutation.attribute.attributeName] = mutation.attribute.value;\n } else {\n delete target.attributes[mutation.attribute.attributeName];\n }\n }\n\n const previousSibling = mutation.previousSiblingId\n ? this.getStaticVirtualDOMElementByInternalNodeIdOrThrow(mutation.previousSiblingId)\n : null;\n\n if (mutation.type === \"childList\") {\n let index = 0;\n if (previousSibling) {\n index = target.childNodes.indexOf(previousSibling);\n if (index === -1) {\n throw new Error(\"Previous sibling is not currently a child of the parent element\");\n }\n index += 1;\n }\n mutation.addedNodes.forEach((childVirtualDOMElement: StaticVirtualDOMElement) => {\n this.addAndRemapNodeFromInstance(childVirtualDOMElement, target.nodeId);\n\n if (target.childNodes.indexOf(childVirtualDOMElement) === -1) {\n target.childNodes.splice(index, 0, childVirtualDOMElement);\n index++;\n }\n });\n } else if (mutation.type === \"attributes\") {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const attributePair = mutation.attribute!;\n if (attributePair.value === null) {\n delete target.attributes[attributePair.attributeName];\n } else {\n target.attributes[attributePair.attributeName] = attributePair.value;\n }\n } else if (mutation.type === \"characterData\") {\n // TODO - reimplement characterData\n throw new Error(\"characterData not supported\");\n // virtualDOMElement.textContent = targetNode.textContent ? targetNode.textContent : undefined;\n }\n\n const record: StaticVirtualDOMMutationRecord = {\n type: mutation.type,\n target,\n addedNodes: mutation.addedNodes,\n removedNodes: mutation.removedNodeIds.map((nodeId) => {\n return this.getStaticVirtualDOMElementByInternalNodeIdOrThrow(nodeId);\n }),\n previousSibling: mutation.previousSiblingId\n ? this.getStaticVirtualDOMElementByInternalNodeIdOrThrow(mutation.previousSiblingId)\n : null,\n attributeName: mutation.attribute ? mutation.attribute.attributeName : null,\n };\n\n return record;\n }\n\n getSnapshot(): StaticVirtualDOMElement {\n return this.documentRoot;\n }\n\n private addAndRemapNodeFromInstance(node: StaticVirtualDOMElement, parentNodeId: number) {\n const remappedNodeId = this.internalNodeIdToClientNodeId.get(node.nodeId);\n if (remappedNodeId !== undefined) {\n node.nodeId = remappedNodeId;\n } else {\n // This id might already refer to a node in this client's view. If so, we need to remap it to a new id.\n const existingClientReference = this.clientNodeIdToInternalNodeId.get(node.nodeId);\n if (existingClientReference) {\n const newNodeId = ++this.maximumNodeId;\n this.addRemappedNodeId(newNodeId, node.nodeId);\n node.nodeId = newNodeId;\n }\n }\n\n if (this.nodeIdToNode.has(node.nodeId)) {\n throw new Error(\"Node already exists with id \" + node.nodeId);\n }\n\n this.nodeIdToNode.set(node.nodeId, node);\n this.nodeIdToParentNodeId.set(node.nodeId, parentNodeId);\n this.maximumNodeId = Math.max(this.maximumNodeId, node.nodeId);\n\n for (const childNode of node.childNodes) {\n this.addAndRemapNodeFromInstance(childNode, node.nodeId);\n }\n }\n\n public getWebsocketConnectionIdMap() {\n // return a clone of the map\n return new Map(this.webSocketToConnectionId);\n }\n}\n", "import { LogMessage, StaticVirtualDOMElement } from \"@mml-io/observable-dom-common\";\n\nimport { VirtualDOMDiffStruct } from \"./common\";\nimport { NetworkedDOM, ObservableDOMFactory } from \"./NetworkedDOM\";\n\ntype LoadedState = {\n htmlContents: string;\n networkedDOM: NetworkedDOM;\n loaded: boolean;\n};\n\n/**\n * EditableNetworkedDOM wraps NetworkedDOM instances and presents them as a single document that can iterate through\n * revisions by being loaded multiple times with different contents. The connected clients receive deltas between the\n * revisions rather than a complete refresh.\n */\nexport class EditableNetworkedDOM {\n private htmlPath: string;\n private params: object = {};\n\n private websockets = new Set<WebSocket>();\n private loadedState: LoadedState | null = null;\n\n private observableDOMFactory: ObservableDOMFactory;\n private ignoreTextNodes: boolean;\n\n private logCallback?: (message: LogMessage) => void;\n\n constructor(\n htmlPath: string,\n observableDOMFactory: ObservableDOMFactory,\n ignoreTextNodes = true,\n logCallback?: (message: LogMessage) => void,\n ) {\n this.htmlPath = htmlPath;\n this.observableDOMFactory = observableDOMFactory;\n this.ignoreTextNodes = ignoreTextNodes;\n this.logCallback = logCallback;\n }\n\n public isLoaded() {\n return this.loadedState !== null;\n }\n\n public load(htmlContents: string, params?: object) {\n if (params !== undefined) {\n this.params = params;\n }\n\n let oldInstanceRoot: StaticVirtualDOMElement | null = null;\n let existingWebsocketMap: Map<WebSocket, number> | null = null;\n if (this.loadedState) {\n const oldInstance = this.loadedState.networkedDOM;\n existingWebsocketMap = oldInstance.getWebsocketConnectionIdMap();\n oldInstance.dispose();\n oldInstanceRoot = oldInstance.getSnapshot();\n }\n this.loadedState = null;\n\n let didLoad = false;\n const networkedDOM = new NetworkedDOM(\n this.observableDOMFactory,\n this.htmlPath,\n htmlContents,\n oldInstanceRoot,\n (domDiff: VirtualDOMDiffStruct | null, networkedDOM: NetworkedDOM) => {\n didLoad = true;\n if (this.loadedState) {\n this.loadedState.loaded = true;\n }\n networkedDOM.addExistingWebsockets(\n Array.from(this.websockets),\n existingWebsocketMap,\n domDiff,\n );\n },\n this.params,\n this.ignoreTextNodes,\n this.logCallback,\n );\n this.loadedState = {\n htmlContents,\n networkedDOM,\n loaded: didLoad,\n };\n }\n\n public reload() {\n if (this.loadedState) {\n this.load(this.loadedState.htmlContents, this.params);\n } else {\n console.warn(\"EditableNetworkedDOM.reload called whilst not loaded\");\n }\n }\n\n public dispose() {\n for (const ws of this.websockets) {\n ws.close();\n }\n this.websockets.clear();\n if (this.loadedState) {\n this.loadedState.networkedDOM.dispose();\n }\n this.loadedState = null;\n }\n\n public addWebSocket(webSocket: WebSocket) {\n this.websockets.add(webSocket);\n if (this.loadedState && this.loadedState.loaded) {\n this.loadedState.networkedDOM.addWebSocket(webSocket);\n }\n }\n\n public removeWebSocket(webSocket: WebSocket) {\n this.websockets.delete(webSocket);\n if (this.loadedState && this.loadedState.loaded) {\n this.loadedState.networkedDOM.removeWebSocket(webSocket);\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAAO,SAAS,UAAU,GAAQ,GAAiB;AACjD,MAAI,MAAM,GAAG;AACX,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,QAAQ,CAAC,KAAK,MAAM,QAAQ,CAAC,GAAG;AACxC,QAAI,EAAE,WAAW,EAAE,QAAQ;AACzB,aAAO;AAAA,IACT;AAEA,WAAO,EAAE,MAAM,CAAC,MAAM,UAAU;AAC9B,aAAO,UAAU,MAAM,EAAE,KAAK,CAAC;AAAA,IACjC,CAAC;AAAA,EACH;AAEA,MAAI,OAAO,MAAM,YAAY,OAAO,MAAM,YAAY,MAAM,QAAQ,MAAM,MAAM;AAC9E,QAAI,MAAM,QAAQ,CAAC,KAAK,MAAM,QAAQ,CAAC,GAAG;AACxC,aAAO;AAAA,IACT;AAEA,UAAM,QAAQ,OAAO,KAAK,CAAC;AAC3B,UAAM,QAAQ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xC;AACA,SAAK,cAAc;AAAA,EACrB;AAAA,EAEO,aAAa,WAAsB;AACxC,SAAK,WAAW,IAAI,SAAS;AAC7B,QAAI,KAAK,eAAe,KAAK,YAAY,QAAQ;AAC/C,WAAK,YAAY,aAAa,aAAa,SAAS;AAAA,IACtD;AAAA,EACF;AAAA,EAEO,gBAAgB,WAAsB;AAC3C,SAAK,WAAW,OAAO,SAAS;AAChC,QAAI,KAAK,eAAe,KAAK,YAAY,QAAQ;AAC/C,WAAK,YAAY,aAAa,gBAAgB,SAAS;AAAA,IACzD;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["node", "node", "networkedDOM"]
|
|
7
7
|
}
|
package/build/rfc6902/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mml-io/networked-dom-document",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
"type-check": "tsc --noEmit",
|
|
15
15
|
"build": "tsx ./build.ts --build",
|
|
16
16
|
"iterate": "tsx ./build.ts --watch",
|
|
17
|
-
"lint": "eslint \"
|
|
18
|
-
"lint-fix": "eslint \"
|
|
17
|
+
"lint": "eslint \"./**/*.{js,jsx,ts,tsx}\" --max-warnings 0",
|
|
18
|
+
"lint-fix": "eslint \"./**/*.{js,jsx,ts,tsx}\" --fix",
|
|
19
19
|
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@mml-io/networked-dom-protocol": "^0.
|
|
23
|
-
"@mml-io/observable-dom-common": "^0.
|
|
22
|
+
"@mml-io/networked-dom-protocol": "^0.18.1",
|
|
23
|
+
"@mml-io/observable-dom-common": "^0.18.1"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "ef5baff6cda84a1acaed56a957c6b81f4c5acfd5"
|
|
26
26
|
}
|