@mml-io/observable-dom 0.22.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/JSDOMRunner.d.ts +4 -2
- package/build/JSDOMRunner.d.ts.map +1 -0
- package/build/ObservableDOM.d.ts +1 -0
- package/build/ObservableDOM.d.ts.map +1 -0
- package/build/index.d.ts +1 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +6 -1
- package/build/index.js.map +2 -2
- package/build/utils.d.ts +1 -0
- package/build/utils.d.ts.map +1 -0
- package/package.json +3 -3
package/build/JSDOMRunner.d.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { DOMRunnerFactory, DOMRunnerInterface, DOMRunnerMessage } from "./Observ
|
|
|
4
4
|
export declare const JSDOMRunnerFactory: DOMRunnerFactory;
|
|
5
5
|
export type ResourceURL = string | RegExp;
|
|
6
6
|
export type JSDOMRunnerOptions = {
|
|
7
|
-
allowResourceLoading
|
|
7
|
+
allowResourceLoading?: boolean | ResourceURL[];
|
|
8
|
+
globals?: Record<string, any>;
|
|
8
9
|
};
|
|
9
10
|
/**
|
|
10
11
|
* The JSDOMRunner class is used to run HTML Documents using JSDOM and emit DOMRunnerMessages for document events such
|
|
@@ -21,7 +22,7 @@ export declare class JSDOMRunner implements DOMRunnerInterface {
|
|
|
21
22
|
private documentStartTime;
|
|
22
23
|
private isLoaded;
|
|
23
24
|
private logBuffer;
|
|
24
|
-
constructor(htmlPath: string, htmlContents: string, params: object, callback: (domRunnerMessage: DOMRunnerMessage) => void, { allowResourceLoading }?: JSDOMRunnerOptions);
|
|
25
|
+
constructor(htmlPath: string, htmlContents: string, params: object, callback: (domRunnerMessage: DOMRunnerMessage) => void, { allowResourceLoading, globals }?: JSDOMRunnerOptions);
|
|
25
26
|
private flushLogBuffer;
|
|
26
27
|
private log;
|
|
27
28
|
getDocument(): Document;
|
|
@@ -31,3 +32,4 @@ export declare class JSDOMRunner implements DOMRunnerInterface {
|
|
|
31
32
|
dispatchRemoteEventFromConnectionId(connectionId: number, domNode: Element, remoteEvent: ObservableDOMRemoteEvent): void;
|
|
32
33
|
private createVirtualConsole;
|
|
33
34
|
}
|
|
35
|
+
//# sourceMappingURL=JSDOMRunner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JSDOMRunner.d.ts","sourceRoot":"","sources":["../src/JSDOMRunner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAGrF,OAAO,EAEL,SAAS,EAMV,MAAM,OAAO,CAAC;AAKf,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAIzF,eAAO,MAAM,kBAAkB,EAAE,gBAOhC,CAAC;AAUF,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,CAAC;AAwB1C,MAAM,MAAM,kBAAkB,GAAG;IAC/B,oBAAoB,CAAC,EAAE,OAAO,GAAG,WAAW,EAAE,CAAC;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/B,CAAC;AAEF;;;;;GAKG;AACH,qBAAa,WAAY,YAAW,kBAAkB;IAC7C,SAAS,EAAE,SAAS,GAAG,IAAI,CAAQ;IAC1C,OAAO,CAAC,KAAK,CAAQ;IAErB,OAAO,CAAC,QAAQ,CAAsC;IACtD,OAAO,CAAC,gBAAgB,CAAiC;IACzD,OAAO,CAAC,QAAQ,CAAS;IAEzB,OAAO,CAAC,iBAAiB,CAAc;IAEvC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,SAAS,CAAoB;gBAGnC,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,CAAC,gBAAgB,EAAE,gBAAgB,KAAK,IAAI,EACtD,EAAE,oBAA4B,EAAE,OAAO,EAA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;IAInB,mCAAmC,CACxC,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,wBAAwB,GACpC,IAAI;IAmBA,OAAO;IAKd,OAAO,CAAC,eAAe;CAGxB"}
|
package/build/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC"}
|
package/build/index.js
CHANGED
|
@@ -36,7 +36,7 @@ var AllowListResourceLoader = class extends ResourceLoader {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
var JSDOMRunner = class {
|
|
39
|
-
constructor(htmlPath, htmlContents, params, callback, { allowResourceLoading } = {
|
|
39
|
+
constructor(htmlPath, htmlContents, params, callback, { allowResourceLoading = false, globals } = {}) {
|
|
40
40
|
this.domWindow = null;
|
|
41
41
|
this.mutationObserver = null;
|
|
42
42
|
this.documentStartTime = Date.now();
|
|
@@ -64,6 +64,11 @@ var JSDOMRunner = class {
|
|
|
64
64
|
});
|
|
65
65
|
window.document.timeline = timeline;
|
|
66
66
|
window.params = JSON.parse(JSON.stringify(params));
|
|
67
|
+
if (globals) {
|
|
68
|
+
for (const [key, value] of Object.entries(globals)) {
|
|
69
|
+
window[key] = value;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
67
72
|
this.mutationObserver = new window.MutationObserver((mutationList) => {
|
|
68
73
|
this.callback({
|
|
69
74
|
mutationList
|
package/build/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/JSDOMRunner.ts", "../src/utils.ts", "../src/ObservableDOM.ts"],
|
|
4
|
-
"sourcesContent": ["import { LogMessage, ObservableDOMRemoteEvent } from \"@mml-io/observable-dom-common\";\nimport { foreignContent } from \"parse5\";\nforeignContent.SVG_TAG_NAMES_ADJUSTMENT_MAP.set(\"fedropshadow\", \"feDropShadow\");\nimport {\n AbortablePromise,\n DOMWindow,\n FetchOptions,\n JSDOM,\n ResourceLoader,\n ResourceLoaderConstructorOptions,\n VirtualConsole,\n} from \"jsdom\";\nimport * as nodeFetch from \"node-fetch\";\nimport nodeFetchFn from \"node-fetch\";\nimport vm from \"vm\";\n\nimport { DOMRunnerFactory, DOMRunnerInterface, DOMRunnerMessage } from \"./ObservableDOM\";\n\nconst ErrDOMWindowNotInitialized = \"DOMWindow not initialized\";\n\nexport const JSDOMRunnerFactory: DOMRunnerFactory = (\n htmlPath: string,\n htmlContents: string,\n params: object,\n callback: (mutationList: DOMRunnerMessage) => void,\n): DOMRunnerInterface => {\n return new JSDOMRunner(htmlPath, htmlContents, params, callback);\n};\n\n// This is used to stop JSDOM trying to load resources\nclass RejectionResourceLoader extends ResourceLoader {\n public fetch(url: string): AbortablePromise<Buffer> | null {\n console.error(\"RejectionResourceLoader.fetch\", url);\n return null;\n }\n}\n\nexport type ResourceURL = string | RegExp;\n\n// This allows JSDOM to load resources if their URLs are specified in the urls array.\nclass AllowListResourceLoader extends ResourceLoader {\n private urls: ResourceURL[];\n\n constructor(urls: ResourceURL[], opts?: ResourceLoaderConstructorOptions) {\n super(opts);\n this.urls = urls;\n }\n public fetch(url: string, opts?: FetchOptions): AbortablePromise<Buffer> | null {\n const allow = this.urls.some((allowedURL) => {\n return typeof allowedURL === \"string\" ? allowedURL === url : allowedURL.test(url);\n });\n\n if (allow) {\n return super.fetch(url, opts ?? {});\n }\n\n console.error(\"AllowListResourceLoader.fetch: resource not allowed\", url);\n return null;\n }\n}\n\nexport type JSDOMRunnerOptions = {\n allowResourceLoading: boolean | ResourceURL[];\n};\n\n/**\n * The JSDOMRunner class is used to run HTML Documents using JSDOM and emit DOMRunnerMessages for document events such\n * as mutations.\n *\n * It handles the receiving of remote events and the dispatching of them to the underlying DOM elements.\n */\nexport class JSDOMRunner implements DOMRunnerInterface {\n public domWindow: DOMWindow | null = null;\n private jsdom: JSDOM;\n\n private callback: (message: DOMRunnerMessage) => void;\n private mutationObserver: MutationObserver | null = null;\n private htmlPath: string;\n\n private documentStartTime = Date.now();\n\n private isLoaded = false;\n private logBuffer: LogMessage[] = [];\n\n constructor(\n htmlPath: string,\n htmlContents: string,\n params: object,\n callback: (domRunnerMessage: DOMRunnerMessage) => void,\n { allowResourceLoading }: JSDOMRunnerOptions = { allowResourceLoading: false },\n ) {\n this.htmlPath = htmlPath;\n this.callback = callback;\n\n const resources = Array.isArray(allowResourceLoading)\n ? new AllowListResourceLoader(allowResourceLoading)\n : allowResourceLoading\n ? \"usable\"\n : new RejectionResourceLoader();\n\n this.jsdom = new JSDOM(htmlContents, {\n runScripts: \"dangerously\",\n resources,\n url: this.htmlPath,\n virtualConsole: this.createVirtualConsole(),\n beforeParse: (window) => {\n this.domWindow = window;\n\n this.domWindow.fetch = nodeFetchFn as unknown as typeof fetch;\n this.domWindow.Headers = nodeFetch.Headers as unknown as typeof Headers;\n this.domWindow.Request = nodeFetch.Request as unknown as typeof Request;\n this.domWindow.Response = nodeFetch.Response as unknown as typeof Response;\n\n // This is a polyfill for https://developer.mozilla.org/en-US/docs/Web/API/Document/timeline\n const timeline = {};\n Object.defineProperty(timeline, \"currentTime\", {\n get: () => {\n return this.getDocumentTime();\n },\n });\n (window.document as any).timeline = timeline;\n\n // JSON stringify and parse to avoid potential reference leaks from the params object\n window.params = JSON.parse(JSON.stringify(params));\n\n this.mutationObserver = new window.MutationObserver((mutationList) => {\n this.callback({\n mutationList,\n });\n });\n\n window.addEventListener(\"load\", () => {\n this.mutationObserver?.observe(window.document, {\n attributes: true,\n childList: true,\n subtree: true,\n characterData: true,\n });\n\n this.isLoaded = true;\n\n this.callback({\n loaded: true,\n });\n\n this.flushLogBuffer();\n });\n },\n });\n }\n\n private flushLogBuffer() {\n for (const logMessage of this.logBuffer) {\n this.callback({\n logMessage,\n });\n }\n\n this.logBuffer = [];\n }\n\n private log(message: LogMessage) {\n if (!this.isLoaded) {\n this.logBuffer.push(message);\n return;\n }\n\n this.callback({\n logMessage: message,\n });\n }\n\n public getDocument(): Document {\n if (!this.domWindow) {\n throw new Error(ErrDOMWindowNotInitialized);\n }\n\n return this.domWindow.document;\n }\n\n public getWindow(): any {\n return this.domWindow;\n }\n\n public dispose() {\n const records = this.mutationObserver?.takeRecords();\n this.callback({\n mutationList: records,\n });\n this.mutationObserver?.disconnect();\n this.jsdom.window.close();\n }\n\n public getDocumentTime() {\n return Date.now() - this.documentStartTime;\n }\n\n public dispatchRemoteEventFromConnectionId(\n connectionId: number,\n domNode: Element,\n remoteEvent: ObservableDOMRemoteEvent,\n ) {\n if (!this.domWindow) {\n throw new Error(ErrDOMWindowNotInitialized);\n }\n\n const bubbles = remoteEvent.bubbles || false;\n const remoteEventObject = new this.domWindow.CustomEvent(remoteEvent.name, {\n bubbles,\n detail: { ...remoteEvent.params, connectionId },\n });\n\n const eventTypeLowerCase = remoteEvent.name.toLowerCase();\n\n // TODO - check if there are other events that automatically wire up similarly to click->onclick and avoid those too\n if (eventTypeLowerCase !== \"click\") {\n const handlerAttributeName = \"on\" + eventTypeLowerCase;\n const handlerAttributeValue = domNode.getAttribute(handlerAttributeName);\n if (handlerAttributeValue) {\n // This event is defined as an HTML event attribute.\n const script = handlerAttributeValue;\n const vmContext = this.jsdom.getInternalVMContext();\n try {\n const invoke = vm.runInContext(`(function(event){ ${script} })`, vmContext);\n Reflect.apply(invoke, domNode, [remoteEventObject]);\n } catch (e) {\n console.error(\"Error running event handler:\", e);\n }\n }\n }\n\n // Dispatch the event via JavaScript.\n domNode.dispatchEvent(remoteEventObject);\n }\n\n private createVirtualConsole(): VirtualConsole {\n const virtualConsole = new VirtualConsole();\n virtualConsole.on(\"jsdomError\", (...args) => {\n this.log({\n level: \"system\",\n content: args,\n });\n });\n virtualConsole.on(\"error\", (...args) => {\n this.log({\n level: \"error\",\n content: args,\n });\n });\n virtualConsole.on(\"warn\", (...args) => {\n this.log({\n level: \"warn\",\n content: args,\n });\n });\n virtualConsole.on(\"log\", (...args) => {\n this.log({\n level: \"log\",\n content: args,\n });\n });\n virtualConsole.on(\"info\", (...args) => {\n this.log({\n level: \"info\",\n content: args,\n });\n });\n return virtualConsole;\n }\n}\n", "import { StaticVirtualDOMElement } from \"@mml-io/observable-dom-common\";\n\nimport { LiveVirtualDOMElement } from \"./ObservableDOM\";\n\nexport function virtualDOMElementToStatic(el: LiveVirtualDOMElement): StaticVirtualDOMElement {\n return {\n nodeId: el.nodeId,\n tag: el.tag,\n attributes: Object.assign({}, el.attributes), // Copy the attributes object - shallow copy is fine as the attributes are strings\n childNodes: el.childNodes.map((child) => virtualDOMElementToStatic(child)),\n textContent: el.textContent,\n };\n}\n", "import {\n LogMessage,\n ObservableDOMInterface,\n ObservableDOMMessage,\n ObservableDOMParameters,\n ObservableDOMRemoteEvent,\n StaticVirtualDOMElement,\n StaticVirtualDOMMutationIdsRecord,\n} from \"@mml-io/observable-dom-common\";\n\nimport { virtualDOMElementToStatic } from \"./utils\";\n\nexport type DOMRunnerMessage = {\n loaded?: boolean;\n mutationList?: Array<MutationRecord>;\n logMessage?: LogMessage;\n};\n\nexport type DOMRunnerInterface = {\n getDocument(): Document;\n getWindow(): Window & {\n CustomEvent: typeof CustomEvent;\n Text: typeof Text;\n HTMLScriptElement: typeof HTMLScriptElement;\n Comment: typeof Comment;\n }; // TODO - Define this without using JSDOM types\n dispatchRemoteEventFromConnectionId(\n connectionId: number,\n realElement: Element,\n remoteEvent: ObservableDOMRemoteEvent,\n ): void;\n dispose(): void;\n getDocumentTime(): number;\n};\n\nexport type DOMRunnerFactory = (\n htmlPath: string,\n htmlContents: string,\n params: object,\n callback: (domRunnerMessage: DOMRunnerMessage) => void,\n) => DOMRunnerInterface;\n\nexport type LiveVirtualDOMElement = Omit<StaticVirtualDOMElement, \"childNodes\"> & {\n realElement: Element | Text;\n childNodes: Array<LiveVirtualDOMElement>;\n parent: LiveVirtualDOMElement | null;\n};\n\n/**\n * The ObservableDOM class handles the running of an HTML document using a provided DOMRunnerFactory and converting the\n * mutations that are structured as references to live DOM elements into messages that refer to elements by nodeIds.\n */\nexport class ObservableDOM implements ObservableDOMInterface {\n private nodeToNodeId = new Map<LiveVirtualDOMElement, number>();\n private nodeIdToNode = new Map<number, LiveVirtualDOMElement>();\n private realElementToVirtualElement = new Map<Element | Text, LiveVirtualDOMElement>();\n private ignoreTextNodes = true;\n private callback: (message: ObservableDOMMessage, observableDOM: ObservableDOMInterface) => void;\n private nextNodeId = 1;\n private htmlPath: string;\n private domRunner: DOMRunnerInterface;\n private loaded = false;\n private preLoadLogMessages: Array<LogMessage> = [];\n\n private documentTimeIntervalTimer: NodeJS.Timeout;\n\n constructor(\n observableDOMParameters: ObservableDOMParameters,\n callback: (message: ObservableDOMMessage, observableDOM: ObservableDOMInterface) => void,\n runnerFactory: DOMRunnerFactory,\n ) {\n this.htmlPath = observableDOMParameters.htmlPath;\n this.ignoreTextNodes = observableDOMParameters.ignoreTextNodes;\n this.callback = callback;\n\n this.documentTimeIntervalTimer = setInterval(() => {\n this.callback(\n {\n documentTime: this.getDocumentTime(),\n },\n this,\n );\n }, observableDOMParameters.pingIntervalMilliseconds || 5000);\n\n this.domRunner = runnerFactory(\n observableDOMParameters.htmlPath,\n observableDOMParameters.htmlContents,\n observableDOMParameters.params,\n (domRunnerMessage: DOMRunnerMessage) => {\n if (domRunnerMessage.loaded) {\n this.loaded = true;\n this.createVirtualDOMElementWithChildren(\n this.domRunner.getDocument() as unknown as Element,\n null,\n );\n\n const snapshot = virtualDOMElementToStatic(\n this.getVirtualDOMElementForRealElementOrThrow(\n this.domRunner.getDocument() as unknown as Element,\n ),\n );\n\n this.callback(\n {\n snapshot,\n documentTime: this.getDocumentTime(),\n },\n this,\n );\n for (const logMessage of this.preLoadLogMessages) {\n this.callback(\n {\n logMessage,\n documentTime: this.getDocumentTime(),\n },\n this,\n );\n }\n this.preLoadLogMessages = [];\n } else if (domRunnerMessage.mutationList) {\n this.processModificationList(domRunnerMessage.mutationList);\n } else if (domRunnerMessage.logMessage) {\n if (!this.loaded) {\n this.preLoadLogMessages.push(domRunnerMessage.logMessage);\n return;\n }\n this.callback(\n {\n logMessage: domRunnerMessage.logMessage,\n documentTime: this.getDocumentTime(),\n },\n this,\n );\n }\n },\n );\n }\n\n public addConnectedUserId(connectionId: number, connectionToken: string | null): void {\n this.domRunner.getWindow().dispatchEvent(\n new (this.domRunner.getWindow().CustomEvent)(\"connected\", {\n detail: { connectionId, connectionToken },\n }),\n );\n }\n\n public removeConnectedUserId(connectionId: number): void {\n this.domRunner.getWindow().dispatchEvent(\n new (this.domRunner.getWindow().CustomEvent)(\"disconnected\", {\n detail: { connectionId },\n }),\n );\n }\n\n private processModificationList(mutationList: Array<MutationRecord>): void {\n if (mutationList.length > 1) {\n // TODO (https://github.com/mml-io/mml/issues/100) - walk back through the records to derive the intermediate\n // states (e.g. if an attribute is later added to an element created in an earlier record then it should not\n // have that attribute when the element is added. This is important as incorrect attribute sets can affect\n // visibility and expected client performance.\n }\n\n const allMutationRecords: Array<StaticVirtualDOMMutationIdsRecord> = [];\n for (const mutation of mutationList) {\n const idsRecord = this.createMutationRecord(mutation);\n if (idsRecord) {\n allMutationRecords.push(idsRecord);\n }\n }\n\n if (allMutationRecords.length > 0) {\n this.callback(\n {\n mutations: allMutationRecords,\n documentTime: this.getDocumentTime(),\n },\n this,\n );\n }\n }\n\n private createMutationRecord(mutation: MutationRecord): StaticVirtualDOMMutationIdsRecord | null {\n if (this.isIgnoredElement(mutation.target as Element | Text)) {\n return null;\n }\n\n if (\n mutation.type === \"attributes\" &&\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.isIgnoredAttribute(mutation.target as Element | Text, mutation.attributeName!)\n ) {\n return null;\n }\n\n const targetNode = mutation.target as Element | Text;\n const targetElement = this.realElementToVirtualElement.get(targetNode);\n if (!targetElement) {\n // This can happen if the target element for this mutation has been removed in a previous mutation\n return null;\n }\n\n let previousSiblingElement: LiveVirtualDOMElement | null = null;\n let insertionIndex = 0;\n const toAdd: Array<LiveVirtualDOMElement> = [];\n const removedNodeIds: Array<number> = [];\n\n if (mutation.type === \"childList\") {\n mutation.removedNodes.forEach((node: Node) => {\n const asElementOrText = node as Element | Text;\n if (this.isIgnoredElement(asElementOrText)) {\n return;\n }\n const childDOMElement = this.realElementToVirtualElement.get(asElementOrText);\n if (!childDOMElement) {\n /*\n This can happen if element was a child of a parent element, but was moved to a new parent in the same batch of mutations.\n We can ignore this removal as the element will be in the correct place in the hierarchy already.\n */\n return;\n } else {\n const index = targetElement.childNodes.indexOf(childDOMElement);\n if (index === -1) {\n /*\n This can happen if element was a child of a parent element, but was moved to a new parent in the same batch of mutations.\n We can ignore this removal as the element will be in the correct place in the hierarchy already.\n */\n } else {\n this.removeVirtualDOMElement(childDOMElement);\n removedNodeIds.push(childDOMElement.nodeId);\n const removal = targetElement.childNodes.splice(index, 1);\n if (removal.length !== 1) {\n throw new Error(\"Removal length not 1\");\n } else {\n if (removal[0].nodeId !== childDOMElement.nodeId) {\n throw new Error(\"Removal node id mismatch\");\n }\n }\n }\n }\n });\n\n mutation.addedNodes.forEach((node: Node) => {\n const asElementOrText = node as Element | Text;\n if (asElementOrText.parentNode !== targetNode) {\n // Ignore this addition - it is likely overridden by an earlier addition of this element to its eventual node in this mutation batch\n } else {\n if (!previousSiblingElement) {\n /*\n Either there is no previous element (this is the first element)\n or the previous element has not yet been determined.\n\n Use the current previous sibling of this added node as the first\n choice for the previous sibling, but only use previous siblings\n that are not ignored (are tracked as virtual elements).\n */\n let firstNonIgnoredPreviousSibling: Element | Text | null =\n asElementOrText.previousSibling as Element | Text;\n let virtualPreviousSibling: LiveVirtualDOMElement | undefined;\n while (firstNonIgnoredPreviousSibling && !virtualPreviousSibling) {\n virtualPreviousSibling = this.realElementToVirtualElement.get(\n firstNonIgnoredPreviousSibling as Element | Text,\n );\n if (\n virtualPreviousSibling &&\n targetElement.childNodes.indexOf(virtualPreviousSibling) === -1\n ) {\n // This element is not a child of the parent element - it is not a valid previous sibling\n virtualPreviousSibling = undefined;\n }\n\n firstNonIgnoredPreviousSibling = firstNonIgnoredPreviousSibling.previousSibling as\n | Element\n | Text\n | null;\n }\n\n if (virtualPreviousSibling) {\n previousSiblingElement = virtualPreviousSibling;\n insertionIndex = targetElement.childNodes.indexOf(previousSiblingElement);\n if (insertionIndex === -1) {\n throw new Error(\"Previous sibling is not currently a child of the parent element\");\n }\n insertionIndex += 1;\n }\n }\n const childVirtualDOMElement = this.createVirtualDOMElementWithChildren(\n asElementOrText,\n targetElement,\n );\n if (childVirtualDOMElement) {\n toAdd.push(childVirtualDOMElement);\n }\n }\n });\n targetElement.childNodes.splice(insertionIndex, 0, ...toAdd);\n\n if (toAdd.length === 0 && removedNodeIds.length === 0) {\n // This is a no-op mutation\n return null;\n }\n // Convert the \"real\" DOM MutationRecord into a \"virtual\" DOM MutationRecord that references the VirtualDOMElements\n // This is done so that the same process for handling mutations can be used for both changes to a live DOM and also\n // to diffs between DOM snapshots when reloading\n const addedNodes: Array<StaticVirtualDOMElement> = toAdd.map(virtualDOMElementToStatic);\n return {\n type: \"childList\",\n targetId: targetElement.nodeId,\n addedNodes,\n removedNodeIds,\n previousSiblingId: previousSiblingElement\n ? (previousSiblingElement as LiveVirtualDOMElement).nodeId\n : null,\n };\n } else if (mutation.type === \"attributes\") {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const attributeName = mutation.attributeName!;\n if (!this.isIgnoredAttribute(targetNode, attributeName)) {\n const previousValue = targetElement.attributes[attributeName];\n const attributeValue = (targetNode as Element).getAttribute(attributeName);\n if (attributeValue === null) {\n if (previousValue === undefined) {\n // This is a no-op mutation\n return null;\n }\n delete targetElement.attributes[attributeName];\n } else {\n if (attributeValue === previousValue) {\n // This is a no-op mutation\n return null;\n }\n targetElement.attributes[attributeName] = attributeValue;\n }\n return {\n type: \"attributes\",\n targetId: targetElement.nodeId,\n attributes: {\n [attributeName]: attributeValue,\n },\n };\n }\n } else if (mutation.type === \"characterData\") {\n targetElement.textContent = targetNode.textContent ? targetNode.textContent : undefined;\n return {\n type: \"characterData\",\n targetId: targetElement.nodeId,\n textContent: targetElement.textContent ? targetElement.textContent : \"\",\n };\n }\n\n throw new Error(\"Unknown mutation type: \" + mutation.type);\n }\n\n private removeVirtualDOMElement(virtualDOMElement: LiveVirtualDOMElement): void {\n this.nodeIdToNode.delete(virtualDOMElement.nodeId);\n this.nodeToNodeId.delete(virtualDOMElement);\n this.realElementToVirtualElement.delete(virtualDOMElement.realElement);\n for (const child of virtualDOMElement.childNodes) {\n this.removeVirtualDOMElement(child);\n }\n }\n\n private createVirtualDOMElementWithChildren(\n node: Element | Text,\n parent: LiveVirtualDOMElement | null,\n ): LiveVirtualDOMElement | null {\n const [virtualElement, existing] = this.createVirtualDOMElement(node, parent);\n if (!virtualElement) {\n return null;\n }\n if (existing) {\n return null;\n }\n if ((node as Element).childNodes) {\n for (let i = 0; i < (node as Element).childNodes.length; i++) {\n const child = (node as Element).childNodes[i];\n const childVirtualElement = this.createVirtualDOMElementWithChildren(\n child as Element | Text,\n virtualElement,\n );\n if (childVirtualElement) {\n virtualElement.childNodes.push(childVirtualElement);\n }\n }\n }\n\n return virtualElement;\n }\n\n private createVirtualDOMElement(\n node: Element | Text,\n parent: LiveVirtualDOMElement | null,\n ): [LiveVirtualDOMElement | null, boolean] {\n if (this.isIgnoredElement(node)) {\n return [null, false];\n }\n if (!node) {\n throw new Error(\"Cannot assign node id to null\");\n }\n\n const existingValue = this.realElementToVirtualElement.get(node);\n if (existingValue !== undefined) {\n /*\n This is undesirable, but the batching of mutations from MutationObserver means that\n this node could be being added in a mutation after a mutation of a parent that when\n handled resulting in adding this node early.\n */\n return [existingValue, true];\n }\n\n const attributes: { [key: string]: string } = {};\n if ((node as any).attributes) {\n const asHTMLElement = node as HTMLElement;\n for (const key of asHTMLElement.getAttributeNames()) {\n const value = asHTMLElement.getAttribute(key);\n if (value === null) {\n throw new Error(\"Null attribute value for key: \" + key);\n }\n if (!this.isIgnoredAttribute(node, key)) {\n attributes[key] = value;\n }\n }\n }\n\n const nodeId = this.nextNodeId++;\n const localNameValue = (node as Element).localName;\n const nodeNameValue = node.nodeName;\n let tag = localNameValue || nodeNameValue;\n if (tag !== \"#text\") {\n tag = tag.toUpperCase();\n }\n\n const virtualElement: LiveVirtualDOMElement = {\n nodeId,\n tag,\n attributes,\n childNodes: [],\n realElement: node,\n parent,\n };\n if (node instanceof this.domRunner.getWindow().Text && node.textContent) {\n virtualElement.textContent = node.textContent;\n }\n this.nodeToNodeId.set(virtualElement, nodeId);\n this.nodeIdToNode.set(nodeId, virtualElement);\n this.realElementToVirtualElement.set(node, virtualElement);\n return [virtualElement, false];\n }\n\n private getVirtualDOMElementForRealElementOrThrow(\n realElement: Element | Text,\n ): LiveVirtualDOMElement {\n const virtualElement = this.realElementToVirtualElement.get(realElement);\n if (!virtualElement) {\n throw new Error(`Virtual element not found for real element`);\n }\n return virtualElement;\n }\n\n private isIgnoredElement(node: Element | Text): boolean {\n if (this.ignoreTextNodes && node instanceof this.domRunner.getWindow().Text) {\n return true;\n } else if (node instanceof this.domRunner.getWindow().HTMLScriptElement) {\n return true;\n } else if (node instanceof this.domRunner.getWindow().Comment) {\n return true;\n }\n return false;\n }\n\n private isIgnoredAttribute(node: Element | Text, attributeName: string): boolean {\n return attributeName.startsWith(\"on\");\n }\n\n public dispatchRemoteEventFromConnectionId(\n connectionId: number,\n remoteEvent: ObservableDOMRemoteEvent,\n ): void {\n const domNode = this.nodeIdToNode.get(remoteEvent.nodeId);\n if (!domNode) {\n console.error(\"Unknown node ID in remote event: \" + remoteEvent.nodeId);\n return;\n }\n\n if (domNode instanceof this.domRunner.getWindow().Text) {\n console.warn(\"Cannot dispatch remote event to text node\");\n return;\n }\n\n this.domRunner.dispatchRemoteEventFromConnectionId(\n connectionId,\n domNode.realElement as Element,\n remoteEvent,\n );\n }\n\n public dispose() {\n clearInterval(this.documentTimeIntervalTimer);\n this.domRunner.dispose();\n }\n\n private getDocum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IACF;AAEA,QAAI,mBAAmB,KAAK,UAAU,UAAU,EAAE,MAAM;AACtD,cAAQ,KAAK,2CAA2C;AACxD;AAAA,IACF;AAEA,SAAK,UAAU;AAAA,MACb;AAAA,MACA,QAAQ;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAAA,EAEO,UAAU;AACf,kBAAc,KAAK,yBAAyB;AAC5C,SAAK,UAAU,QAAQ;AAAA,EACzB;AAAA,EAEQ,kBAAkB;AACxB,WAAO,KAAK,UAAU,gBAAgB;AAAA,EACxC;AACF;",
|
|
4
|
+
"sourcesContent": ["import { LogMessage, ObservableDOMRemoteEvent } from \"@mml-io/observable-dom-common\";\nimport { foreignContent } from \"parse5\";\nforeignContent.SVG_TAG_NAMES_ADJUSTMENT_MAP.set(\"fedropshadow\", \"feDropShadow\");\nimport {\n AbortablePromise,\n DOMWindow,\n FetchOptions,\n JSDOM,\n ResourceLoader,\n ResourceLoaderConstructorOptions,\n VirtualConsole,\n} from \"jsdom\";\nimport * as nodeFetch from \"node-fetch\";\nimport nodeFetchFn from \"node-fetch\";\nimport vm from \"vm\";\n\nimport { DOMRunnerFactory, DOMRunnerInterface, DOMRunnerMessage } from \"./ObservableDOM\";\n\nconst ErrDOMWindowNotInitialized = \"DOMWindow not initialized\";\n\nexport const JSDOMRunnerFactory: DOMRunnerFactory = (\n htmlPath: string,\n htmlContents: string,\n params: object,\n callback: (mutationList: DOMRunnerMessage) => void,\n): DOMRunnerInterface => {\n return new JSDOMRunner(htmlPath, htmlContents, params, callback);\n};\n\n// This is used to stop JSDOM trying to load resources\nclass RejectionResourceLoader extends ResourceLoader {\n public fetch(url: string): AbortablePromise<Buffer> | null {\n console.error(\"RejectionResourceLoader.fetch\", url);\n return null;\n }\n}\n\nexport type ResourceURL = string | RegExp;\n\n// This allows JSDOM to load resources if their URLs are specified in the urls array.\nclass AllowListResourceLoader extends ResourceLoader {\n private urls: ResourceURL[];\n\n constructor(urls: ResourceURL[], opts?: ResourceLoaderConstructorOptions) {\n super(opts);\n this.urls = urls;\n }\n public fetch(url: string, opts?: FetchOptions): AbortablePromise<Buffer> | null {\n const allow = this.urls.some((allowedURL) => {\n return typeof allowedURL === \"string\" ? allowedURL === url : allowedURL.test(url);\n });\n\n if (allow) {\n return super.fetch(url, opts ?? {});\n }\n\n console.error(\"AllowListResourceLoader.fetch: resource not allowed\", url);\n return null;\n }\n}\n\nexport type JSDOMRunnerOptions = {\n allowResourceLoading?: boolean | ResourceURL[];\n globals?: Record<string, any>;\n};\n\n/**\n * The JSDOMRunner class is used to run HTML Documents using JSDOM and emit DOMRunnerMessages for document events such\n * as mutations.\n *\n * It handles the receiving of remote events and the dispatching of them to the underlying DOM elements.\n */\nexport class JSDOMRunner implements DOMRunnerInterface {\n public domWindow: DOMWindow | null = null;\n private jsdom: JSDOM;\n\n private callback: (message: DOMRunnerMessage) => void;\n private mutationObserver: MutationObserver | null = null;\n private htmlPath: string;\n\n private documentStartTime = Date.now();\n\n private isLoaded = false;\n private logBuffer: LogMessage[] = [];\n\n constructor(\n htmlPath: string,\n htmlContents: string,\n params: object,\n callback: (domRunnerMessage: DOMRunnerMessage) => void,\n { allowResourceLoading = false, globals }: JSDOMRunnerOptions = {},\n ) {\n this.htmlPath = htmlPath;\n this.callback = callback;\n\n const resources = Array.isArray(allowResourceLoading)\n ? new AllowListResourceLoader(allowResourceLoading)\n : allowResourceLoading\n ? \"usable\"\n : new RejectionResourceLoader();\n\n this.jsdom = new JSDOM(htmlContents, {\n runScripts: \"dangerously\",\n resources,\n url: this.htmlPath,\n virtualConsole: this.createVirtualConsole(),\n beforeParse: (window) => {\n this.domWindow = window;\n\n this.domWindow.fetch = nodeFetchFn as unknown as typeof fetch;\n this.domWindow.Headers = nodeFetch.Headers as unknown as typeof Headers;\n this.domWindow.Request = nodeFetch.Request as unknown as typeof Request;\n this.domWindow.Response = nodeFetch.Response as unknown as typeof Response;\n\n // This is a polyfill for https://developer.mozilla.org/en-US/docs/Web/API/Document/timeline\n const timeline = {};\n Object.defineProperty(timeline, \"currentTime\", {\n get: () => {\n return this.getDocumentTime();\n },\n });\n (window.document as any).timeline = timeline;\n\n // JSON stringify and parse to avoid potential reference leaks from the params object\n window.params = JSON.parse(JSON.stringify(params));\n\n // Inject any provided globals onto the window\n if (globals) {\n for (const [key, value] of Object.entries(globals)) {\n (window as any)[key] = value;\n }\n }\n\n this.mutationObserver = new window.MutationObserver((mutationList) => {\n this.callback({\n mutationList,\n });\n });\n\n window.addEventListener(\"load\", () => {\n this.mutationObserver?.observe(window.document, {\n attributes: true,\n childList: true,\n subtree: true,\n characterData: true,\n });\n\n this.isLoaded = true;\n\n this.callback({\n loaded: true,\n });\n\n this.flushLogBuffer();\n });\n },\n });\n }\n\n private flushLogBuffer() {\n for (const logMessage of this.logBuffer) {\n this.callback({\n logMessage,\n });\n }\n\n this.logBuffer = [];\n }\n\n private log(message: LogMessage) {\n if (!this.isLoaded) {\n this.logBuffer.push(message);\n return;\n }\n\n this.callback({\n logMessage: message,\n });\n }\n\n public getDocument(): Document {\n if (!this.domWindow) {\n throw new Error(ErrDOMWindowNotInitialized);\n }\n\n return this.domWindow.document;\n }\n\n public getWindow(): any {\n return this.domWindow;\n }\n\n public dispose() {\n const records = this.mutationObserver?.takeRecords();\n this.callback({\n mutationList: records,\n });\n this.mutationObserver?.disconnect();\n this.jsdom.window.close();\n }\n\n public getDocumentTime() {\n return Date.now() - this.documentStartTime;\n }\n\n public dispatchRemoteEventFromConnectionId(\n connectionId: number,\n domNode: Element,\n remoteEvent: ObservableDOMRemoteEvent,\n ) {\n if (!this.domWindow) {\n throw new Error(ErrDOMWindowNotInitialized);\n }\n\n const bubbles = remoteEvent.bubbles || false;\n const remoteEventObject = new this.domWindow.CustomEvent(remoteEvent.name, {\n bubbles,\n detail: { ...remoteEvent.params, connectionId },\n });\n\n const eventTypeLowerCase = remoteEvent.name.toLowerCase();\n\n // TODO - check if there are other events that automatically wire up similarly to click->onclick and avoid those too\n if (eventTypeLowerCase !== \"click\") {\n const handlerAttributeName = \"on\" + eventTypeLowerCase;\n const handlerAttributeValue = domNode.getAttribute(handlerAttributeName);\n if (handlerAttributeValue) {\n // This event is defined as an HTML event attribute.\n const script = handlerAttributeValue;\n const vmContext = this.jsdom.getInternalVMContext();\n try {\n const invoke = vm.runInContext(`(function(event){ ${script} })`, vmContext);\n Reflect.apply(invoke, domNode, [remoteEventObject]);\n } catch (e) {\n console.error(\"Error running event handler:\", e);\n }\n }\n }\n\n // Dispatch the event via JavaScript.\n domNode.dispatchEvent(remoteEventObject);\n }\n\n private createVirtualConsole(): VirtualConsole {\n const virtualConsole = new VirtualConsole();\n virtualConsole.on(\"jsdomError\", (...args) => {\n this.log({\n level: \"system\",\n content: args,\n });\n });\n virtualConsole.on(\"error\", (...args) => {\n this.log({\n level: \"error\",\n content: args,\n });\n });\n virtualConsole.on(\"warn\", (...args) => {\n this.log({\n level: \"warn\",\n content: args,\n });\n });\n virtualConsole.on(\"log\", (...args) => {\n this.log({\n level: \"log\",\n content: args,\n });\n });\n virtualConsole.on(\"info\", (...args) => {\n this.log({\n level: \"info\",\n content: args,\n });\n });\n return virtualConsole;\n }\n}\n", "import { StaticVirtualDOMElement } from \"@mml-io/observable-dom-common\";\n\nimport { LiveVirtualDOMElement } from \"./ObservableDOM\";\n\nexport function virtualDOMElementToStatic(el: LiveVirtualDOMElement): StaticVirtualDOMElement {\n return {\n nodeId: el.nodeId,\n tag: el.tag,\n attributes: Object.assign({}, el.attributes), // Copy the attributes object - shallow copy is fine as the attributes are strings\n childNodes: el.childNodes.map((child) => virtualDOMElementToStatic(child)),\n textContent: el.textContent,\n };\n}\n", "import {\n LogMessage,\n ObservableDOMInterface,\n ObservableDOMMessage,\n ObservableDOMParameters,\n ObservableDOMRemoteEvent,\n StaticVirtualDOMElement,\n StaticVirtualDOMMutationIdsRecord,\n} from \"@mml-io/observable-dom-common\";\n\nimport { virtualDOMElementToStatic } from \"./utils\";\n\nexport type DOMRunnerMessage = {\n loaded?: boolean;\n mutationList?: Array<MutationRecord>;\n logMessage?: LogMessage;\n};\n\nexport type DOMRunnerInterface = {\n getDocument(): Document;\n getWindow(): Window & {\n CustomEvent: typeof CustomEvent;\n Text: typeof Text;\n HTMLScriptElement: typeof HTMLScriptElement;\n Comment: typeof Comment;\n }; // TODO - Define this without using JSDOM types\n dispatchRemoteEventFromConnectionId(\n connectionId: number,\n realElement: Element,\n remoteEvent: ObservableDOMRemoteEvent,\n ): void;\n dispose(): void;\n getDocumentTime(): number;\n};\n\nexport type DOMRunnerFactory = (\n htmlPath: string,\n htmlContents: string,\n params: object,\n callback: (domRunnerMessage: DOMRunnerMessage) => void,\n) => DOMRunnerInterface;\n\nexport type LiveVirtualDOMElement = Omit<StaticVirtualDOMElement, \"childNodes\"> & {\n realElement: Element | Text;\n childNodes: Array<LiveVirtualDOMElement>;\n parent: LiveVirtualDOMElement | null;\n};\n\n/**\n * The ObservableDOM class handles the running of an HTML document using a provided DOMRunnerFactory and converting the\n * mutations that are structured as references to live DOM elements into messages that refer to elements by nodeIds.\n */\nexport class ObservableDOM implements ObservableDOMInterface {\n private nodeToNodeId = new Map<LiveVirtualDOMElement, number>();\n private nodeIdToNode = new Map<number, LiveVirtualDOMElement>();\n private realElementToVirtualElement = new Map<Element | Text, LiveVirtualDOMElement>();\n private ignoreTextNodes = true;\n private callback: (message: ObservableDOMMessage, observableDOM: ObservableDOMInterface) => void;\n private nextNodeId = 1;\n private htmlPath: string;\n private domRunner: DOMRunnerInterface;\n private loaded = false;\n private preLoadLogMessages: Array<LogMessage> = [];\n\n private documentTimeIntervalTimer: NodeJS.Timeout;\n\n constructor(\n observableDOMParameters: ObservableDOMParameters,\n callback: (message: ObservableDOMMessage, observableDOM: ObservableDOMInterface) => void,\n runnerFactory: DOMRunnerFactory,\n ) {\n this.htmlPath = observableDOMParameters.htmlPath;\n this.ignoreTextNodes = observableDOMParameters.ignoreTextNodes;\n this.callback = callback;\n\n this.documentTimeIntervalTimer = setInterval(() => {\n this.callback(\n {\n documentTime: this.getDocumentTime(),\n },\n this,\n );\n }, observableDOMParameters.pingIntervalMilliseconds || 5000);\n\n this.domRunner = runnerFactory(\n observableDOMParameters.htmlPath,\n observableDOMParameters.htmlContents,\n observableDOMParameters.params,\n (domRunnerMessage: DOMRunnerMessage) => {\n if (domRunnerMessage.loaded) {\n this.loaded = true;\n this.createVirtualDOMElementWithChildren(\n this.domRunner.getDocument() as unknown as Element,\n null,\n );\n\n const snapshot = virtualDOMElementToStatic(\n this.getVirtualDOMElementForRealElementOrThrow(\n this.domRunner.getDocument() as unknown as Element,\n ),\n );\n\n this.callback(\n {\n snapshot,\n documentTime: this.getDocumentTime(),\n },\n this,\n );\n for (const logMessage of this.preLoadLogMessages) {\n this.callback(\n {\n logMessage,\n documentTime: this.getDocumentTime(),\n },\n this,\n );\n }\n this.preLoadLogMessages = [];\n } else if (domRunnerMessage.mutationList) {\n this.processModificationList(domRunnerMessage.mutationList);\n } else if (domRunnerMessage.logMessage) {\n if (!this.loaded) {\n this.preLoadLogMessages.push(domRunnerMessage.logMessage);\n return;\n }\n this.callback(\n {\n logMessage: domRunnerMessage.logMessage,\n documentTime: this.getDocumentTime(),\n },\n this,\n );\n }\n },\n );\n }\n\n public addConnectedUserId(connectionId: number, connectionToken: string | null): void {\n this.domRunner.getWindow().dispatchEvent(\n new (this.domRunner.getWindow().CustomEvent)(\"connected\", {\n detail: { connectionId, connectionToken },\n }),\n );\n }\n\n public removeConnectedUserId(connectionId: number): void {\n this.domRunner.getWindow().dispatchEvent(\n new (this.domRunner.getWindow().CustomEvent)(\"disconnected\", {\n detail: { connectionId },\n }),\n );\n }\n\n private processModificationList(mutationList: Array<MutationRecord>): void {\n if (mutationList.length > 1) {\n // TODO (https://github.com/mml-io/mml/issues/100) - walk back through the records to derive the intermediate\n // states (e.g. if an attribute is later added to an element created in an earlier record then it should not\n // have that attribute when the element is added. This is important as incorrect attribute sets can affect\n // visibility and expected client performance.\n }\n\n const allMutationRecords: Array<StaticVirtualDOMMutationIdsRecord> = [];\n for (const mutation of mutationList) {\n const idsRecord = this.createMutationRecord(mutation);\n if (idsRecord) {\n allMutationRecords.push(idsRecord);\n }\n }\n\n if (allMutationRecords.length > 0) {\n this.callback(\n {\n mutations: allMutationRecords,\n documentTime: this.getDocumentTime(),\n },\n this,\n );\n }\n }\n\n private createMutationRecord(mutation: MutationRecord): StaticVirtualDOMMutationIdsRecord | null {\n if (this.isIgnoredElement(mutation.target as Element | Text)) {\n return null;\n }\n\n if (\n mutation.type === \"attributes\" &&\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.isIgnoredAttribute(mutation.target as Element | Text, mutation.attributeName!)\n ) {\n return null;\n }\n\n const targetNode = mutation.target as Element | Text;\n const targetElement = this.realElementToVirtualElement.get(targetNode);\n if (!targetElement) {\n // This can happen if the target element for this mutation has been removed in a previous mutation\n return null;\n }\n\n let previousSiblingElement: LiveVirtualDOMElement | null = null;\n let insertionIndex = 0;\n const toAdd: Array<LiveVirtualDOMElement> = [];\n const removedNodeIds: Array<number> = [];\n\n if (mutation.type === \"childList\") {\n mutation.removedNodes.forEach((node: Node) => {\n const asElementOrText = node as Element | Text;\n if (this.isIgnoredElement(asElementOrText)) {\n return;\n }\n const childDOMElement = this.realElementToVirtualElement.get(asElementOrText);\n if (!childDOMElement) {\n /*\n This can happen if element was a child of a parent element, but was moved to a new parent in the same batch of mutations.\n We can ignore this removal as the element will be in the correct place in the hierarchy already.\n */\n return;\n } else {\n const index = targetElement.childNodes.indexOf(childDOMElement);\n if (index === -1) {\n /*\n This can happen if element was a child of a parent element, but was moved to a new parent in the same batch of mutations.\n We can ignore this removal as the element will be in the correct place in the hierarchy already.\n */\n } else {\n this.removeVirtualDOMElement(childDOMElement);\n removedNodeIds.push(childDOMElement.nodeId);\n const removal = targetElement.childNodes.splice(index, 1);\n if (removal.length !== 1) {\n throw new Error(\"Removal length not 1\");\n } else {\n if (removal[0].nodeId !== childDOMElement.nodeId) {\n throw new Error(\"Removal node id mismatch\");\n }\n }\n }\n }\n });\n\n mutation.addedNodes.forEach((node: Node) => {\n const asElementOrText = node as Element | Text;\n if (asElementOrText.parentNode !== targetNode) {\n // Ignore this addition - it is likely overridden by an earlier addition of this element to its eventual node in this mutation batch\n } else {\n if (!previousSiblingElement) {\n /*\n Either there is no previous element (this is the first element)\n or the previous element has not yet been determined.\n\n Use the current previous sibling of this added node as the first\n choice for the previous sibling, but only use previous siblings\n that are not ignored (are tracked as virtual elements).\n */\n let firstNonIgnoredPreviousSibling: Element | Text | null =\n asElementOrText.previousSibling as Element | Text;\n let virtualPreviousSibling: LiveVirtualDOMElement | undefined;\n while (firstNonIgnoredPreviousSibling && !virtualPreviousSibling) {\n virtualPreviousSibling = this.realElementToVirtualElement.get(\n firstNonIgnoredPreviousSibling as Element | Text,\n );\n if (\n virtualPreviousSibling &&\n targetElement.childNodes.indexOf(virtualPreviousSibling) === -1\n ) {\n // This element is not a child of the parent element - it is not a valid previous sibling\n virtualPreviousSibling = undefined;\n }\n\n firstNonIgnoredPreviousSibling = firstNonIgnoredPreviousSibling.previousSibling as\n | Element\n | Text\n | null;\n }\n\n if (virtualPreviousSibling) {\n previousSiblingElement = virtualPreviousSibling;\n insertionIndex = targetElement.childNodes.indexOf(previousSiblingElement);\n if (insertionIndex === -1) {\n throw new Error(\"Previous sibling is not currently a child of the parent element\");\n }\n insertionIndex += 1;\n }\n }\n const childVirtualDOMElement = this.createVirtualDOMElementWithChildren(\n asElementOrText,\n targetElement,\n );\n if (childVirtualDOMElement) {\n toAdd.push(childVirtualDOMElement);\n }\n }\n });\n targetElement.childNodes.splice(insertionIndex, 0, ...toAdd);\n\n if (toAdd.length === 0 && removedNodeIds.length === 0) {\n // This is a no-op mutation\n return null;\n }\n // Convert the \"real\" DOM MutationRecord into a \"virtual\" DOM MutationRecord that references the VirtualDOMElements\n // This is done so that the same process for handling mutations can be used for both changes to a live DOM and also\n // to diffs between DOM snapshots when reloading\n const addedNodes: Array<StaticVirtualDOMElement> = toAdd.map(virtualDOMElementToStatic);\n return {\n type: \"childList\",\n targetId: targetElement.nodeId,\n addedNodes,\n removedNodeIds,\n previousSiblingId: previousSiblingElement\n ? (previousSiblingElement as LiveVirtualDOMElement).nodeId\n : null,\n };\n } else if (mutation.type === \"attributes\") {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const attributeName = mutation.attributeName!;\n if (!this.isIgnoredAttribute(targetNode, attributeName)) {\n const previousValue = targetElement.attributes[attributeName];\n const attributeValue = (targetNode as Element).getAttribute(attributeName);\n if (attributeValue === null) {\n if (previousValue === undefined) {\n // This is a no-op mutation\n return null;\n }\n delete targetElement.attributes[attributeName];\n } else {\n if (attributeValue === previousValue) {\n // This is a no-op mutation\n return null;\n }\n targetElement.attributes[attributeName] = attributeValue;\n }\n return {\n type: \"attributes\",\n targetId: targetElement.nodeId,\n attributes: {\n [attributeName]: attributeValue,\n },\n };\n }\n } else if (mutation.type === \"characterData\") {\n targetElement.textContent = targetNode.textContent ? targetNode.textContent : undefined;\n return {\n type: \"characterData\",\n targetId: targetElement.nodeId,\n textContent: targetElement.textContent ? targetElement.textContent : \"\",\n };\n }\n\n throw new Error(\"Unknown mutation type: \" + mutation.type);\n }\n\n private removeVirtualDOMElement(virtualDOMElement: LiveVirtualDOMElement): void {\n this.nodeIdToNode.delete(virtualDOMElement.nodeId);\n this.nodeToNodeId.delete(virtualDOMElement);\n this.realElementToVirtualElement.delete(virtualDOMElement.realElement);\n for (const child of virtualDOMElement.childNodes) {\n this.removeVirtualDOMElement(child);\n }\n }\n\n private createVirtualDOMElementWithChildren(\n node: Element | Text,\n parent: LiveVirtualDOMElement | null,\n ): LiveVirtualDOMElement | null {\n const [virtualElement, existing] = this.createVirtualDOMElement(node, parent);\n if (!virtualElement) {\n return null;\n }\n if (existing) {\n return null;\n }\n if ((node as Element).childNodes) {\n for (let i = 0; i < (node as Element).childNodes.length; i++) {\n const child = (node as Element).childNodes[i];\n const childVirtualElement = this.createVirtualDOMElementWithChildren(\n child as Element | Text,\n virtualElement,\n );\n if (childVirtualElement) {\n virtualElement.childNodes.push(childVirtualElement);\n }\n }\n }\n\n return virtualElement;\n }\n\n private createVirtualDOMElement(\n node: Element | Text,\n parent: LiveVirtualDOMElement | null,\n ): [LiveVirtualDOMElement | null, boolean] {\n if (this.isIgnoredElement(node)) {\n return [null, false];\n }\n if (!node) {\n throw new Error(\"Cannot assign node id to null\");\n }\n\n const existingValue = this.realElementToVirtualElement.get(node);\n if (existingValue !== undefined) {\n /*\n This is undesirable, but the batching of mutations from MutationObserver means that\n this node could be being added in a mutation after a mutation of a parent that when\n handled resulting in adding this node early.\n */\n return [existingValue, true];\n }\n\n const attributes: { [key: string]: string } = {};\n if ((node as any).attributes) {\n const asHTMLElement = node as HTMLElement;\n for (const key of asHTMLElement.getAttributeNames()) {\n const value = asHTMLElement.getAttribute(key);\n if (value === null) {\n throw new Error(\"Null attribute value for key: \" + key);\n }\n if (!this.isIgnoredAttribute(node, key)) {\n attributes[key] = value;\n }\n }\n }\n\n const nodeId = this.nextNodeId++;\n const localNameValue = (node as Element).localName;\n const nodeNameValue = node.nodeName;\n let tag = localNameValue || nodeNameValue;\n if (tag !== \"#text\") {\n tag = tag.toUpperCase();\n }\n\n const virtualElement: LiveVirtualDOMElement = {\n nodeId,\n tag,\n attributes,\n childNodes: [],\n realElement: node,\n parent,\n };\n if (node instanceof this.domRunner.getWindow().Text && node.textContent) {\n virtualElement.textContent = node.textContent;\n }\n this.nodeToNodeId.set(virtualElement, nodeId);\n this.nodeIdToNode.set(nodeId, virtualElement);\n this.realElementToVirtualElement.set(node, virtualElement);\n return [virtualElement, false];\n }\n\n private getVirtualDOMElementForRealElementOrThrow(\n realElement: Element | Text,\n ): LiveVirtualDOMElement {\n const virtualElement = this.realElementToVirtualElement.get(realElement);\n if (!virtualElement) {\n throw new Error(`Virtual element not found for real element`);\n }\n return virtualElement;\n }\n\n private isIgnoredElement(node: Element | Text): boolean {\n if (this.ignoreTextNodes && node instanceof this.domRunner.getWindow().Text) {\n return true;\n } else if (node instanceof this.domRunner.getWindow().HTMLScriptElement) {\n return true;\n } else if (node instanceof this.domRunner.getWindow().Comment) {\n return true;\n }\n return false;\n }\n\n private isIgnoredAttribute(node: Element | Text, attributeName: string): boolean {\n return attributeName.startsWith(\"on\");\n }\n\n public dispatchRemoteEventFromConnectionId(\n connectionId: number,\n remoteEvent: ObservableDOMRemoteEvent,\n ): void {\n const domNode = this.nodeIdToNode.get(remoteEvent.nodeId);\n if (!domNode) {\n console.error(\"Unknown node ID in remote event: \" + remoteEvent.nodeId);\n return;\n }\n\n if (domNode instanceof this.domRunner.getWindow().Text) {\n console.warn(\"Cannot dispatch remote event to text node\");\n return;\n }\n\n this.domRunner.dispatchRemoteEventFromConnectionId(\n connectionId,\n domNode.realElement as Element,\n remoteEvent,\n );\n }\n\n public dispose() {\n clearInterval(this.documentTimeIntervalTimer);\n this.domRunner.dispose();\n }\n\n private getDocumentTime() {\n return this.domRunner.getDocumentTime();\n }\n}\n"],
|
|
5
|
+
"mappings": ";AACA,SAAS,sBAAsB;AAE/B;AAAA,EAIE;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AACP,YAAY,eAAe;AAC3B,OAAO,iBAAiB;AACxB,OAAO,QAAQ;AAZf,eAAe,6BAA6B,IAAI,gBAAgB,cAAc;AAgB9E,IAAM,6BAA6B;AAE5B,IAAM,qBAAuC,CAClD,UACA,cACA,QACA,aACuB;AACvB,SAAO,IAAI,YAAY,UAAU,cAAc,QAAQ,QAAQ;AACjE;AAGA,IAAM,0BAAN,cAAsC,eAAe;AAAA,EAC5C,MAAM,KAA8C;AACzD,YAAQ,MAAM,iCAAiC,GAAG;AAClD,WAAO;AAAA,EACT;AACF;AAKA,IAAM,0BAAN,cAAsC,eAAe;AAAA,EAGnD,YAAY,MAAqB,MAAyC;AACxE,UAAM,IAAI;AACV,SAAK,OAAO;AAAA,EACd;AAAA,EACO,MAAM,KAAa,MAAsD;AAC9E,UAAM,QAAQ,KAAK,KAAK,KA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AC,gBAAgB,KAAK;AAAA,EAC/B;AAAA,EAEQ,0CACN,aACuB;AACvB,UAAM,iBAAiB,KAAK,4BAA4B,IAAI,WAAW;AACvE,QAAI,CAAC,gBAAgB;AACnB,YAAM,IAAI,MAAM,4CAA4C;AAAA,IAC9D;AACA,WAAO;AAAA,EACT;AAAA,EAEQ,iBAAiB,MAA+B;AACtD,QAAI,KAAK,mBAAmB,gBAAgB,KAAK,UAAU,UAAU,EAAE,MAAM;AAC3E,aAAO;AAAA,IACT,WAAW,gBAAgB,KAAK,UAAU,UAAU,EAAE,mBAAmB;AACvE,aAAO;AAAA,IACT,WAAW,gBAAgB,KAAK,UAAU,UAAU,EAAE,SAAS;AAC7D,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT;AAAA,EAEQ,mBAAmB,MAAsB,eAAgC;AAC/E,WAAO,cAAc,WAAW,IAAI;AAAA,EACtC;AAAA,EAEO,oCACL,cACA,aACM;AACN,UAAM,UAAU,KAAK,aAAa,IAAI,YAAY,MAAM;AACxD,QAAI,CAAC,SAAS;AACZ,cAAQ,MAAM,sCAAsC,YAAY,MAAM;AACtE;AAAA,IACF;AAEA,QAAI,mBAAmB,KAAK,UAAU,UAAU,EAAE,MAAM;AACtD,cAAQ,KAAK,2CAA2C;AACxD;AAAA,IACF;AAEA,SAAK,UAAU;AAAA,MACb;AAAA,MACA,QAAQ;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAAA,EAEO,UAAU;AACf,kBAAc,KAAK,yBAAyB;AAC5C,SAAK,UAAU,QAAQ;AAAA,EACzB;AAAA,EAEQ,kBAAkB;AACxB,WAAO,KAAK,UAAU,gBAAgB;AAAA,EACxC;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build/utils.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { StaticVirtualDOMElement } from "@mml-io/observable-dom-common";
|
|
2
2
|
import { LiveVirtualDOMElement } from "./ObservableDOM";
|
|
3
3
|
export declare function virtualDOMElementToStatic(el: LiveVirtualDOMElement): StaticVirtualDOMElement;
|
|
4
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAExE,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAExD,wBAAgB,yBAAyB,CAAC,EAAE,EAAE,qBAAqB,GAAG,uBAAuB,CAQ5F"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mml-io/observable-dom",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@mml-io/observable-dom-common": "^0.
|
|
22
|
+
"@mml-io/observable-dom-common": "^0.23.0",
|
|
23
23
|
"canvas": "3.1.2",
|
|
24
24
|
"jsdom": "26.1.0",
|
|
25
25
|
"node-fetch": "3.3.2"
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"@types/jsdom": "^21.1.7",
|
|
29
29
|
"@types/node-fetch": "2.6.12"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "92699e8e944cc238ae856a10173095ad4bf42fad"
|
|
32
32
|
}
|