adnbn 0.12.0 → 0.13.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/dist/cli/bundler/layers.d.ts +3 -3
- package/dist/cli/bundler/layers.js +6 -7
- package/dist/cli/bundler/layers.js.map +1 -1
- package/dist/cli/bundler/plugins/build-assets-map/BuildAssetsMapPlugin.js +42 -14
- package/dist/cli/bundler/plugins/build-assets-map/BuildAssetsMapPlugin.js.map +1 -1
- package/dist/cli/bundler/plugins/build-assets-map/normalize.d.ts +3 -0
- package/dist/cli/bundler/plugins/build-assets-map/normalize.js +24 -0
- package/dist/cli/bundler/plugins/build-assets-map/normalize.js.map +1 -0
- package/dist/cli/bundler/plugins/build-assets-map/templates/runtime.template.d.ts +2 -0
- package/dist/cli/bundler/plugins/build-assets-map/templates.d.ts +9 -0
- package/dist/cli/bundler/plugins/build-assets-map/templates.js +32 -0
- package/dist/cli/bundler/plugins/entrypoint/EntrypointPlugin.js +11 -0
- package/dist/cli/bundler/plugins/entrypoint/EntrypointPlugin.js.map +1 -1
- package/dist/cli/bundler/plugins/isolated-styles/IsolatedStylesPlugin.d.ts +1 -1
- package/dist/cli/bundler/plugins/isolated-styles/IsolatedStylesPlugin.js +38 -13
- package/dist/cli/bundler/plugins/isolated-styles/IsolatedStylesPlugin.js.map +1 -1
- package/dist/cli/bundler/plugins/isolated-styles/chunks.d.ts +5 -1
- package/dist/cli/bundler/plugins/isolated-styles/chunks.js +17 -16
- package/dist/cli/bundler/plugins/isolated-styles/chunks.js.map +1 -1
- package/dist/cli/bundler/plugins/isolated-styles/split-chunks.d.ts +4 -0
- package/dist/cli/bundler/plugins/isolated-styles/split-chunks.js +51 -0
- package/dist/cli/bundler/plugins/isolated-styles/split-chunks.js.map +1 -0
- package/dist/cli/bundler/plugins/isolated-styles/templates.js +36 -6
- package/dist/cli/plugins/content/bundler.d.ts +0 -3
- package/dist/cli/plugins/content/bundler.js +4 -20
- package/dist/cli/plugins/content/bundler.js.map +1 -1
- package/dist/cli/plugins/content/index.js +2 -3
- package/dist/cli/plugins/content/index.js.map +1 -1
- package/dist/cli/plugins/locale/Locale.js +5 -2
- package/dist/cli/plugins/locale/Locale.js.map +1 -1
- package/dist/cli/plugins/style/index.d.ts +1 -2
- package/dist/cli/plugins/style/index.js +19 -30
- package/dist/cli/plugins/style/index.js.map +1 -1
- package/dist/cli/resolvers/config.js +1 -2
- package/dist/cli/resolvers/config.js.map +1 -1
- package/dist/entry/content/adapters/react/Builder.d.ts +4 -2
- package/dist/entry/content/adapters/react/Builder.js +11 -5
- package/dist/entry/content/adapters/react/Builder.js.map +1 -1
- package/dist/entry/content/adapters/react/Node.js +2 -2
- package/dist/entry/content/adapters/react/Node.js.map +1 -1
- package/dist/entry/content/adapters/react/definition.d.ts +2 -0
- package/dist/entry/content/adapters/react/{resolvers/definition.js → definition.js} +1 -1
- package/dist/entry/content/adapters/react/definition.js.map +1 -0
- package/dist/entry/content/adapters/react/index.d.ts +1 -1
- package/dist/entry/content/adapters/react/index.js +1 -1
- package/dist/entry/content/adapters/react/index.js.map +1 -1
- package/dist/entry/content/adapters/vanilla/Builder.d.ts +4 -2
- package/dist/entry/content/adapters/vanilla/Builder.js +14 -5
- package/dist/entry/content/adapters/vanilla/Builder.js.map +1 -1
- package/dist/entry/content/adapters/vanilla/definition.d.ts +2 -0
- package/dist/entry/content/adapters/vanilla/{resolvers/definition.js → definition.js} +2 -2
- package/dist/entry/content/adapters/vanilla/definition.js.map +1 -0
- package/dist/entry/content/adapters/vanilla/index.d.ts +1 -1
- package/dist/entry/content/adapters/vanilla/index.js +1 -1
- package/dist/entry/content/adapters/vanilla/index.js.map +1 -1
- package/dist/entry/content/adapters/vanilla/utils.d.ts +1 -0
- package/dist/entry/content/adapters/vanilla/utils.js +7 -0
- package/dist/entry/content/adapters/vanilla/utils.js.map +1 -0
- package/dist/entry/content/lifecycle/Builder.d.ts +10 -4
- package/dist/entry/content/lifecycle/Builder.js +102 -60
- package/dist/entry/content/lifecycle/Builder.js.map +1 -1
- package/dist/entry/content/lifecycle/MountBuilder.d.ts +6 -3
- package/dist/entry/content/lifecycle/MountBuilder.js +32 -16
- package/dist/entry/content/lifecycle/MountBuilder.js.map +1 -1
- package/dist/entry/content/lifecycle/context/ContainerRegistry.d.ts +7 -0
- package/dist/entry/content/lifecycle/context/ContainerRegistry.js +45 -0
- package/dist/entry/content/lifecycle/context/ContainerRegistry.js.map +1 -0
- package/dist/entry/content/lifecycle/context/Context.d.ts +6 -3
- package/dist/entry/content/lifecycle/context/Context.js +21 -6
- package/dist/entry/content/lifecycle/context/Context.js.map +1 -1
- package/dist/entry/content/lifecycle/context/ManagedContext.d.ts +4 -1
- package/dist/entry/content/lifecycle/context/ManagedContext.js +7 -0
- package/dist/entry/content/lifecycle/context/ManagedContext.js.map +1 -1
- package/dist/entry/content/lifecycle/context/index.d.ts +1 -0
- package/dist/entry/content/lifecycle/context/index.js +6 -4
- package/dist/entry/content/lifecycle/context/index.js.map +1 -1
- package/dist/entry/content/lifecycle/markers/AttributeMarker.js +3 -1
- package/dist/entry/content/lifecycle/markers/AttributeMarker.js.map +1 -1
- package/dist/entry/content/lifecycle/nodes/EventNode.d.ts +4 -2
- package/dist/entry/content/lifecycle/nodes/EventNode.js +7 -2
- package/dist/entry/content/lifecycle/nodes/EventNode.js.map +1 -1
- package/dist/entry/content/lifecycle/nodes/FrameNode.d.ts +2 -1
- package/dist/entry/content/lifecycle/nodes/FrameNode.js +3 -0
- package/dist/entry/content/lifecycle/nodes/FrameNode.js.map +1 -1
- package/dist/entry/content/lifecycle/nodes/MarkerNode.d.ts +1 -1
- package/dist/entry/content/lifecycle/nodes/MarkerNode.js.map +1 -1
- package/dist/entry/content/lifecycle/nodes/MountNode.d.ts +7 -3
- package/dist/entry/content/lifecycle/nodes/MountNode.js +47 -12
- package/dist/entry/content/lifecycle/nodes/MountNode.js.map +1 -1
- package/dist/entry/content/lifecycle/nodes/Node.d.ts +1 -1
- package/dist/entry/content/lifecycle/nodes/Node.js.map +1 -1
- package/dist/entry/content/lifecycle/nodes/RenderNode.d.ts +13 -4
- package/dist/entry/content/lifecycle/nodes/RenderNode.js +71 -6
- package/dist/entry/content/lifecycle/nodes/RenderNode.js.map +1 -1
- package/dist/entry/content/lifecycle/nodes/ShadowNode.d.ts +2 -1
- package/dist/entry/content/lifecycle/nodes/ShadowNode.js +3 -0
- package/dist/entry/content/lifecycle/nodes/ShadowNode.js.map +1 -1
- package/dist/entry/content/lifecycle/types.d.ts +28 -0
- package/dist/entry/content/resolvers/watch.d.ts +1 -1
- package/dist/entry/content/resolvers/watch.js +29 -14
- package/dist/entry/content/resolvers/watch.js.map +1 -1
- package/dist/entry/relay/index.js.map +1 -1
- package/dist/shared/locale/index.d.ts +1 -1
- package/dist/shared/locale/index.js +3 -1
- package/dist/shared/locale/index.js.map +1 -1
- package/dist/shared/locale/messages.d.ts +4 -0
- package/dist/shared/locale/messages.js +12 -0
- package/dist/shared/locale/messages.js.map +1 -1
- package/dist/types/content/common.d.ts +8 -0
- package/dist/types/content/common.js.map +1 -1
- package/dist/types/content/definition.d.ts +5 -0
- package/dist/types/locale.d.ts +3 -0
- package/dist/types/locale.js.map +1 -1
- package/package.json +1 -3
- package/types/client.d.ts +3 -3
- package/dist/cli/plugins/style/types.d.ts +0 -5
- package/dist/entry/content/adapters/react/resolvers/definition.d.ts +0 -2
- package/dist/entry/content/adapters/react/resolvers/definition.js.map +0 -1
- package/dist/entry/content/adapters/react/resolvers/render.d.ts +0 -2
- package/dist/entry/content/adapters/react/resolvers/render.js +0 -9
- package/dist/entry/content/adapters/react/resolvers/render.js.map +0 -1
- package/dist/entry/content/adapters/vanilla/resolvers/definition.d.ts +0 -2
- package/dist/entry/content/adapters/vanilla/resolvers/definition.js.map +0 -1
- package/dist/entry/content/adapters/vanilla/resolvers/render.d.ts +0 -3
- package/dist/entry/content/adapters/vanilla/resolvers/render.js +0 -15
- package/dist/entry/content/adapters/vanilla/resolvers/render.js.map +0 -1
- /package/dist/{cli/plugins/style → entry/content/lifecycle}/types.js +0 -0
- /package/dist/{cli/plugins/style → entry/content/lifecycle}/types.js.map +0 -0
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { default as default2 } from "./Context.js";
|
|
2
|
-
import { default as default3 } from "./
|
|
3
|
-
import { default as default4 } from "./
|
|
2
|
+
import { default as default3 } from "./ContainerRegistry.js";
|
|
3
|
+
import { default as default4 } from "./ManagedContext.js";
|
|
4
|
+
import { default as default5 } from "./EventEmitter.js";
|
|
4
5
|
export {
|
|
6
|
+
default3 as ContainerRegistry,
|
|
5
7
|
default2 as Context,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
default5 as EventEmitter,
|
|
9
|
+
default4 as ManagedContext
|
|
8
10
|
};
|
|
9
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/entry/content/lifecycle/context/index.ts"],"sourcesContent":["export {default as Context} from \"./Context\";\nexport {default as ManagedContext} from \"./ManagedContext\";\nexport {default as EventEmitter} from \"./EventEmitter\";\n"],"mappings":"AAAA,SAAmB,WAAXA,gBAAyB;AACjC,SAAmB,WAAXA,gBAAgC;AACxC,SAAmB,WAAXA,gBAA8B;","names":["default"]}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/entry/content/lifecycle/context/index.ts"],"sourcesContent":["export {default as Context} from \"./Context\";\nexport {default as ContainerRegistry} from \"./ContainerRegistry\";\nexport {default as ManagedContext} from \"./ManagedContext\";\nexport {default as EventEmitter} from \"./EventEmitter\";\n"],"mappings":"AAAA,SAAmB,WAAXA,gBAAyB;AACjC,SAAmB,WAAXA,gBAAmC;AAC3C,SAAmB,WAAXA,gBAAgC;AACxC,SAAmB,WAAXA,gBAA8B;","names":["default"]}
|
|
@@ -10,7 +10,9 @@ class AttributeMarker extends AbstractMarker {
|
|
|
10
10
|
return element.hasAttribute(this.attr);
|
|
11
11
|
}
|
|
12
12
|
mark(element, value) {
|
|
13
|
-
element.
|
|
13
|
+
if (element.getAttribute(this.attr) !== value) {
|
|
14
|
+
element.setAttribute(this.attr, value);
|
|
15
|
+
}
|
|
14
16
|
return true;
|
|
15
17
|
}
|
|
16
18
|
unmark(element) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/entry/content/lifecycle/markers/AttributeMarker.ts"],"sourcesContent":["import {customAlphabet} from \"nanoid\";\n\nimport AbstractMarker from \"./AbstractMarker\";\n\nimport {ContentScriptAnchor, ContentScriptMarkerValue} from \"@typing/content\";\n\nexport default class AttributeMarker extends AbstractMarker {\n protected readonly attr: string;\n\n constructor(anchor?: ContentScriptAnchor, attr?: string) {\n super(anchor);\n\n this.attr = attr ?? `data-${customAlphabet(\"abcdefghijklmnopqrstuvwxyz\", 7)()}`;\n }\n\n public isMarked(element: Element): boolean {\n return element.hasAttribute(this.attr);\n }\n\n public mark(element: Element, value: ContentScriptMarkerValue): boolean {\n element.setAttribute(this.attr, value);\n\n return true;\n }\n\n public unmark(element: Element): boolean {\n element.removeAttribute(this.attr);\n\n return true;\n }\n\n public value(element: Element): ContentScriptMarkerValue | undefined {\n const value = element.getAttribute(this.attr);\n\n return this.isValidValue(value) ? value : undefined;\n }\n\n protected querySelector(selector: string, marked: boolean = false): Element[] {\n const filter = marked ? `[${this.attr}]` : `:not([${this.attr}])`;\n\n return super.querySelector(`:is(${selector})${filter}`, marked);\n }\n\n protected queryXpath(xpath: string, marked: boolean = false): Element[] {\n const filter = marked ? `[@${this.attr}]` : `[not(@${this.attr})]`;\n\n return super.queryXpath(`(${xpath.trim()})${filter}`, marked);\n }\n}\n"],"mappings":"AAAA,SAAQ,sBAAqB;AAE7B,OAAO,oBAAoB;AAI3B,MAAO,wBAAsC,eAAe;AAAA,EACrC;AAAA,EAEnB,YAAY,QAA8B,MAAe;AACrD,UAAM,MAAM;AAEZ,SAAK,OAAO,QAAQ,QAAQ,eAAe,8BAA8B,CAAC,EAAE,CAAC;AAAA,EACjF;AAAA,EAEO,SAAS,SAA2B;AACvC,WAAO,QAAQ,aAAa,KAAK,IAAI;AAAA,EACzC;AAAA,EAEO,KAAK,SAAkB,OAA0C;AACpE,
|
|
1
|
+
{"version":3,"sources":["../../../../../src/entry/content/lifecycle/markers/AttributeMarker.ts"],"sourcesContent":["import {customAlphabet} from \"nanoid\";\n\nimport AbstractMarker from \"./AbstractMarker\";\n\nimport {ContentScriptAnchor, ContentScriptMarkerValue} from \"@typing/content\";\n\nexport default class AttributeMarker extends AbstractMarker {\n protected readonly attr: string;\n\n constructor(anchor?: ContentScriptAnchor, attr?: string) {\n super(anchor);\n\n this.attr = attr ?? `data-${customAlphabet(\"abcdefghijklmnopqrstuvwxyz\", 7)()}`;\n }\n\n public isMarked(element: Element): boolean {\n return element.hasAttribute(this.attr);\n }\n\n public mark(element: Element, value: ContentScriptMarkerValue): boolean {\n if (element.getAttribute(this.attr) !== value) {\n element.setAttribute(this.attr, value);\n }\n\n return true;\n }\n\n public unmark(element: Element): boolean {\n element.removeAttribute(this.attr);\n\n return true;\n }\n\n public value(element: Element): ContentScriptMarkerValue | undefined {\n const value = element.getAttribute(this.attr);\n\n return this.isValidValue(value) ? value : undefined;\n }\n\n protected querySelector(selector: string, marked: boolean = false): Element[] {\n const filter = marked ? `[${this.attr}]` : `:not([${this.attr}])`;\n\n return super.querySelector(`:is(${selector})${filter}`, marked);\n }\n\n protected queryXpath(xpath: string, marked: boolean = false): Element[] {\n const filter = marked ? `[@${this.attr}]` : `[not(@${this.attr})]`;\n\n return super.queryXpath(`(${xpath.trim()})${filter}`, marked);\n }\n}\n"],"mappings":"AAAA,SAAQ,sBAAqB;AAE7B,OAAO,oBAAoB;AAI3B,MAAO,wBAAsC,eAAe;AAAA,EACrC;AAAA,EAEnB,YAAY,QAA8B,MAAe;AACrD,UAAM,MAAM;AAEZ,SAAK,OAAO,QAAQ,QAAQ,eAAe,8BAA8B,CAAC,EAAE,CAAC;AAAA,EACjF;AAAA,EAEO,SAAS,SAA2B;AACvC,WAAO,QAAQ,aAAa,KAAK,IAAI;AAAA,EACzC;AAAA,EAEO,KAAK,SAAkB,OAA0C;AACpE,QAAI,QAAQ,aAAa,KAAK,IAAI,MAAM,OAAO;AAC3C,cAAQ,aAAa,KAAK,MAAM,KAAK;AAAA,IACzC;AAEA,WAAO;AAAA,EACX;AAAA,EAEO,OAAO,SAA2B;AACrC,YAAQ,gBAAgB,KAAK,IAAI;AAEjC,WAAO;AAAA,EACX;AAAA,EAEO,MAAM,SAAwD;AACjE,UAAM,QAAQ,QAAQ,aAAa,KAAK,IAAI;AAE5C,WAAO,KAAK,aAAa,KAAK,IAAI,QAAQ;AAAA,EAC9C;AAAA,EAEU,cAAc,UAAkB,SAAkB,OAAkB;AAC1E,UAAM,SAAS,SAAS,IAAI,KAAK,IAAI,MAAM,SAAS,KAAK,IAAI;AAE7D,WAAO,MAAM,cAAc,OAAO,QAAQ,IAAI,MAAM,IAAI,MAAM;AAAA,EAClE;AAAA,EAEU,WAAW,OAAe,SAAkB,OAAkB;AACpE,UAAM,SAAS,SAAS,KAAK,KAAK,IAAI,MAAM,SAAS,KAAK,IAAI;AAE9D,WAAO,MAAM,WAAW,IAAI,MAAM,KAAK,CAAC,IAAI,MAAM,IAAI,MAAM;AAAA,EAChE;AACJ;","names":[]}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { ContentScriptBoundary, ContentScriptEventEmitter
|
|
1
|
+
import { ContentScriptNode, ContentScriptBoundary, ContentScriptEventEmitter } from "../../../../types/content/index.js";
|
|
2
|
+
import type { ContentScriptMountNotifier } from "../types.js";
|
|
2
3
|
export default class EventNode implements ContentScriptNode {
|
|
3
4
|
protected readonly node: ContentScriptNode;
|
|
4
5
|
protected readonly emitter: ContentScriptEventEmitter;
|
|
6
|
+
private readonly notifier?;
|
|
5
7
|
private generation;
|
|
6
|
-
constructor(node: ContentScriptNode, emitter: ContentScriptEventEmitter);
|
|
8
|
+
constructor(node: ContentScriptNode, emitter: ContentScriptEventEmitter, notifier?: ContentScriptMountNotifier | undefined);
|
|
7
9
|
get anchor(): Element;
|
|
8
10
|
get container(): Element | undefined;
|
|
9
11
|
get target(): Element | undefined;
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
class EventNode {
|
|
2
|
-
constructor(node, emitter) {
|
|
2
|
+
constructor(node, emitter, notifier) {
|
|
3
3
|
this.node = node;
|
|
4
4
|
this.emitter = emitter;
|
|
5
|
+
this.notifier = notifier;
|
|
6
|
+
notifier == null ? void 0 : notifier.setMountHandler(() => {
|
|
7
|
+
this.emitter.emitMount(this.node);
|
|
8
|
+
});
|
|
5
9
|
}
|
|
6
10
|
node;
|
|
7
11
|
emitter;
|
|
12
|
+
notifier;
|
|
8
13
|
generation = 0;
|
|
9
14
|
get anchor() {
|
|
10
15
|
return this.node.anchor;
|
|
@@ -24,7 +29,7 @@ class EventNode {
|
|
|
24
29
|
if (generation !== this.generation) {
|
|
25
30
|
return false;
|
|
26
31
|
}
|
|
27
|
-
if (result === true) {
|
|
32
|
+
if (result === true && !this.notifier) {
|
|
28
33
|
this.emitter.emitMount(this.node);
|
|
29
34
|
}
|
|
30
35
|
return !!result;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/entry/content/lifecycle/nodes/EventNode.ts"],"sourcesContent":["import {ContentScriptBoundary, ContentScriptEventEmitter
|
|
1
|
+
{"version":3,"sources":["../../../../../src/entry/content/lifecycle/nodes/EventNode.ts"],"sourcesContent":["import {ContentScriptNode, ContentScriptBoundary, ContentScriptEventEmitter} from \"@typing/content\";\nimport type {ContentScriptMountNotifier} from \"../types\";\n\nexport default class EventNode implements ContentScriptNode {\n private generation = 0;\n\n constructor(\n protected readonly node: ContentScriptNode,\n protected readonly emitter: ContentScriptEventEmitter,\n private readonly notifier?: ContentScriptMountNotifier\n ) {\n notifier?.setMountHandler(() => {\n this.emitter.emitMount(this.node);\n });\n }\n\n public get anchor(): Element {\n return this.node.anchor;\n }\n\n public get container(): Element | undefined {\n return this.node.container;\n }\n\n public get target(): Element | undefined {\n return this.node.target;\n }\n\n public get boundary(): ContentScriptBoundary {\n return this.node.boundary;\n }\n\n public mount(): boolean {\n const generation = this.generation;\n const result = this.node.mount();\n\n if (generation !== this.generation) {\n return false;\n }\n\n if (result === true && !this.notifier) {\n this.emitter.emitMount(this.node);\n }\n\n return !!result;\n }\n\n public unmount(): boolean {\n this.generation++;\n\n const result = this.node.unmount();\n\n if (result === true) {\n this.emitter.emitUnmount(this.node);\n }\n\n return !!result;\n }\n}\n"],"mappings":"AAGA,MAAO,UAAqD;AAAA,EAGxD,YACuB,MACA,SACF,UACnB;AAHqB;AACA;AACF;AAEjB,yCAAU,gBAAgB,MAAM;AAC5B,WAAK,QAAQ,UAAU,KAAK,IAAI;AAAA,IACpC;AAAA,EACJ;AAAA,EAPuB;AAAA,EACA;AAAA,EACF;AAAA,EALb,aAAa;AAAA,EAYrB,IAAW,SAAkB;AACzB,WAAO,KAAK,KAAK;AAAA,EACrB;AAAA,EAEA,IAAW,YAAiC;AACxC,WAAO,KAAK,KAAK;AAAA,EACrB;AAAA,EAEA,IAAW,SAA8B;AACrC,WAAO,KAAK,KAAK;AAAA,EACrB;AAAA,EAEA,IAAW,WAAkC;AACzC,WAAO,KAAK,KAAK;AAAA,EACrB;AAAA,EAEO,QAAiB;AACpB,UAAM,aAAa,KAAK;AACxB,UAAM,SAAS,KAAK,KAAK,MAAM;AAE/B,QAAI,eAAe,KAAK,YAAY;AAChC,aAAO;AAAA,IACX;AAEA,QAAI,WAAW,QAAQ,CAAC,KAAK,UAAU;AACnC,WAAK,QAAQ,UAAU,KAAK,IAAI;AAAA,IACpC;AAEA,WAAO,CAAC,CAAC;AAAA,EACb;AAAA,EAEO,UAAmB;AACtB,SAAK;AAEL,UAAM,SAAS,KAAK,KAAK,QAAQ;AAEjC,QAAI,WAAW,MAAM;AACjB,WAAK,QAAQ,YAAY,KAAK,IAAI;AAAA,IACtC;AAEA,WAAO,CAAC,CAAC;AAAA,EACb;AACJ;","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ContentScriptNode, ContentScriptIsolationFrameOptions } from "../../../../types/content/index.js";
|
|
2
2
|
import type IsolationSetup from "../IsolationSetup.js";
|
|
3
3
|
/** Owns the child document but never moves the content script's JavaScript into it. */
|
|
4
4
|
export default class FrameNode<Data = unknown> implements ContentScriptNode {
|
|
@@ -20,6 +20,7 @@ export default class FrameNode<Data = unknown> implements ContentScriptNode {
|
|
|
20
20
|
get container(): Element | undefined;
|
|
21
21
|
get target(): Element | undefined;
|
|
22
22
|
get boundary(): HTMLIFrameElement | undefined;
|
|
23
|
+
ready(): Promise<void>;
|
|
23
24
|
private readonly onLoad;
|
|
24
25
|
private intact;
|
|
25
26
|
mount(): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/entry/content/lifecycle/nodes/FrameNode.ts"],"sourcesContent":["import {getPageUrl} from \"@main/page\";\n\nimport type {\n ContentScriptBoundaryCleanup,\n ContentScriptIsolationFrameOptions,\n ContentScriptNode,\n ContentScriptStylesRuntime,\n} from \"@typing/content\";\nimport {ContentScriptIsolation} from \"@typing/content\";\n\nimport type IsolationSetup from \"../IsolationSetup\";\n\nimport {getContentScriptStylesRuntime} from \"./isolated-styles\";\n\nimport {isContentScriptFrameNavigation} from \"@shared/content\";\n\n/** Owns the child document but never moves the content script's JavaScript into it. */\nexport default class FrameNode<Data = unknown> implements ContentScriptNode {\n private frame?: HTMLIFrameElement;\n private head?: HTMLHeadElement;\n private _target?: Element;\n\n private runtime?: ContentScriptStylesRuntime;\n\n private generation = 0;\n private queued = false;\n\n private cleanupBoundary?: ContentScriptBoundaryCleanup;\n\n private mounting = false;\n private unmounting = false;\n\n public constructor(\n private readonly node: ContentScriptNode,\n private readonly options: ContentScriptIsolationFrameOptions = {type: ContentScriptIsolation.Iframe},\n private readonly recover: () => void,\n private readonly isolation: IsolationSetup<Data, \"iframe\">\n ) {}\n\n public get anchor(): Element {\n return this.node.anchor;\n }\n\n public get container(): Element | undefined {\n return this.node.container;\n }\n\n public get target(): Element | undefined {\n return this._target;\n }\n\n public get boundary(): HTMLIFrameElement | undefined {\n return this.frame;\n }\n\n private readonly onLoad = (): void => {\n if (!this.frame || this.queued || this.intact()) {\n return;\n }\n\n const generation = this.generation;\n\n this.queued = true;\n\n queueMicrotask(() => {\n if (generation !== this.generation) {\n return;\n }\n\n this.queued = false;\n\n if (this.container?.isConnected && this.anchor.isConnected) {\n try {\n this.recover();\n } catch (error) {\n console.error(\"Restoring content iframe failed\", error);\n }\n }\n });\n };\n\n private intact(): boolean {\n const doc = this.frame?.contentDocument;\n\n return !!doc && this._target?.ownerDocument === doc && this._target.isConnected && this.head === doc.head;\n }\n\n public mount(): boolean {\n if (this.mounting || this.unmounting) {\n return false;\n }\n\n this.mounting = true;\n\n try {\n return this.mountNode();\n } finally {\n this.mounting = false;\n }\n }\n\n private mountNode(): boolean {\n const mounted = !!this.node.mount();\n\n if (!this.container) {\n return mounted;\n }\n\n if (!isContentScriptFrameNavigation(this.options) && !this.container.isConnected) {\n throw new Error(\n \"Content iframe container is not connected to the document; mount must attach the container before returning\"\n );\n }\n\n let created = false;\n\n if (!this.frame) {\n const frame = this.container.ownerDocument.createElement(\"iframe\");\n\n this.frame = frame;\n const generation = this.generation;\n\n try {\n const cleanup = this.isolation.setup(frame);\n\n if (generation !== this.generation || this.frame !== frame) {\n cleanup?.();\n\n return false;\n }\n\n this.cleanupBoundary = cleanup || undefined;\n\n if (isContentScriptFrameNavigation(this.options)) {\n frame.src = this.options.page !== undefined ? getPageUrl(this.options.page) : this.options.src!;\n } else {\n frame.addEventListener(\"load\", this.onLoad);\n }\n\n this.container.append(frame);\n\n if (generation !== this.generation || this.frame !== frame) {\n return false;\n }\n\n created = true;\n } catch (error) {\n if (generation === this.generation && this.frame === frame) {\n this.unmount();\n }\n\n throw error;\n }\n }\n\n if (isContentScriptFrameNavigation(this.options) || this.intact()) {\n return mounted || created;\n }\n\n const doc = this.frame.contentDocument;\n\n if (!doc?.head || !doc.body) {\n throw new Error(\n \"Content iframe has no accessible document; only an empty same-origin iframe can render UI\"\n );\n }\n\n const recovering = this.head !== undefined;\n\n this.releaseStyles();\n\n const frame = this.frame;\n const generation = this.generation;\n\n try {\n const target = this.isolation.createTarget(frame, doc);\n\n if (generation !== this.generation || this.frame !== frame || frame.contentDocument !== doc) {\n return false;\n }\n\n doc.body.append(target);\n\n this._target = target;\n this.head = doc.head;\n this.runtime = getContentScriptStylesRuntime();\n this.runtime.add(doc.head, null, recovering);\n } catch (error) {\n if (generation === this.generation && this.frame === frame) {\n this.unmount();\n }\n\n throw error;\n }\n\n return true;\n }\n\n public unmount(): boolean {\n if (this.unmounting) {\n return false;\n }\n\n this.unmounting = true;\n this.generation++;\n this.queued = false;\n this._target = undefined;\n\n const cleanup = this.cleanupBoundary;\n\n this.cleanupBoundary = undefined;\n\n let removed = false;\n\n try {\n try {\n cleanup?.();\n } finally {\n try {\n this.frame?.removeEventListener(\"load\", this.onLoad);\n this.releaseStyles();\n } finally {\n this.frame = undefined;\n removed = !!this.node.unmount();\n }\n }\n\n return removed;\n } finally {\n this.unmounting = false;\n }\n }\n\n private releaseStyles(): void {\n const head = this.head;\n const runtime = this.runtime;\n\n this.head = undefined;\n this.runtime = undefined;\n this._target = undefined;\n\n if (head) {\n runtime?.delete(head);\n }\n }\n}\n"],"mappings":"AAAA,SAAQ,kBAAiB;AAQzB,SAAQ,8BAA6B;AAIrC,SAAQ,qCAAoC;AAE5C,SAAQ,sCAAqC;AAG7C,MAAO,UAAqE;AAAA,EAejE,YACc,MACA,UAA8C,EAAC,MAAM,uBAAuB,OAAM,GAClF,SACA,WACnB;AAJmB;AACA;AACA;AACA;AAAA,EAClB;AAAA,EAJkB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAlBb;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EAEA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ent":["import {getPageUrl} from \"@main/page\";\n\nimport type {\n ContentScriptNode,\n ContentScriptBoundaryCleanup,\n ContentScriptIsolationFrameOptions,\n ContentScriptStylesRuntime,\n} from \"@typing/content\";\nimport {ContentScriptIsolation} from \"@typing/content\";\n\nimport type IsolationSetup from \"../IsolationSetup\";\n\nimport {getContentScriptStylesRuntime} from \"./isolated-styles\";\n\nimport {isContentScriptFrameNavigation} from \"@shared/content\";\n\n/** Owns the child document but never moves the content script's JavaScript into it. */\nexport default class FrameNode<Data = unknown> implements ContentScriptNode {\n private frame?: HTMLIFrameElement;\n private head?: HTMLHeadElement;\n private _target?: Element;\n\n private runtime?: ContentScriptStylesRuntime;\n\n private generation = 0;\n private queued = false;\n\n private cleanupBoundary?: ContentScriptBoundaryCleanup;\n\n private mounting = false;\n private unmounting = false;\n\n public constructor(\n private readonly node: ContentScriptNode,\n private readonly options: ContentScriptIsolationFrameOptions = {type: ContentScriptIsolation.Iframe},\n private readonly recover: () => void,\n private readonly isolation: IsolationSetup<Data, \"iframe\">\n ) {}\n\n public get anchor(): Element {\n return this.node.anchor;\n }\n\n public get container(): Element | undefined {\n return this.node.container;\n }\n\n public get target(): Element | undefined {\n return this._target;\n }\n\n public get boundary(): HTMLIFrameElement | undefined {\n return this.frame;\n }\n\n public ready(): Promise<void> {\n return this.head && this.runtime ? this.runtime.ready(this.head) : Promise.resolve();\n }\n\n private readonly onLoad = (): void => {\n if (!this.frame || this.queued || this.intact()) {\n return;\n }\n\n const generation = this.generation;\n\n this.queued = true;\n\n queueMicrotask(() => {\n if (generation !== this.generation) {\n return;\n }\n\n this.queued = false;\n\n if (this.container?.isConnected && this.anchor.isConnected) {\n try {\n this.recover();\n } catch (error) {\n console.error(\"Restoring content iframe failed\", error);\n }\n }\n });\n };\n\n private intact(): boolean {\n const doc = this.frame?.contentDocument;\n\n return !!doc && this._target?.ownerDocument === doc && this._target.isConnected && this.head === doc.head;\n }\n\n public mount(): boolean {\n if (this.mounting || this.unmounting) {\n return false;\n }\n\n this.mounting = true;\n\n try {\n return this.mountNode();\n } finally {\n this.mounting = false;\n }\n }\n\n private mountNode(): boolean {\n const mounted = !!this.node.mount();\n\n if (!this.container) {\n return mounted;\n }\n\n if (!isContentScriptFrameNavigation(this.options) && !this.container.isConnected) {\n throw new Error(\n \"Content iframe container is not connected to the document; mount must attach the container before returning\"\n );\n }\n\n let created = false;\n\n if (!this.frame) {\n const frame = this.container.ownerDocument.createElement(\"iframe\");\n\n this.frame = frame;\n const generation = this.generation;\n\n try {\n const cleanup = this.isolation.setup(frame);\n\n if (generation !== this.generation || this.frame !== frame) {\n cleanup?.();\n\n return false;\n }\n\n this.cleanupBoundary = cleanup || undefined;\n\n if (isContentScriptFrameNavigation(this.options)) {\n frame.src = this.options.page !== undefined ? getPageUrl(this.options.page) : this.options.src!;\n } else {\n frame.addEventListener(\"load\", this.onLoad);\n }\n\n this.container.append(frame);\n\n if (generation !== this.generation || this.frame !== frame) {\n return false;\n }\n\n created = true;\n } catch (error) {\n if (generation === this.generation && this.frame === frame) {\n this.unmount();\n }\n\n throw error;\n }\n }\n\n if (isContentScriptFrameNavigation(this.options) || this.intact()) {\n return mounted || created;\n }\n\n const doc = this.frame.contentDocument;\n\n if (!doc?.head || !doc.body) {\n throw new Error(\n \"Content iframe has no accessible document; only an empty same-origin iframe can render UI\"\n );\n }\n\n const recovering = this.head !== undefined;\n\n this.releaseStyles();\n\n const frame = this.frame;\n const generation = this.generation;\n\n try {\n const target = this.isolation.createTarget(frame, doc);\n\n if (generation !== this.generation || this.frame !== frame || frame.contentDocument !== doc) {\n return false;\n }\n\n doc.body.append(target);\n\n this._target = target;\n this.head = doc.head;\n this.runtime = getContentScriptStylesRuntime();\n this.runtime.add(doc.head, null, recovering);\n } catch (error) {\n if (generation === this.generation && this.frame === frame) {\n this.unmount();\n }\n\n throw error;\n }\n\n return true;\n }\n\n public unmount(): boolean {\n if (this.unmounting) {\n return false;\n }\n\n this.unmounting = true;\n this.generation++;\n this.queued = false;\n this._target = undefined;\n\n const cleanup = this.cleanupBoundary;\n\n this.cleanupBoundary = undefined;\n\n let removed = false;\n\n try {\n try {\n cleanup?.();\n } finally {\n try {\n this.frame?.removeEventListener(\"load\", this.onLoad);\n this.releaseStyles();\n } finally {\n this.frame = undefined;\n removed = !!this.node.unmount();\n }\n }\n\n return removed;\n } finally {\n this.unmounting = false;\n }\n }\n\n private releaseStyles(): void {\n const head = this.head;\n const runtime = this.runtime;\n\n this.head = undefined;\n this.runtime = undefined;\n this._target = undefined;\n\n if (head) {\n runtime?.delete(head);\n }\n }\n}\n"],"mappings":"AAAA,SAAQ,kBAAiB;AAQzB,SAAQ,8BAA6B;AAIrC,SAAQ,qCAAoC;AAE5C,SAAQ,sCAAqC;AAG7C,MAAO,UAAqE;AAAA,EAejE,YACc,MACA,UAA8C,EAAC,MAAM,uBAAuB,OAAM,GAClF,SACA,WACnB;AAJmB;AACA;AACA;AACA;AAAA,EAClB;AAAA,EAJkB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAlBb;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EAEA,aAAa;AAAA,EACb,SAAS;AAAA,EAET;AAAA,EAEA,WAAW;AAAA,EACX,aAAa;AAAA,EASrB,IAAW,SAAkB;AACzB,WAAO,KAAK,KAAK;AAAA,EACrB;AAAA,EAEA,IAAW,YAAiC;AACxC,WAAO,KAAK,KAAK;AAAA,EACrB;AAAA,EAEA,IAAW,SAA8B;AACrC,WAAO,KAAK;AAAA,EAChB;AAAA,EAEA,IAAW,WAA0C;AACjD,WAAO,KAAK;AAAA,EAChB;AAAA,EAEO,QAAuB;AAC1B,WAAO,KAAK,QAAQ,KAAK,UAAU,KAAK,QAAQ,MAAM,KAAK,IAAI,IAAI,QAAQ,QAAQ;AAAA,EACvF;AAAA,EAEiB,SAAS,MAAY;AAClC,QAAI,CAAC,KAAK,SAAS,KAAK,UAAU,KAAK,OAAO,GAAG;AAC7C;AAAA,IACJ;AAEA,UAAM,aA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A,IACV;AAEA,WAAO;AAAA,EACX;AAAA,EAEO,UAAmB;AA1M9B;AA2MQ,QAAI,KAAK,YAAY;AACjB,aAAO;AAAA,IACX;AAEA,SAAK,aAAa;AAClB,SAAK;AACL,SAAK,SAAS;AACd,SAAK,UAAU;AAEf,UAAM,UAAU,KAAK;AAErB,SAAK,kBAAkB;AAEvB,QAAI,UAAU;AAEd,QAAI;AACA,UAAI;AACA;AAAA,MACJ,UAAE;AACE,YAAI;AACA,qBAAK,UAAL,mBAAY,oBAAoB,QAAQ,KAAK;AAC7C,eAAK,cAAc;AAAA,QACvB,UAAE;AACE,eAAK,QAAQ;AACb,oBAAU,CAAC,CAAC,KAAK,KAAK,QAAQ;AAAA,QAClC;AAAA,MACJ;AAEA,aAAO;AAAA,IACX,UAAE;AACE,WAAK,aAAa;AAAA,IACtB;AAAA,EACJ;AAAA,EAEQ,gBAAsB;AAC1B,UAAM,OAAO,KAAK;AAClB,UAAM,UAAU,KAAK;AAErB,SAAK,OAAO;AACZ,SAAK,UAAU;AACf,SAAK,UAAU;AAEf,QAAI,MAAM;AACN,yCAAS,OAAO;AAAA,IACpB;AAAA,EACJ;AACJ;","names":["frame","generation"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ContentScriptBoundary, ContentScriptMarkerContract
|
|
1
|
+
import { ContentScriptNode, ContentScriptBoundary, ContentScriptMarkerContract } from "../../../../types/content/index.js";
|
|
2
2
|
export default class MarkerNode implements ContentScriptNode {
|
|
3
3
|
protected readonly node: ContentScriptNode;
|
|
4
4
|
protected readonly marker: ContentScriptMarkerContract;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/entry/content/lifecycle/nodes/MarkerNode.ts"],"sourcesContent":["import {ContentScriptBoundary, ContentScriptMarkerContract
|
|
1
|
+
{"version":3,"sources":["../../../../../src/entry/content/lifecycle/nodes/MarkerNode.ts"],"sourcesContent":["import {ContentScriptNode, ContentScriptBoundary, ContentScriptMarkerContract} from \"@typing/content\";\n\nexport default class MarkerNode implements ContentScriptNode {\n constructor(\n protected readonly node: ContentScriptNode,\n protected readonly marker: ContentScriptMarkerContract\n ) {}\n\n public get anchor(): Element {\n return this.node.anchor;\n }\n\n public get container(): Element | undefined {\n return this.node.container;\n }\n\n public get target(): Element | undefined {\n return this.node.target;\n }\n\n public get boundary(): ContentScriptBoundary {\n return this.node.boundary;\n }\n\n public mount(): boolean | undefined | void {\n this.marker.mount(this.anchor);\n\n return this.node.mount();\n }\n\n public unmount(): boolean | undefined | void {\n this.marker.unmount(this.anchor);\n\n return this.node.unmount();\n }\n}\n"],"mappings":"AAEA,MAAO,WAAsD;AAAA,EACzD,YACuB,MACA,QACrB;AAFqB;AACA;AAAA,EACpB;AAAA,EAFoB;AAAA,EACA;AAAA,EAGvB,IAAW,SAAkB;AACzB,WAAO,KAAK,KAAK;AAAA,EACrB;AAAA,EAEA,IAAW,YAAiC;AACxC,WAAO,KAAK,KAAK;AAAA,EACrB;AAAA,EAEA,IAAW,SAA8B;AACrC,WAAO,KAAK,KAAK;AAAA,EACrB;AAAA,EAEA,IAAW,WAAkC;AACzC,WAAO,KAAK,KAAK;AAAA,EACrB;AAAA,EAEO,QAAoC;AACvC,SAAK,OAAO,MAAM,KAAK,MAAM;AAE7B,WAAO,KAAK,KAAK,MAAM;AAAA,EAC3B;AAAA,EAEO,UAAsC;AACzC,SAAK,OAAO,QAAQ,KAAK,MAAM;AAE/B,WAAO,KAAK,KAAK,QAAQ;AAAA,EAC7B;AACJ;","names":[]}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { ContentScriptBoundary, ContentScriptMountFunction
|
|
1
|
+
import { ContentScriptNode, ContentScriptBoundary, ContentScriptMountFunction } from "../../../../types/content/index.js";
|
|
2
|
+
import type ContainerRegistry from "../context/ContainerRegistry.js";
|
|
2
3
|
export default class MountNode implements ContentScriptNode {
|
|
3
4
|
protected node: ContentScriptNode;
|
|
5
|
+
private readonly registry;
|
|
4
6
|
protected mounter?: ContentScriptMountFunction | undefined;
|
|
5
|
-
private
|
|
6
|
-
|
|
7
|
+
private unregister?;
|
|
8
|
+
private cleanup?;
|
|
9
|
+
private unmounting;
|
|
10
|
+
constructor(node: ContentScriptNode, registry: ContainerRegistry, mounter?: ContentScriptMountFunction | undefined);
|
|
7
11
|
get anchor(): Element;
|
|
8
12
|
get container(): Element | undefined;
|
|
9
13
|
get target(): Element | undefined;
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
class MountNode {
|
|
2
|
-
constructor(node, mounter) {
|
|
2
|
+
constructor(node, registry, mounter) {
|
|
3
3
|
this.node = node;
|
|
4
|
+
this.registry = registry;
|
|
4
5
|
this.mounter = mounter;
|
|
5
6
|
}
|
|
6
7
|
node;
|
|
8
|
+
registry;
|
|
7
9
|
mounter;
|
|
8
|
-
|
|
10
|
+
unregister;
|
|
11
|
+
cleanup;
|
|
12
|
+
unmounting = false;
|
|
9
13
|
get anchor() {
|
|
10
14
|
return this.node.anchor;
|
|
11
15
|
}
|
|
@@ -19,24 +23,55 @@ class MountNode {
|
|
|
19
23
|
return this.node.boundary;
|
|
20
24
|
}
|
|
21
25
|
mount() {
|
|
26
|
+
var _a;
|
|
27
|
+
if (this.unmounting) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
22
30
|
this.node.mount();
|
|
23
|
-
|
|
31
|
+
const container = this.container;
|
|
32
|
+
if (!container || container.isConnected || !this.mounter) {
|
|
24
33
|
return false;
|
|
25
34
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
(_a = this.unregister) == null ? void 0 : _a.call(this);
|
|
36
|
+
const unregister = this.registry.register(container, this.anchor);
|
|
37
|
+
this.unregister = unregister;
|
|
38
|
+
try {
|
|
39
|
+
const cleanup = this.mounter(this.anchor, container);
|
|
40
|
+
if (this.unregister !== unregister || this.container !== container) {
|
|
41
|
+
cleanup == null ? void 0 : cleanup();
|
|
42
|
+
return false;
|
|
30
43
|
}
|
|
44
|
+
this.cleanup = cleanup || void 0;
|
|
31
45
|
return true;
|
|
46
|
+
} catch (error) {
|
|
47
|
+
unregister();
|
|
48
|
+
if (this.unregister === unregister) {
|
|
49
|
+
this.unregister = void 0;
|
|
50
|
+
}
|
|
51
|
+
throw error;
|
|
32
52
|
}
|
|
33
|
-
return false;
|
|
34
53
|
}
|
|
35
54
|
unmount() {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
55
|
+
if (this.unmounting) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
const unregister = this.unregister;
|
|
59
|
+
const cleanup = this.cleanup;
|
|
60
|
+
this.unregister = void 0;
|
|
61
|
+
this.cleanup = void 0;
|
|
62
|
+
this.unmounting = true;
|
|
63
|
+
let removed = false;
|
|
64
|
+
try {
|
|
65
|
+
unregister == null ? void 0 : unregister();
|
|
66
|
+
try {
|
|
67
|
+
cleanup == null ? void 0 : cleanup();
|
|
68
|
+
} finally {
|
|
69
|
+
removed = !!this.node.unmount();
|
|
70
|
+
}
|
|
71
|
+
} finally {
|
|
72
|
+
this.unmounting = false;
|
|
73
|
+
}
|
|
74
|
+
return removed;
|
|
40
75
|
}
|
|
41
76
|
}
|
|
42
77
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/entry/content/lifecycle/nodes/MountNode.ts"],"sourcesContent":["import {ContentScriptBoundary, ContentScriptMountFunction
|
|
1
|
+
{"version":3,"sources":["../../../../../src/entry/content/lifecycle/nodes/MountNode.ts"],"sourcesContent":["import {ContentScriptNode, ContentScriptBoundary, ContentScriptMountFunction} from \"@typing/content\";\nimport type ContainerRegistry from \"../context/ContainerRegistry\";\n\nexport default class MountNode implements ContentScriptNode {\n private unregister?: () => void;\n private cleanup?: () => void;\n private unmounting = false;\n\n constructor(\n protected node: ContentScriptNode,\n private readonly registry: ContainerRegistry,\n protected mounter?: ContentScriptMountFunction\n ) {}\n\n public get anchor(): Element {\n return this.node.anchor;\n }\n\n public get container(): Element | undefined {\n return this.node.container;\n }\n\n public get target(): Element | undefined {\n return this.node.target;\n }\n\n public get boundary(): ContentScriptBoundary {\n return this.node.boundary;\n }\n\n public mount(): boolean {\n if (this.unmounting) {\n return false;\n }\n\n this.node.mount();\n const container = this.container;\n\n if (!container || container.isConnected || !this.mounter) {\n return false;\n }\n\n this.unregister?.();\n const unregister = this.registry.register(container, this.anchor);\n this.unregister = unregister;\n\n try {\n const cleanup = this.mounter(this.anchor, container);\n\n if (this.unregister !== unregister || this.container !== container) {\n // A synchronous cancellation must not retain cleanup or revive the registration.\n cleanup?.();\n\n return false;\n }\n\n this.cleanup = cleanup || undefined;\n\n return true;\n } catch (error) {\n unregister();\n\n if (this.unregister === unregister) {\n this.unregister = undefined;\n }\n\n throw error;\n }\n }\n\n public unmount(): boolean {\n if (this.unmounting) {\n return false;\n }\n\n const unregister = this.unregister;\n const cleanup = this.cleanup;\n this.unregister = undefined;\n this.cleanup = undefined;\n this.unmounting = true;\n let removed = false;\n\n try {\n unregister?.();\n\n try {\n cleanup?.();\n } finally {\n removed = !!this.node.unmount();\n }\n } finally {\n this.unmounting = false;\n }\n\n return removed;\n }\n}\n"],"mappings":"AAGA,MAAO,UAAqD;AAAA,EAKxD,YACc,MACO,UACP,SACZ;AAHY;AACO;AACP;AAAA,EACX;AAAA,EAHW;AAAA,EACO;AAAA,EACP;AAAA,EAPN;AAAA,EACA;AAAA,EACA,aAAa;AAAA,EAQrB,IAAW,SAAkB;AACzB,WAAO,KAAK,KAAK;AAAA,EACrB;AAAA,EAEA,IAAW,YAAiC;AACxC,WAAO,KAAK,KAAK;AAAA,EACrB;AAAA,EAEA,IAAW,SAA8B;AACrC,WAAO,KAAK,KAAK;AAAA,EACrB;AAAA,EAEA,IAAW,WAAkC;AACzC,WAAO,KAAK,KAAK;AAAA,EACrB;AAAA,EAEO,QAAiB;AA9B5B;AA+BQ,QAAI,KAAK,YAAY;AACjB,aAAO;AAAA,IACX;AAEA,SAAK,KAAK,MAAM;AAChB,UAAM,YAAY,KAAK;AAEvB,QAAI,CAAC,aAAa,UAAU,eAAe,CAAC,KAAK,SAAS;AACtD,aAAO;AAAA,IACX;AAEA,eAAK,eAAL;AACA,UAAM,aAAa,KAAK,SAAS,SAAS,WAAW,KAAK,MAAM;AAChE,SAAK,aAAa;AAElB,QAAI;AACA,YAAM,UAAU,KAAK,QAAQ,KAAK,QAAQ,SAAS;AAEnD,UAAI,KAAK,eAAe,cAAc,KAAK,cAAc,WAAW;AAEhE;AAEA,eAAO;AAAA,MACX;AAEA,WAAK,UAAU,WAAW;AAE1B,aAAO;AAAA,IACX,SAAS,OAAO;AACZ,iBAAW;AAEX,UAAI,KAAK,eAAe,YAAY;AAChC,aAAK,aAAa;AAAA,MACtB;AAEA,YAAM;AAAA,IACV;AAAA,EACJ;AAAA,EAEO,UAAmB;AACtB,QAAI,KAAK,YAAY;AACjB,aAAO;AAAA,IACX;AAEA,UAAM,aAAa,KAAK;AACxB,UAAM,UAAU,KAAK;AACrB,SAAK,aAAa;AAClB,SAAK,UAAU;AACf,SAAK,aAAa;AAClB,QAAI,UAAU;AAEd,QAAI;AACA;AAEA,UAAI;AACA;AAAA,MACJ,UAAE;AACE,kBAAU,CAAC,CAAC,KAAK,KAAK,QAAQ;AAAA,MAClC;AAAA,IACJ,UAAE;AACE,WAAK,aAAa;AAAA,IACtB;AAEA,WAAO;AAAA,EACX;AACJ;","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ContentScriptNode } from "../../../../types/content/index.js";
|
|
1
|
+
import type { ContentScriptNode } from "../../../../types/content/index.js";
|
|
2
2
|
export default class Node implements ContentScriptNode {
|
|
3
3
|
readonly anchor: Element;
|
|
4
4
|
container?: Element | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/entry/content/lifecycle/nodes/Node.ts"],"sourcesContent":["import {ContentScriptNode} from \"@typing/content\";\n\nexport default class Node implements ContentScriptNode {\n private readonly _container?: Element;\n\n constructor(\n public readonly anchor: Element,\n public container?: Element\n ) {\n if (this.container) {\n this._container = this.container.cloneNode(false) as Element;\n }\n }\n\n public get target(): Element | undefined {\n return this.container;\n }\n\n public mount(): boolean {\n if (!this.container && this._container) {\n this.container = this._container.cloneNode(false) as Element;\n\n return true;\n }\n\n return false;\n }\n\n public unmount(): boolean {\n if (this.container) {\n this.container.remove();\n this.container = undefined;\n\n return true;\n }\n\n return false;\n }\n}\n"],"mappings":"AAEA,MAAO,KAAgD;AAAA,EAGnD,YACoB,QACT,WACT;AAFkB;AACT;AAEP,QAAI,KAAK,WAAW;AAChB,WAAK,aAAa,KAAK,UAAU,UAAU,KAAK;AAAA,IACpD;AAAA,EACJ;AAAA,EANoB;AAAA,EACT;AAAA,EAJM;AAAA,EAWjB,IAAW,SAA8B;AACrC,WAAO,KAAK;AAAA,EAChB;AAAA,EAEO,QAAiB;AACpB,QAAI,CAAC,KAAK,aAAa,KAAK,YAAY;AACpC,WAAK,YAAY,KAAK,WAAW,UAAU,KAAK;AAEhD,aAAO;AAAA,IACX;AAEA,WAAO;AAAA,EACX;AAAA,EAEO,UAAmB;AACtB,QAAI,KAAK,WAAW;AAChB,WAAK,UAAU,OAAO;AACtB,WAAK,YAAY;AAEjB,aAAO;AAAA,IACX;AAEA,WAAO;AAAA,EACX;AACJ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/entry/content/lifecycle/nodes/Node.ts"],"sourcesContent":["import type {ContentScriptNode} from \"@typing/content\";\n\nexport default class Node implements ContentScriptNode {\n private readonly _container?: Element;\n\n constructor(\n public readonly anchor: Element,\n public container?: Element\n ) {\n if (this.container) {\n this._container = this.container.cloneNode(false) as Element;\n }\n }\n\n public get target(): Element | undefined {\n return this.container;\n }\n\n public mount(): boolean {\n if (!this.container && this._container) {\n this.container = this._container.cloneNode(false) as Element;\n\n return true;\n }\n\n return false;\n }\n\n public unmount(): boolean {\n if (this.container) {\n this.container.remove();\n this.container = undefined;\n\n return true;\n }\n\n return false;\n }\n}\n"],"mappings":"AAEA,MAAO,KAAgD;AAAA,EAGnD,YACoB,QACT,WACT;AAFkB;AACT;AAEP,QAAI,KAAK,WAAW;AAChB,WAAK,aAAa,KAAK,UAAU,UAAU,KAAK;AAAA,IACpD;AAAA,EACJ;AAAA,EANoB;AAAA,EACT;AAAA,EAJM;AAAA,EAWjB,IAAW,SAA8B;AACrC,WAAO,KAAK;AAAA,EAChB;AAAA,EAEO,QAAiB;AACpB,QAAI,CAAC,KAAK,aAAa,KAAK,YAAY;AACpC,WAAK,YAAY,KAAK,WAAW,UAAU,KAAK;AAEhD,aAAO;AAAA,IACX;AAEA,WAAO;AAAA,EACX;AAAA,EAEO,UAAmB;AACtB,QAAI,KAAK,WAAW;AAChB,WAAK,UAAU,OAAO;AACtB,WAAK,YAAY;AAEjB,aAAO;AAAA,IACX;AAEA,WAAO;AAAA,EACX;AACJ;","names":[]}
|
|
@@ -1,19 +1,28 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { ContentScriptNode, ContentScriptBoundary, ContentScriptProps, ContentScriptRenderHandler, ContentScriptRenderValue } from "../../../../types/content/index.js";
|
|
2
|
+
import type { ContentScriptRenderLifecycle, ContentScriptRenderOptions } from "../types.js";
|
|
3
|
+
/** Runs the adapter only after mounting DOM and invalidates work when its target is replaced. */
|
|
4
|
+
export default abstract class RenderNode<Data = unknown> implements ContentScriptNode, ContentScriptRenderLifecycle {
|
|
4
5
|
protected readonly node: ContentScriptNode;
|
|
5
6
|
private readonly resolve;
|
|
6
7
|
private readonly props;
|
|
8
|
+
private readonly options?;
|
|
7
9
|
private generation;
|
|
8
10
|
private renderedTarget?;
|
|
11
|
+
private pendingTarget?;
|
|
12
|
+
private mountHandler?;
|
|
13
|
+
private errorHandler?;
|
|
9
14
|
private empty;
|
|
10
|
-
constructor(node: ContentScriptNode, resolve: ContentScriptRenderHandler<Data>, props: () => ContentScriptProps<Data
|
|
15
|
+
constructor(node: ContentScriptNode, resolve: ContentScriptRenderHandler<Data>, props: () => ContentScriptProps<Data>, options?: ContentScriptRenderOptions | undefined);
|
|
11
16
|
get anchor(): Element;
|
|
12
17
|
get container(): Element | undefined;
|
|
13
18
|
get target(): Element | undefined;
|
|
14
19
|
get boundary(): ContentScriptBoundary;
|
|
15
20
|
protected abstract render(value: ContentScriptRenderValue<Data> | undefined, target: Element): boolean;
|
|
16
21
|
protected abstract clear(): void;
|
|
22
|
+
setMountHandler(handler: () => void): void;
|
|
23
|
+
setErrorHandler(handler: (error: unknown) => void): void;
|
|
17
24
|
mount(): boolean;
|
|
25
|
+
private completeRender;
|
|
26
|
+
private renderTarget;
|
|
18
27
|
unmount(): boolean;
|
|
19
28
|
}
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
class RenderNode {
|
|
2
|
-
constructor(node, resolve, props) {
|
|
2
|
+
constructor(node, resolve, props, options) {
|
|
3
3
|
this.node = node;
|
|
4
4
|
this.resolve = resolve;
|
|
5
5
|
this.props = props;
|
|
6
|
+
this.options = options;
|
|
6
7
|
}
|
|
7
8
|
node;
|
|
8
9
|
resolve;
|
|
9
10
|
props;
|
|
11
|
+
options;
|
|
10
12
|
generation = 0;
|
|
11
13
|
renderedTarget;
|
|
14
|
+
pendingTarget;
|
|
15
|
+
mountHandler;
|
|
16
|
+
errorHandler;
|
|
12
17
|
empty = false;
|
|
13
18
|
get anchor() {
|
|
14
19
|
return this.node.anchor;
|
|
@@ -22,29 +27,83 @@ class RenderNode {
|
|
|
22
27
|
get boundary() {
|
|
23
28
|
return this.node.boundary;
|
|
24
29
|
}
|
|
30
|
+
setMountHandler(handler) {
|
|
31
|
+
this.mountHandler = handler;
|
|
32
|
+
}
|
|
33
|
+
setErrorHandler(handler) {
|
|
34
|
+
this.errorHandler = handler;
|
|
35
|
+
}
|
|
25
36
|
mount() {
|
|
26
37
|
var _a;
|
|
27
38
|
if (this.empty || !this.anchor.isConnected) {
|
|
28
39
|
return false;
|
|
29
40
|
}
|
|
41
|
+
const ready = (_a = this.options) == null ? void 0 : _a.ready;
|
|
42
|
+
const onError = this.errorHandler;
|
|
43
|
+
if (ready && !onError) {
|
|
44
|
+
throw new Error("Deferred content rendering requires an error handler before mount");
|
|
45
|
+
}
|
|
30
46
|
this.node.mount();
|
|
31
47
|
const target = this.target;
|
|
32
48
|
if (!target) {
|
|
33
49
|
return false;
|
|
34
50
|
}
|
|
35
|
-
if (target === this.renderedTarget) {
|
|
51
|
+
if (target === this.renderedTarget || target === this.pendingTarget) {
|
|
36
52
|
return false;
|
|
37
53
|
}
|
|
38
54
|
this.clear();
|
|
39
55
|
const generation = ++this.generation;
|
|
40
|
-
this.
|
|
56
|
+
this.pendingTarget = void 0;
|
|
41
57
|
const replacedAnchor = !this.anchor.isConnected;
|
|
58
|
+
if (ready && onError) {
|
|
59
|
+
const loading = ready();
|
|
60
|
+
this.pendingTarget = target;
|
|
61
|
+
void loading.then(
|
|
62
|
+
() => {
|
|
63
|
+
if (generation !== this.generation || target !== this.target) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
this.pendingTarget = void 0;
|
|
67
|
+
try {
|
|
68
|
+
this.completeRender(target, generation, replacedAnchor);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
onError(error);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
() => {
|
|
74
|
+
if (generation === this.generation) {
|
|
75
|
+
this.pendingTarget = void 0;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
return this.completeRender(target, generation, replacedAnchor);
|
|
82
|
+
}
|
|
83
|
+
completeRender(target, generation, replacedAnchor) {
|
|
84
|
+
var _a;
|
|
85
|
+
const rendered = this.renderTarget(target, generation, replacedAnchor);
|
|
86
|
+
if (rendered && generation === this.generation && target === this.target) {
|
|
87
|
+
(_a = this.mountHandler) == null ? void 0 : _a.call(this);
|
|
88
|
+
}
|
|
89
|
+
return rendered;
|
|
90
|
+
}
|
|
91
|
+
renderTarget(target, generation, replacedAnchor) {
|
|
92
|
+
var _a, _b;
|
|
93
|
+
if (generation !== this.generation || target !== this.target) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
if (!this.anchor.isConnected && !(replacedAnchor && ((_a = this.container) == null ? void 0 : _a.isConnected))) {
|
|
97
|
+
this.unmount();
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
this.renderedTarget = target;
|
|
42
101
|
try {
|
|
43
102
|
const value = this.resolve(this.props());
|
|
44
103
|
if (generation !== this.generation || target !== this.target) {
|
|
45
104
|
return false;
|
|
46
105
|
}
|
|
47
|
-
if (!this.anchor.isConnected && !(replacedAnchor && ((
|
|
106
|
+
if (!this.anchor.isConnected && !(replacedAnchor && ((_b = this.container) == null ? void 0 : _b.isConnected))) {
|
|
48
107
|
this.unmount();
|
|
49
108
|
return false;
|
|
50
109
|
}
|
|
@@ -65,8 +124,14 @@ class RenderNode {
|
|
|
65
124
|
unmount() {
|
|
66
125
|
this.generation++;
|
|
67
126
|
this.renderedTarget = void 0;
|
|
68
|
-
this.
|
|
69
|
-
|
|
127
|
+
this.pendingTarget = void 0;
|
|
128
|
+
let removed = false;
|
|
129
|
+
try {
|
|
130
|
+
this.clear();
|
|
131
|
+
} finally {
|
|
132
|
+
removed = !!this.node.unmount();
|
|
133
|
+
}
|
|
134
|
+
return removed;
|
|
70
135
|
}
|
|
71
136
|
}
|
|
72
137
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/entry/content/lifecycle/nodes/RenderNode.ts"],"sourcesContent":["import type {\n
|
|
1
|
+
{"version":3,"sources":["../../../../../src/entry/content/lifecycle/nodes/RenderNode.ts"],"sourcesContent":["import type {\n ContentScriptNode,\n ContentScriptBoundary,\n ContentScriptProps,\n ContentScriptRenderHandler,\n ContentScriptRenderValue,\n} from \"@typing/content\";\nimport type {ContentScriptRenderLifecycle, ContentScriptRenderOptions} from \"../types\";\n\n/** Runs the adapter only after mounting DOM and invalidates work when its target is replaced. */\nexport default abstract class RenderNode<Data = unknown> implements ContentScriptNode, ContentScriptRenderLifecycle {\n private generation = 0;\n private renderedTarget?: Element;\n private pendingTarget?: Element;\n private mountHandler?: () => void;\n private errorHandler?: (error: unknown) => void;\n private empty = false;\n\n constructor(\n protected readonly node: ContentScriptNode,\n private readonly resolve: ContentScriptRenderHandler<Data>,\n private readonly props: () => ContentScriptProps<Data>,\n private readonly options?: ContentScriptRenderOptions\n ) {}\n\n public get anchor(): Element {\n return this.node.anchor;\n }\n\n public get container(): Element | undefined {\n return this.node.container;\n }\n\n public get target(): Element | undefined {\n return this.node.target;\n }\n\n public get boundary(): ContentScriptBoundary {\n return this.node.boundary;\n }\n\n protected abstract render(value: ContentScriptRenderValue<Data> | undefined, target: Element): boolean;\n\n protected abstract clear(): void;\n\n public setMountHandler(handler: () => void): void {\n this.mountHandler = handler;\n }\n\n public setErrorHandler(handler: (error: unknown) => void): void {\n this.errorHandler = handler;\n }\n\n public mount(): boolean {\n if (this.empty || !this.anchor.isConnected) {\n return false;\n }\n\n const ready = this.options?.ready;\n const onError = this.errorHandler;\n\n if (ready && !onError) {\n throw new Error(\"Deferred content rendering requires an error handler before mount\");\n }\n\n this.node.mount();\n\n const target = this.target;\n\n if (!target) {\n return false;\n }\n\n if (target === this.renderedTarget || target === this.pendingTarget) {\n return false;\n }\n\n this.clear();\n\n const generation = ++this.generation;\n this.pendingTarget = undefined;\n\n const replacedAnchor = !this.anchor.isConnected;\n\n if (ready && onError) {\n const loading = ready();\n this.pendingTarget = target;\n\n void loading.then(\n () => {\n if (generation !== this.generation || target !== this.target) {\n return;\n }\n\n this.pendingTarget = undefined;\n\n try {\n this.completeRender(target, generation, replacedAnchor);\n } catch (error) {\n onError(error);\n }\n },\n () => {\n // The style runtime reports the failure. A later mount can retry this target.\n if (generation === this.generation) {\n this.pendingTarget = undefined;\n }\n }\n );\n\n return false;\n }\n\n return this.completeRender(target, generation, replacedAnchor);\n }\n\n private completeRender(target: Element, generation: number, replacedAnchor: boolean): boolean {\n const rendered = this.renderTarget(target, generation, replacedAnchor);\n\n if (rendered && generation === this.generation && target === this.target) {\n this.mountHandler?.();\n }\n\n return rendered;\n }\n\n private renderTarget(target: Element, generation: number, replacedAnchor: boolean): boolean {\n if (generation !== this.generation || target !== this.target) {\n return false;\n }\n\n if (!this.anchor.isConnected && !(replacedAnchor && this.container?.isConnected)) {\n this.unmount();\n\n return false;\n }\n\n // Prevent a render callback from recursively rendering into the same target.\n this.renderedTarget = target;\n\n try {\n const value = this.resolve(this.props());\n\n if (generation !== this.generation || target !== this.target) {\n return false;\n }\n\n // A synchronous custom mount (including append: Replace) can deliberately replace its anchor.\n if (!this.anchor.isConnected && !(replacedAnchor && this.container?.isConnected)) {\n this.unmount();\n\n return false;\n }\n\n if (!this.render(value, target)) {\n this.empty = true;\n this.node.unmount();\n\n return false;\n }\n\n return true;\n } catch (error) {\n if (generation !== this.generation) {\n return false;\n }\n\n this.unmount();\n\n throw error;\n }\n }\n\n public unmount(): boolean {\n this.generation++;\n this.renderedTarget = undefined;\n this.pendingTarget = undefined;\n\n let removed = false;\n\n try {\n this.clear();\n } finally {\n removed = !!this.node.unmount();\n }\n\n return removed;\n }\n}\n"],"mappings":"AAUA,MAAO,WAA6G;AAAA,EAQhH,YACuB,MACF,SACA,OACA,SACnB;AAJqB;AACF;AACA;AACA;AAAA,EAClB;AAAA,EAJoB;AAAA,EACF;AAAA,EACA;AAAA,EACA;AAAA,EAXb,aAAa;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ;AAAA,EAShB,IAAW,SAAkB;AACzB,WAAO,KAAK,KAAK;AAAA,EACrB;AAAA,EAEA,IAAW,YAAiC;AACxC,WAAO,KAAK,KAAK;AAAA,EACrB;AAAA,EAEA,IAAW,SAA8B;AACrC,WAAO,KAAK,KAAK;AAAA,EACrB;AAA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solationSetup.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ContentScriptNode, type ContentScriptShadowOptions } from "../../../../types/content/index.js";
|
|
3
3
|
export default class ShadowNode<Data = unknown> implements ContentScriptNode {
|
|
4
4
|
protected readonly node: ContentScriptNode;
|
|
5
5
|
private readonly options;
|
|
@@ -15,6 +15,7 @@ export default class ShadowNode<Data = unknown> implements ContentScriptNode {
|
|
|
15
15
|
get container(): Element | undefined;
|
|
16
16
|
get target(): Element | undefined;
|
|
17
17
|
get boundary(): ShadowRoot | undefined;
|
|
18
|
+
ready(): Promise<void>;
|
|
18
19
|
mount(): boolean;
|
|
19
20
|
private mountNode;
|
|
20
21
|
unmount(): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/entry/content/lifecycle/nodes/ShadowNode.ts"],"sourcesContent":["import type IsolationSetup from \"../IsolationSetup\";\n\nimport {getContentScriptStylesRuntime} from \"./isolated-styles\";\n\nimport {\n ContentScriptShadowMode,\n type ContentScriptShadowOptions,\n type ContentScriptStylesRuntime,\n type
|
|
1
|
+
{"version":3,"sources":["../../../../../src/entry/content/lifecycle/nodes/ShadowNode.ts"],"sourcesContent":["import type IsolationSetup from \"../IsolationSetup\";\n\nimport {getContentScriptStylesRuntime} from \"./isolated-styles\";\n\nimport {\n ContentScriptNode,\n ContentScriptShadowMode,\n type ContentScriptShadowOptions,\n type ContentScriptStylesRuntime,\n type ContentScriptBoundaryCleanup,\n} from \"@typing/content\";\n\nexport default class ShadowNode<Data = unknown> implements ContentScriptNode {\n private root?: ShadowRoot;\n\n private _target?: Element;\n\n private runtime?: ContentScriptStylesRuntime;\n private cleanupBoundary?: ContentScriptBoundaryCleanup;\n\n private mounting = false;\n private unmounting = false;\n\n public constructor(\n protected readonly node: ContentScriptNode,\n private readonly options: ContentScriptShadowOptions = {},\n private readonly isolation: IsolationSetup<Data, \"shadow\">\n ) {}\n\n public get anchor(): Element {\n return this.node.anchor;\n }\n\n public get container(): Element | undefined {\n return this.node.container;\n }\n\n public get target(): Element | undefined {\n return this._target;\n }\n\n public get boundary(): ShadowRoot | undefined {\n return this.root;\n }\n\n public ready(): Promise<void> {\n return this.root && this.runtime ? this.runtime.ready(this.root) : Promise.resolve();\n }\n\n public mount(): boolean {\n if (this.mounting || this.unmounting) {\n return false;\n }\n\n this.mounting = true;\n\n try {\n return this.mountNode();\n } finally {\n this.mounting = false;\n }\n }\n\n private mountNode(): boolean {\n const mounted = !!this.node.mount();\n\n if (!this.container || this.root) {\n return mounted;\n }\n\n if (!(\"attachShadow\" in this.container) || typeof this.container.attachShadow !== \"function\") {\n throw new Error(\"Content script container does not support Shadow DOM\");\n }\n\n if (this.container.shadowRoot) {\n throw new Error(\"Content script container already has an open ShadowRoot\");\n }\n\n let root: ShadowRoot;\n\n try {\n root = this.container.attachShadow({mode: this.options.mode ?? ContentScriptShadowMode.Open});\n } catch (cause) {\n // A pre-existing closed root is not observable through container.shadowRoot.\n throw new Error(\n \"Cannot attach ShadowRoot: the content script container may already have a root or not support Shadow DOM\",\n {cause}\n );\n }\n\n this.root = root;\n\n try {\n const cleanup = this.isolation.setup(root);\n\n if (this.root !== root) {\n cleanup?.();\n\n return false;\n }\n\n this.cleanupBoundary = cleanup || undefined;\n const target = this.isolation.createTarget(root, this.container.ownerDocument);\n\n if (this.root !== root) {\n return false;\n }\n\n root.appendChild(target);\n\n this._target = target;\n this.runtime = getContentScriptStylesRuntime();\n this.runtime.add(root, target);\n } catch (error) {\n if (this.root === root) {\n this.unmount();\n }\n\n throw error;\n }\n\n return mounted;\n }\n\n public unmount(): boolean {\n if (this.unmounting) {\n return false;\n }\n\n this.unmounting = true;\n this._target = undefined;\n\n const cleanup = this.cleanupBoundary;\n\n this.cleanupBoundary = undefined;\n\n let removed = false;\n\n try {\n try {\n cleanup?.();\n } finally {\n try {\n if (this.root) {\n this.runtime?.delete(this.root);\n }\n } finally {\n this.root = undefined;\n this._target = undefined;\n this.runtime = undefined;\n removed = !!this.node.unm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