@noldova/browser.protocol 0.0.0-stage → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +6 -2
- package/package.json +44 -4
- package/src/api/index.d.ts +1767 -0
- package/src/api/index.js +35 -0
- package/src/enums/address-kind.js +14 -0
- package/src/enums/page-action.js +15 -0
- package/src/enums/page-activity-state.js +12 -0
- package/src/enums/typed-address-answer-kind.js +11 -0
- package/src/enums/typed-address-refusal.js +15 -0
- package/src/models/address-kinds.js +62 -0
- package/src/models/browser-events.js +10 -0
- package/src/models/browser-methods.js +23 -0
- package/src/models/browser-tool-names.js +30 -0
- package/src/models/browsing-data-request.js +25 -0
- package/src/models/held-pages.js +29 -0
- package/src/models/local-sites.js +46 -0
- package/src/models/open-pages-request.js +25 -0
- package/src/models/page-activity.js +69 -0
- package/src/models/page-agent.js +27 -0
- package/src/models/page-box.js +43 -0
- package/src/models/page-change-script.js +53 -0
- package/src/models/page-claim.js +40 -0
- package/src/models/page-point.js +32 -0
- package/src/models/page-record.js +29 -0
- package/src/models/page-refusal.js +33 -0
- package/src/models/page-request.js +25 -0
- package/src/models/page-stop-request.js +27 -0
- package/src/models/typed-address-allowed.js +30 -0
- package/src/models/typed-address-refused.js +32 -0
- package/src/models/typed-address-request.js +27 -0
- package/src/models/typed-redirect-request.js +29 -0
- package/src/resources.js +73 -0
- package/src/services/typed-address-answer.reader.js +19 -0
- package/src/services/wire-contract.js +28 -0
- package/src/types/browser-tool-name.js +8 -0
- package/src/types/typed-address-answer.js +8 -0
package/src/api/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export { AddressKind } from "../enums/address-kind.js";
|
|
9
|
+
export { PageAction } from "../enums/page-action.js";
|
|
10
|
+
export { PageActivityState } from "../enums/page-activity-state.js";
|
|
11
|
+
export { TypedAddressAnswerKind } from "../enums/typed-address-answer-kind.js";
|
|
12
|
+
export { TypedAddressRefusal } from "../enums/typed-address-refusal.js";
|
|
13
|
+
export { AddressKinds } from "../models/address-kinds.js";
|
|
14
|
+
export { BrowserEvents } from "../models/browser-events.js";
|
|
15
|
+
export { BrowserMethods } from "../models/browser-methods.js";
|
|
16
|
+
export { BrowserToolNames } from "../models/browser-tool-names.js";
|
|
17
|
+
export { BrowsingDataRequest } from "../models/browsing-data-request.js";
|
|
18
|
+
export { HeldPages } from "../models/held-pages.js";
|
|
19
|
+
export { LocalSites } from "../models/local-sites.js";
|
|
20
|
+
export { OpenPagesRequest } from "../models/open-pages-request.js";
|
|
21
|
+
export { PageActivity } from "../models/page-activity.js";
|
|
22
|
+
export { PageAgent } from "../models/page-agent.js";
|
|
23
|
+
export { PageBox } from "../models/page-box.js";
|
|
24
|
+
export { PageChangeScript } from "../models/page-change-script.js";
|
|
25
|
+
export { PageClaim } from "../models/page-claim.js";
|
|
26
|
+
export { PagePoint } from "../models/page-point.js";
|
|
27
|
+
export { PageRecord } from "../models/page-record.js";
|
|
28
|
+
export { PageRefusal } from "../models/page-refusal.js";
|
|
29
|
+
export { PageRequest } from "../models/page-request.js";
|
|
30
|
+
export { PageStopRequest } from "../models/page-stop-request.js";
|
|
31
|
+
export { TypedAddressAllowed } from "../models/typed-address-allowed.js";
|
|
32
|
+
export { TypedAddressRefused } from "../models/typed-address-refused.js";
|
|
33
|
+
export { TypedAddressRequest } from "../models/typed-address-request.js";
|
|
34
|
+
export { TypedRedirectRequest } from "../models/typed-redirect-request.js";
|
|
35
|
+
export { TypedAddressAnswerReader } from "../services/typed-address-answer.reader.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export const AddressKind = {
|
|
9
|
+
Public: "Public",
|
|
10
|
+
Loopback: "Loopback",
|
|
11
|
+
Private: "Private",
|
|
12
|
+
LinkLocal: "LinkLocal",
|
|
13
|
+
Unspecified: "Unspecified"
|
|
14
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export const PageAction = {
|
|
9
|
+
Navigating: "Navigating",
|
|
10
|
+
Reading: "Reading",
|
|
11
|
+
Clicking: "Clicking",
|
|
12
|
+
Typing: "Typing",
|
|
13
|
+
PressingKey: "PressingKey",
|
|
14
|
+
Waiting: "Waiting"
|
|
15
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export const PageActivityState = {
|
|
9
|
+
Acting: "Acting",
|
|
10
|
+
Asking: "Asking",
|
|
11
|
+
Ended: "Ended"
|
|
12
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export const TypedAddressAnswerKind = {
|
|
9
|
+
Allowed: "Allowed",
|
|
10
|
+
Refused: "Refused"
|
|
11
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export const TypedAddressRefusal = {
|
|
9
|
+
NotAnAddress: "NotAnAddress",
|
|
10
|
+
NotWeb: "NotWeb",
|
|
11
|
+
TooLong: "TooLong",
|
|
12
|
+
Credentials: "Credentials",
|
|
13
|
+
Local: "Local",
|
|
14
|
+
NeverAllowed: "NeverAllowed"
|
|
15
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { AddressKind } from "../enums/address-kind.js";
|
|
9
|
+
import { Resources } from "../resources.js";
|
|
10
|
+
export class AddressKinds {
|
|
11
|
+
static ofHost(hostname) {
|
|
12
|
+
if (hostname.startsWith(Resources.ipv6Opening))
|
|
13
|
+
return AddressKinds.ofIpv6(AddressKinds.readIpv6(hostname.slice(1, -1)));
|
|
14
|
+
const host = hostname.replace(Resources.trailingDotsPattern, "");
|
|
15
|
+
if (AddressKinds.isIpv4(host))
|
|
16
|
+
return AddressKinds.ofIpv4(host.split(Resources.ipv4PartSeparator).reduce((value, t) => value * 256 + Number(t), 0));
|
|
17
|
+
return host === Resources.loopbackName || host.endsWith(Resources.loopbackSuffix) ? AddressKind.Loopback : AddressKind.Public;
|
|
18
|
+
}
|
|
19
|
+
static isIpv4(host) {
|
|
20
|
+
return Resources.ipv4Pattern.test(host) && host.split(Resources.ipv4PartSeparator).every(t => Number(t) <= Resources.ipv4PartMaximum);
|
|
21
|
+
}
|
|
22
|
+
static ofIpv4(address) {
|
|
23
|
+
const a = address >>> 24;
|
|
24
|
+
const b = (address >>> 16) & 0xff;
|
|
25
|
+
if (a === 0)
|
|
26
|
+
return AddressKind.Unspecified;
|
|
27
|
+
if (a === Resources.ipv4LoopbackNetwork)
|
|
28
|
+
return AddressKind.Loopback;
|
|
29
|
+
if (Resources.ipv4PrivateRanges.some(t => AddressKinds.isInRange(a, b, t)))
|
|
30
|
+
return AddressKind.Private;
|
|
31
|
+
if (AddressKinds.isInRange(a, b, Resources.ipv4LinkLocalRange))
|
|
32
|
+
return AddressKind.LinkLocal;
|
|
33
|
+
return AddressKind.Public;
|
|
34
|
+
}
|
|
35
|
+
static isInRange(a, b, range) {
|
|
36
|
+
return a === range[0] && b >= range[1] && b <= range[2];
|
|
37
|
+
}
|
|
38
|
+
static ofIpv6(address) {
|
|
39
|
+
if (address === 0n)
|
|
40
|
+
return AddressKind.Unspecified;
|
|
41
|
+
if (address === 1n)
|
|
42
|
+
return AddressKind.Loopback;
|
|
43
|
+
const prefix = address >> Resources.ipv4Bits;
|
|
44
|
+
if (prefix === Resources.mappedPrefix || prefix === 0n || prefix === Resources.nat64Prefix)
|
|
45
|
+
return AddressKinds.ofIpv4(Number(address & Resources.ipv4Mask));
|
|
46
|
+
if (address >> Resources.uniqueLocalShift === Resources.uniqueLocalPrefix)
|
|
47
|
+
return AddressKind.Private;
|
|
48
|
+
if (address >> Resources.linkLocalShift === Resources.linkLocalPrefix)
|
|
49
|
+
return AddressKind.LinkLocal;
|
|
50
|
+
return AddressKind.Public;
|
|
51
|
+
}
|
|
52
|
+
static readIpv6(address) {
|
|
53
|
+
const gap = address.indexOf(Resources.ipv6ZeroRun);
|
|
54
|
+
const head = AddressKinds.readPieces(gap < 0 ? address : address.slice(0, gap));
|
|
55
|
+
const tail = gap < 0 ? [] : AddressKinds.readPieces(address.slice(gap + Resources.ipv6ZeroRun.length));
|
|
56
|
+
const pieces = [...head, ...new Array(8 - head.length - tail.length).fill(0n), ...tail];
|
|
57
|
+
return pieces.reduce((value, t) => (value << 16n) | t, 0n);
|
|
58
|
+
}
|
|
59
|
+
static readPieces(text) {
|
|
60
|
+
return text === "" ? [] : text.split(Resources.ipv6PieceSeparator).map(t => BigInt(Resources.formatHexPiece(t)));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export class BrowserMethods {
|
|
9
|
+
static allowTypedAddress = "browser.allowTypedAddress";
|
|
10
|
+
static passTypedRedirect = "browser.passTypedRedirect";
|
|
11
|
+
static endTypedRedirects = "browser.endTypedRedirects";
|
|
12
|
+
static readyPage = "browser.readyPage";
|
|
13
|
+
static rememberPage = "browser.rememberPage";
|
|
14
|
+
static readPage = "browser.readPage";
|
|
15
|
+
static forgetPage = "browser.forgetPage";
|
|
16
|
+
static clearBrowsingData = "browser.clearBrowsingData";
|
|
17
|
+
static readAppName = "browser.readAppName";
|
|
18
|
+
static stopPage = "browser.stopPage";
|
|
19
|
+
static readActivities = "browser.readActivities";
|
|
20
|
+
static claimPage = "browser.claimPage";
|
|
21
|
+
static holdPages = "browser.holdPages";
|
|
22
|
+
static letGoPage = "browser.letGoPage";
|
|
23
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export class BrowserToolNames {
|
|
9
|
+
static navigate = "browser_navigate";
|
|
10
|
+
static snapshot = "browser_snapshot";
|
|
11
|
+
static click = "browser_click";
|
|
12
|
+
static type = "browser_type";
|
|
13
|
+
static pressKey = "browser_press_key";
|
|
14
|
+
static screenshot = "browser_screenshot";
|
|
15
|
+
static console = "browser_console";
|
|
16
|
+
static waitFor = "browser_wait_for";
|
|
17
|
+
static all = [
|
|
18
|
+
BrowserToolNames.navigate,
|
|
19
|
+
BrowserToolNames.snapshot,
|
|
20
|
+
BrowserToolNames.click,
|
|
21
|
+
BrowserToolNames.type,
|
|
22
|
+
BrowserToolNames.pressKey,
|
|
23
|
+
BrowserToolNames.screenshot,
|
|
24
|
+
BrowserToolNames.console,
|
|
25
|
+
BrowserToolNames.waitFor
|
|
26
|
+
];
|
|
27
|
+
static includes(value) {
|
|
28
|
+
return BrowserToolNames.all.some(t => t === value);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { JsonReader } from "@noldova/context.json";
|
|
9
|
+
import { Resources } from "../resources.js";
|
|
10
|
+
import { WireContract } from "../services/wire-contract.js";
|
|
11
|
+
export class BrowsingDataRequest {
|
|
12
|
+
static FIELDS = [Resources.profileKeyField];
|
|
13
|
+
profileKey;
|
|
14
|
+
constructor(profileKey) {
|
|
15
|
+
this.profileKey = profileKey;
|
|
16
|
+
}
|
|
17
|
+
static fromJson(value, path) {
|
|
18
|
+
const reader = JsonReader.fromValue(value, path);
|
|
19
|
+
WireContract.requireKnownFields(reader, BrowsingDataRequest.FIELDS);
|
|
20
|
+
return new BrowsingDataRequest(reader.readString(Resources.profileKeyField));
|
|
21
|
+
}
|
|
22
|
+
toJson() {
|
|
23
|
+
return { [Resources.profileKeyField]: this.profileKey };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { JsonReader } from "@noldova/context.json";
|
|
9
|
+
import { Resources } from "../resources.js";
|
|
10
|
+
import { WireContract } from "../services/wire-contract.js";
|
|
11
|
+
import { PageAgent } from "./page-agent.js";
|
|
12
|
+
export class HeldPages {
|
|
13
|
+
static FIELDS = [Resources.refusedField, Resources.agentsField];
|
|
14
|
+
refused;
|
|
15
|
+
agents;
|
|
16
|
+
constructor(refused, agents) {
|
|
17
|
+
this.refused = refused;
|
|
18
|
+
this.agents = agents;
|
|
19
|
+
}
|
|
20
|
+
static fromJson(value, path) {
|
|
21
|
+
const reader = JsonReader.fromValue(value, path);
|
|
22
|
+
WireContract.requireKnownFields(reader, HeldPages.FIELDS);
|
|
23
|
+
const refused = reader.readStringArray(Resources.refusedField);
|
|
24
|
+
return new HeldPages(refused, reader.readObjectArray(Resources.agentsField).map(t => PageAgent.fromJson(t.toJson(), t.path)));
|
|
25
|
+
}
|
|
26
|
+
toJson() {
|
|
27
|
+
return { [Resources.refusedField]: this.refused, [Resources.agentsField]: this.agents.map(t => t.toJson()) };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { AddressKind } from "../enums/address-kind.js";
|
|
9
|
+
import { Resources } from "../resources.js";
|
|
10
|
+
import { AddressKinds } from "./address-kinds.js";
|
|
11
|
+
export class LocalSites {
|
|
12
|
+
static LOCAL_KINDS = [AddressKind.Loopback, AddressKind.Private];
|
|
13
|
+
origins;
|
|
14
|
+
ignored;
|
|
15
|
+
ignoredEntries;
|
|
16
|
+
constructor(origins, ignored, ignoredEntries) {
|
|
17
|
+
this.origins = origins;
|
|
18
|
+
this.ignored = ignored;
|
|
19
|
+
this.ignoredEntries = ignoredEntries;
|
|
20
|
+
}
|
|
21
|
+
static read(text) {
|
|
22
|
+
const origins = [];
|
|
23
|
+
const ignored = [];
|
|
24
|
+
const ignoredEntries = [];
|
|
25
|
+
const entries = text.split(Resources.localSitesSeparator).map(t => t.trim()).filter(t => t !== "");
|
|
26
|
+
for (const [index, entry] of entries.entries()) {
|
|
27
|
+
const origin = LocalSites.originOf(entry);
|
|
28
|
+
if (origin === null) {
|
|
29
|
+
ignored.push(index + 1);
|
|
30
|
+
ignoredEntries.push(entry);
|
|
31
|
+
}
|
|
32
|
+
else if (!origins.includes(origin))
|
|
33
|
+
origins.push(origin);
|
|
34
|
+
}
|
|
35
|
+
return new LocalSites(origins, ignored, ignoredEntries);
|
|
36
|
+
}
|
|
37
|
+
static originOf(entry) {
|
|
38
|
+
const parsed = URL.parse(entry);
|
|
39
|
+
if (parsed === null || !Resources.webSchemes.includes(parsed.protocol) || parsed.username !== "" || parsed.password !== ""
|
|
40
|
+
|| parsed.href !== Resources.formatOriginRoot(parsed.origin))
|
|
41
|
+
return null;
|
|
42
|
+
if (Resources.wildcardPattern.test(entry + parsed.hostname) || Resources.emptyLabelPattern.test(parsed.hostname))
|
|
43
|
+
return null;
|
|
44
|
+
return LocalSites.LOCAL_KINDS.includes(AddressKinds.ofHost(parsed.hostname)) ? parsed.origin : null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { JsonReader } from "@noldova/context.json";
|
|
9
|
+
import { Resources } from "../resources.js";
|
|
10
|
+
import { WireContract } from "../services/wire-contract.js";
|
|
11
|
+
export class OpenPagesRequest {
|
|
12
|
+
static FIELDS = [Resources.instancesField];
|
|
13
|
+
instances;
|
|
14
|
+
constructor(instances) {
|
|
15
|
+
this.instances = instances;
|
|
16
|
+
}
|
|
17
|
+
static fromJson(value, path) {
|
|
18
|
+
const reader = JsonReader.fromValue(value, path);
|
|
19
|
+
WireContract.requireKnownFields(reader, OpenPagesRequest.FIELDS);
|
|
20
|
+
return new OpenPagesRequest(reader.readStringArray(Resources.instancesField));
|
|
21
|
+
}
|
|
22
|
+
toJson() {
|
|
23
|
+
return { [Resources.instancesField]: this.instances };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { JsonReader } from "@noldova/context.json";
|
|
9
|
+
import { PageAction } from "../enums/page-action.js";
|
|
10
|
+
import { PageActivityState } from "../enums/page-activity-state.js";
|
|
11
|
+
import { Resources } from "../resources.js";
|
|
12
|
+
import { WireContract } from "../services/wire-contract.js";
|
|
13
|
+
import { PageBox } from "./page-box.js";
|
|
14
|
+
import { PagePoint } from "./page-point.js";
|
|
15
|
+
import { PageRefusal } from "./page-refusal.js";
|
|
16
|
+
export class PageActivity {
|
|
17
|
+
static FIELDS = [
|
|
18
|
+
Resources.instanceField, Resources.activityField, Resources.agentNameField, Resources.actionField, Resources.stateField, Resources.boxField, Resources.pointField,
|
|
19
|
+
Resources.refusalField, Resources.isHandedOverField
|
|
20
|
+
];
|
|
21
|
+
static ACTIONS = Object.values(PageAction);
|
|
22
|
+
static STATES = Object.values(PageActivityState);
|
|
23
|
+
instance;
|
|
24
|
+
activity;
|
|
25
|
+
agentName;
|
|
26
|
+
action;
|
|
27
|
+
state;
|
|
28
|
+
box;
|
|
29
|
+
point;
|
|
30
|
+
refusal;
|
|
31
|
+
isHandedOver;
|
|
32
|
+
constructor(instance, activity, agentName, action, state, box, point, refusal, isHandedOver) {
|
|
33
|
+
this.instance = instance;
|
|
34
|
+
this.activity = activity;
|
|
35
|
+
this.agentName = agentName;
|
|
36
|
+
this.action = action;
|
|
37
|
+
this.state = state;
|
|
38
|
+
this.box = box;
|
|
39
|
+
this.point = point;
|
|
40
|
+
this.refusal = refusal;
|
|
41
|
+
this.isHandedOver = isHandedOver;
|
|
42
|
+
}
|
|
43
|
+
static fromJson(value, path) {
|
|
44
|
+
const reader = JsonReader.fromValue(value, path);
|
|
45
|
+
WireContract.requireKnownFields(reader, PageActivity.FIELDS);
|
|
46
|
+
const instance = reader.readString(Resources.instanceField);
|
|
47
|
+
const activity = reader.readString(Resources.activityField);
|
|
48
|
+
const agentName = reader.readString(Resources.agentNameField);
|
|
49
|
+
const action = reader.readOneOf(Resources.actionField, PageActivity.ACTIONS);
|
|
50
|
+
const state = reader.readOneOf(Resources.stateField, PageActivity.STATES);
|
|
51
|
+
const box = reader.readNullableObject(Resources.boxField);
|
|
52
|
+
const point = reader.readNullableObject(Resources.pointField);
|
|
53
|
+
const refusal = reader.readNullableObject(Resources.refusalField);
|
|
54
|
+
return new PageActivity(instance, activity, agentName, action, state, box === null ? null : PageBox.fromJson(box.toJson(), box.path), point === null ? null : PagePoint.fromJson(point.toJson(), point.path), refusal === null ? null : PageRefusal.fromJson(refusal.toJson(), refusal.path), reader.readBoolean(Resources.isHandedOverField));
|
|
55
|
+
}
|
|
56
|
+
toJson() {
|
|
57
|
+
return {
|
|
58
|
+
[Resources.instanceField]: this.instance,
|
|
59
|
+
[Resources.activityField]: this.activity,
|
|
60
|
+
[Resources.agentNameField]: this.agentName,
|
|
61
|
+
[Resources.actionField]: this.action,
|
|
62
|
+
[Resources.stateField]: this.state,
|
|
63
|
+
[Resources.boxField]: this.box === null ? null : this.box.toJson(),
|
|
64
|
+
[Resources.pointField]: this.point === null ? null : this.point.toJson(),
|
|
65
|
+
[Resources.refusalField]: this.refusal === null ? null : this.refusal.toJson(),
|
|
66
|
+
[Resources.isHandedOverField]: this.isHandedOver
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { JsonReader } from "@noldova/context.json";
|
|
9
|
+
import { Resources } from "../resources.js";
|
|
10
|
+
import { WireContract } from "../services/wire-contract.js";
|
|
11
|
+
export class PageAgent {
|
|
12
|
+
static FIELDS = [Resources.instanceField, Resources.agentNameField];
|
|
13
|
+
instance;
|
|
14
|
+
agentName;
|
|
15
|
+
constructor(instance, agentName) {
|
|
16
|
+
this.instance = instance;
|
|
17
|
+
this.agentName = agentName;
|
|
18
|
+
}
|
|
19
|
+
static fromJson(value, path) {
|
|
20
|
+
const reader = JsonReader.fromValue(value, path);
|
|
21
|
+
WireContract.requireKnownFields(reader, PageAgent.FIELDS);
|
|
22
|
+
return new PageAgent(reader.readString(Resources.instanceField), reader.readString(Resources.agentNameField));
|
|
23
|
+
}
|
|
24
|
+
toJson() {
|
|
25
|
+
return { [Resources.instanceField]: this.instance, [Resources.agentNameField]: this.agentName };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { ArgumentException } from "@noldova/context.exceptions";
|
|
9
|
+
import { JsonReader } from "@noldova/context.json";
|
|
10
|
+
import { Resources } from "../resources.js";
|
|
11
|
+
import { WireContract } from "../services/wire-contract.js";
|
|
12
|
+
export class PageBox {
|
|
13
|
+
static FIELDS = [Resources.xField, Resources.yField, Resources.widthField, Resources.heightField];
|
|
14
|
+
x;
|
|
15
|
+
y;
|
|
16
|
+
width;
|
|
17
|
+
height;
|
|
18
|
+
constructor(x, y, width, height) {
|
|
19
|
+
if (!Number.isFinite(x))
|
|
20
|
+
throw new ArgumentException(Resources.coordinateNotFinite, Resources.xField);
|
|
21
|
+
if (!Number.isFinite(y))
|
|
22
|
+
throw new ArgumentException(Resources.coordinateNotFinite, Resources.yField);
|
|
23
|
+
if (!Number.isFinite(width) || width < 0)
|
|
24
|
+
throw new ArgumentException(Resources.sizeNegative, Resources.widthField);
|
|
25
|
+
if (!Number.isFinite(height) || height < 0)
|
|
26
|
+
throw new ArgumentException(Resources.sizeNegative, Resources.heightField);
|
|
27
|
+
this.x = x;
|
|
28
|
+
this.y = y;
|
|
29
|
+
this.width = width;
|
|
30
|
+
this.height = height;
|
|
31
|
+
}
|
|
32
|
+
static fromJson(value, path) {
|
|
33
|
+
const reader = JsonReader.fromValue(value, path);
|
|
34
|
+
WireContract.requireKnownFields(reader, PageBox.FIELDS);
|
|
35
|
+
return WireContract.create(reader, () => new PageBox(reader.readNumber(Resources.xField), reader.readNumber(Resources.yField), reader.readNumber(Resources.widthField), reader.readNumber(Resources.heightField)));
|
|
36
|
+
}
|
|
37
|
+
isSame(box) {
|
|
38
|
+
return box.x === this.x && box.y === this.y && box.width === this.width && box.height === this.height;
|
|
39
|
+
}
|
|
40
|
+
toJson() {
|
|
41
|
+
return { [Resources.xField]: this.x, [Resources.yField]: this.y, [Resources.widthField]: this.width, [Resources.heightField]: this.height };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export class PageChangeScript {
|
|
9
|
+
static worldName = "noldova-browser-changes";
|
|
10
|
+
static bindingName = "noldovaBrowserChanged";
|
|
11
|
+
static functionDeclaration = `function (isOn) {
|
|
12
|
+
const key = "noldovaBrowserChanges";
|
|
13
|
+
const report = globalThis.noldovaBrowserChanged;
|
|
14
|
+
if (typeof isOn !== "boolean" || typeof report !== "function")
|
|
15
|
+
return false;
|
|
16
|
+
let state = globalThis[key];
|
|
17
|
+
if (state === undefined) {
|
|
18
|
+
state = { isPending: false, stop: null };
|
|
19
|
+
globalThis[key] = state;
|
|
20
|
+
}
|
|
21
|
+
if (!isOn && state.stop !== null) {
|
|
22
|
+
state.stop();
|
|
23
|
+
state.stop = null;
|
|
24
|
+
}
|
|
25
|
+
if (!isOn || state.stop !== null)
|
|
26
|
+
return true;
|
|
27
|
+
const changed = () => {
|
|
28
|
+
if (state.isPending)
|
|
29
|
+
return;
|
|
30
|
+
state.isPending = true;
|
|
31
|
+
requestAnimationFrame(() => {
|
|
32
|
+
state.isPending = false;
|
|
33
|
+
if (state.stop !== null)
|
|
34
|
+
report("");
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
const options = { capture: true, passive: true };
|
|
38
|
+
const targets = [[document, ["scroll", "load", "transitionend", "animationend"]], [window, ["resize"]], [visualViewport, ["resize", "scroll"]],
|
|
39
|
+
[document.fonts, ["loadingdone"]]];
|
|
40
|
+
for (const [target, names] of targets)
|
|
41
|
+
for (const name of names)
|
|
42
|
+
target.addEventListener(name, changed, options);
|
|
43
|
+
const observer = new MutationObserver(changed);
|
|
44
|
+
observer.observe(document, { childList: true, subtree: true, attributes: true, characterData: true });
|
|
45
|
+
state.stop = () => {
|
|
46
|
+
observer.disconnect();
|
|
47
|
+
for (const [target, names] of targets)
|
|
48
|
+
for (const name of names)
|
|
49
|
+
target.removeEventListener(name, changed, options);
|
|
50
|
+
};
|
|
51
|
+
return true;
|
|
52
|
+
}`;
|
|
53
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { JsonReader } from "@noldova/context.json";
|
|
9
|
+
import { Resources } from "../resources.js";
|
|
10
|
+
import { WireContract } from "../services/wire-contract.js";
|
|
11
|
+
import { PageRecord } from "./page-record.js";
|
|
12
|
+
export class PageClaim {
|
|
13
|
+
static FIELDS = [Resources.isClaimedField, Resources.isHereField, Resources.recordField, Resources.agentNameField];
|
|
14
|
+
isClaimed;
|
|
15
|
+
isHere;
|
|
16
|
+
record;
|
|
17
|
+
agentName;
|
|
18
|
+
constructor(isClaimed, isHere, record, agentName) {
|
|
19
|
+
this.isClaimed = isClaimed;
|
|
20
|
+
this.isHere = isHere;
|
|
21
|
+
this.record = record;
|
|
22
|
+
this.agentName = agentName;
|
|
23
|
+
}
|
|
24
|
+
static fromJson(value, path) {
|
|
25
|
+
const reader = JsonReader.fromValue(value, path);
|
|
26
|
+
WireContract.requireKnownFields(reader, PageClaim.FIELDS);
|
|
27
|
+
const isClaimed = reader.readBoolean(Resources.isClaimedField);
|
|
28
|
+
const isHere = reader.readBoolean(Resources.isHereField);
|
|
29
|
+
const record = reader.readNullableObject(Resources.recordField);
|
|
30
|
+
return new PageClaim(isClaimed, isHere, record === null ? null : PageRecord.fromJson(record.toJson(), record.path), reader.readNullableString(Resources.agentNameField));
|
|
31
|
+
}
|
|
32
|
+
toJson() {
|
|
33
|
+
return {
|
|
34
|
+
[Resources.isClaimedField]: this.isClaimed,
|
|
35
|
+
[Resources.isHereField]: this.isHere,
|
|
36
|
+
[Resources.recordField]: this.record === null ? null : this.record.toJson(),
|
|
37
|
+
[Resources.agentNameField]: this.agentName
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { ArgumentException } from "@noldova/context.exceptions";
|
|
9
|
+
import { JsonReader } from "@noldova/context.json";
|
|
10
|
+
import { Resources } from "../resources.js";
|
|
11
|
+
import { WireContract } from "../services/wire-contract.js";
|
|
12
|
+
export class PagePoint {
|
|
13
|
+
static FIELDS = [Resources.xField, Resources.yField];
|
|
14
|
+
x;
|
|
15
|
+
y;
|
|
16
|
+
constructor(x, y) {
|
|
17
|
+
if (!Number.isFinite(x))
|
|
18
|
+
throw new ArgumentException(Resources.coordinateNotFinite, Resources.xField);
|
|
19
|
+
if (!Number.isFinite(y))
|
|
20
|
+
throw new ArgumentException(Resources.coordinateNotFinite, Resources.yField);
|
|
21
|
+
this.x = x;
|
|
22
|
+
this.y = y;
|
|
23
|
+
}
|
|
24
|
+
static fromJson(value, path) {
|
|
25
|
+
const reader = JsonReader.fromValue(value, path);
|
|
26
|
+
WireContract.requireKnownFields(reader, PagePoint.FIELDS);
|
|
27
|
+
return WireContract.create(reader, () => new PagePoint(reader.readNumber(Resources.xField), reader.readNumber(Resources.yField)));
|
|
28
|
+
}
|
|
29
|
+
toJson() {
|
|
30
|
+
return { [Resources.xField]: this.x, [Resources.yField]: this.y };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { JsonReader } from "@noldova/context.json";
|
|
9
|
+
import { Resources } from "../resources.js";
|
|
10
|
+
import { WireContract } from "../services/wire-contract.js";
|
|
11
|
+
export class PageRecord {
|
|
12
|
+
static FIELDS = [Resources.instanceField, Resources.profileKeyField, Resources.urlField];
|
|
13
|
+
instance;
|
|
14
|
+
profileKey;
|
|
15
|
+
url;
|
|
16
|
+
constructor(instance, profileKey, url) {
|
|
17
|
+
this.instance = instance;
|
|
18
|
+
this.profileKey = profileKey;
|
|
19
|
+
this.url = url;
|
|
20
|
+
}
|
|
21
|
+
static fromJson(value, path) {
|
|
22
|
+
const reader = JsonReader.fromValue(value, path);
|
|
23
|
+
WireContract.requireKnownFields(reader, PageRecord.FIELDS);
|
|
24
|
+
return new PageRecord(reader.readString(Resources.instanceField), reader.readString(Resources.profileKeyField), reader.readString(Resources.urlField));
|
|
25
|
+
}
|
|
26
|
+
toJson() {
|
|
27
|
+
return { [Resources.instanceField]: this.instance, [Resources.profileKeyField]: this.profileKey, [Resources.urlField]: this.url };
|
|
28
|
+
}
|
|
29
|
+
}
|