@chat-de-hp/site 0.2.5 → 0.2.6
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/runtime/annotation-capture.js +14 -16
- package/dist/runtime/capture-contract.d.ts +4 -0
- package/dist/runtime/capture-contract.d.ts.map +1 -1
- package/dist/runtime/capture-contract.js +3 -1
- package/dist/runtime/capture-viewport.d.ts +4 -0
- package/dist/runtime/capture-viewport.d.ts.map +1 -0
- package/dist/runtime/capture-viewport.js +39 -0
- package/package.json +1 -1
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { isExpectedSiteCaptureParentMessage, SITE_CAPTURE_BOOT_NONCE_PARAM, SITE_CAPTURE_BOOT_PAGE_HASH_PARAM, SITE_CAPTURE_BOOT_PARENT_ORIGIN_PARAM, SITE_CAPTURE_MESSAGE_TYPE, SITE_CAPTURE_PARENT_ORIGIN_COOKIE, SITE_CAPTURE_SESSION_STORAGE_KEY, } from "./capture-contract.js";
|
|
2
|
+
import { freezeCaptureViewport } from "./capture-viewport.js";
|
|
2
3
|
import { SITE_ANNOTATION_END_PARAM } from "./contracts.js";
|
|
3
4
|
import { extractElements } from "./element-extractor.js";
|
|
4
5
|
let captureFrozen = false;
|
|
5
6
|
let endSessionPromise = null;
|
|
7
|
+
let resumeViewport = null;
|
|
6
8
|
function startAnnotationCapture() {
|
|
7
9
|
if (window.parent === window) {
|
|
8
10
|
return;
|
|
@@ -23,13 +25,24 @@ function startAnnotationCapture() {
|
|
|
23
25
|
void endAnnotationSession(session, true);
|
|
24
26
|
return;
|
|
25
27
|
}
|
|
28
|
+
if (event.data.type === SITE_CAPTURE_MESSAGE_TYPE.resume) {
|
|
29
|
+
resumeViewport?.();
|
|
30
|
+
resumeViewport = null;
|
|
31
|
+
captureFrozen = false;
|
|
32
|
+
postToParent(session, {
|
|
33
|
+
nonce: session.nonce,
|
|
34
|
+
pagePath: currentPagePath(),
|
|
35
|
+
type: SITE_CAPTURE_MESSAGE_TYPE.ready,
|
|
36
|
+
});
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
26
39
|
if (captureFrozen) {
|
|
27
40
|
return;
|
|
28
41
|
}
|
|
29
42
|
try {
|
|
30
43
|
const root = document.body ?? document.documentElement;
|
|
31
44
|
const elements = extractElements(root);
|
|
32
|
-
|
|
45
|
+
resumeViewport = freezeCaptureViewport();
|
|
33
46
|
captureFrozen = true;
|
|
34
47
|
postToParent(session, {
|
|
35
48
|
elements,
|
|
@@ -37,7 +50,6 @@ function startAnnotationCapture() {
|
|
|
37
50
|
pagePath: currentPagePath(),
|
|
38
51
|
type: SITE_CAPTURE_MESSAGE_TYPE.captured,
|
|
39
52
|
});
|
|
40
|
-
void endAnnotationSession(session, false);
|
|
41
53
|
}
|
|
42
54
|
catch {
|
|
43
55
|
postToParent(session, {
|
|
@@ -145,20 +157,6 @@ function readAllowedParentOrigin() {
|
|
|
145
157
|
function currentPagePath() {
|
|
146
158
|
return `${window.location.pathname}${window.location.search}${window.location.hash}`;
|
|
147
159
|
}
|
|
148
|
-
function freezeViewport() {
|
|
149
|
-
const { body, documentElement } = document;
|
|
150
|
-
const scrollX = window.scrollX;
|
|
151
|
-
const scrollY = window.scrollY;
|
|
152
|
-
documentElement.style.overflow = "hidden";
|
|
153
|
-
documentElement.style.touchAction = "none";
|
|
154
|
-
body.style.position = "fixed";
|
|
155
|
-
body.style.top = `-${scrollY}px`;
|
|
156
|
-
body.style.left = `-${scrollX}px`;
|
|
157
|
-
body.style.width = "100%";
|
|
158
|
-
body.style.overflow = "hidden";
|
|
159
|
-
body.style.pointerEvents = "none";
|
|
160
|
-
body.style.touchAction = "none";
|
|
161
|
-
}
|
|
162
160
|
function endAnnotationSession(session, notifyParent) {
|
|
163
161
|
if (endSessionPromise) {
|
|
164
162
|
return endSessionPromise;
|
|
@@ -11,6 +11,7 @@ export declare const SITE_CAPTURE_MESSAGE_TYPE: {
|
|
|
11
11
|
readonly ended: "chat-de-hp:capture-ended";
|
|
12
12
|
readonly error: "chat-de-hp:capture-error";
|
|
13
13
|
readonly ready: "chat-de-hp:capture-ready";
|
|
14
|
+
readonly resume: "chat-de-hp:resume-capture";
|
|
14
15
|
};
|
|
15
16
|
export type SiteCaptureParentMessage = {
|
|
16
17
|
nonce: string;
|
|
@@ -18,6 +19,9 @@ export type SiteCaptureParentMessage = {
|
|
|
18
19
|
} | {
|
|
19
20
|
nonce: string;
|
|
20
21
|
type: typeof SITE_CAPTURE_MESSAGE_TYPE.end;
|
|
22
|
+
} | {
|
|
23
|
+
nonce: string;
|
|
24
|
+
type: typeof SITE_CAPTURE_MESSAGE_TYPE.resume;
|
|
21
25
|
};
|
|
22
26
|
export type SiteCaptureFrameMessage = {
|
|
23
27
|
nonce: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capture-contract.d.ts","sourceRoot":"","sources":["../../src/runtime/capture-contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,eAAO,MAAM,6BAA6B,yBAAyB,CAAC;AACpE,eAAO,MAAM,qCAAqC,gCACnB,CAAC;AAChC,eAAO,MAAM,iCAAiC,mCACZ,CAAC;AACnC,eAAO,MAAM,iCAAiC,wCACP,CAAC;AACxC,eAAO,MAAM,gCAAgC,+BAA+B,CAAC;AAE7E,eAAO,MAAM,yBAAyB
|
|
1
|
+
{"version":3,"file":"capture-contract.d.ts","sourceRoot":"","sources":["../../src/runtime/capture-contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,eAAO,MAAM,6BAA6B,yBAAyB,CAAC;AACpE,eAAO,MAAM,qCAAqC,gCACnB,CAAC;AAChC,eAAO,MAAM,iCAAiC,mCACZ,CAAC;AACnC,eAAO,MAAM,iCAAiC,wCACP,CAAC;AACxC,eAAO,MAAM,gCAAgC,+BAA+B,CAAC;AAE7E,eAAO,MAAM,y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,IAAI,EAAE,wBAAwB,CAAA;CAAE,CAOnE;AAED,wBAAgB,iCAAiC,CAC/C,KAAK,EAAE,mBAAmB,EAC1B,QAAQ,EAAE,yBAAyB,GAClC,KAAK,IAAI,mBAAmB,GAAG;IAAE,IAAI,EAAE,uBAAuB,CAAA;CAAE,CAOlE;AAED,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,wBAAwB,CASnC;AAED,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,uBAAuB,CAmBlC"}
|
|
@@ -10,6 +10,7 @@ export const SITE_CAPTURE_MESSAGE_TYPE = {
|
|
|
10
10
|
ended: "chat-de-hp:capture-ended",
|
|
11
11
|
error: "chat-de-hp:capture-error",
|
|
12
12
|
ready: "chat-de-hp:capture-ready",
|
|
13
|
+
resume: "chat-de-hp:resume-capture",
|
|
13
14
|
};
|
|
14
15
|
export function isExpectedSiteCaptureParentMessage(event, expected) {
|
|
15
16
|
return (event.origin === expected.origin &&
|
|
@@ -28,7 +29,8 @@ export function isSiteCaptureParentMessage(value) {
|
|
|
28
29
|
return false;
|
|
29
30
|
}
|
|
30
31
|
return (value.type === SITE_CAPTURE_MESSAGE_TYPE.capture ||
|
|
31
|
-
value.type === SITE_CAPTURE_MESSAGE_TYPE.end
|
|
32
|
+
value.type === SITE_CAPTURE_MESSAGE_TYPE.end ||
|
|
33
|
+
value.type === SITE_CAPTURE_MESSAGE_TYPE.resume);
|
|
32
34
|
}
|
|
33
35
|
export function isSiteCaptureFrameMessage(value) {
|
|
34
36
|
if (!isRecord(value) || !isNonce(value.nonce)) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capture-viewport.d.ts","sourceRoot":"","sources":["../../src/runtime/capture-viewport.ts"],"names":[],"mappings":"AAAA,KAAK,qBAAqB,GAAG,IAAI,CAC/B,MAAM,EACN,UAAU,GAAG,UAAU,GAAG,SAAS,GAAG,SAAS,CAChD,CAAC;AAEF,wBAAgB,qBAAqB,CACnC,YAAY,GAAE,qBAA8B,cAyC7C"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export function freezeCaptureViewport(targetWindow = window) {
|
|
2
|
+
const { body, documentElement } = targetWindow.document;
|
|
3
|
+
const scrollX = targetWindow.scrollX;
|
|
4
|
+
const scrollY = targetWindow.scrollY;
|
|
5
|
+
const documentStyles = {
|
|
6
|
+
overflow: documentElement.style.overflow,
|
|
7
|
+
touchAction: documentElement.style.touchAction,
|
|
8
|
+
};
|
|
9
|
+
const bodyStyles = {
|
|
10
|
+
left: body.style.left,
|
|
11
|
+
overflow: body.style.overflow,
|
|
12
|
+
pointerEvents: body.style.pointerEvents,
|
|
13
|
+
position: body.style.position,
|
|
14
|
+
top: body.style.top,
|
|
15
|
+
touchAction: body.style.touchAction,
|
|
16
|
+
width: body.style.width,
|
|
17
|
+
};
|
|
18
|
+
documentElement.style.overflow = "hidden";
|
|
19
|
+
documentElement.style.touchAction = "none";
|
|
20
|
+
body.style.position = "fixed";
|
|
21
|
+
body.style.top = `-${scrollY}px`;
|
|
22
|
+
body.style.left = `-${scrollX}px`;
|
|
23
|
+
body.style.width = "100%";
|
|
24
|
+
body.style.overflow = "hidden";
|
|
25
|
+
body.style.pointerEvents = "none";
|
|
26
|
+
body.style.touchAction = "none";
|
|
27
|
+
return () => {
|
|
28
|
+
documentElement.style.overflow = documentStyles.overflow;
|
|
29
|
+
documentElement.style.touchAction = documentStyles.touchAction;
|
|
30
|
+
body.style.left = bodyStyles.left;
|
|
31
|
+
body.style.overflow = bodyStyles.overflow;
|
|
32
|
+
body.style.pointerEvents = bodyStyles.pointerEvents;
|
|
33
|
+
body.style.position = bodyStyles.position;
|
|
34
|
+
body.style.top = bodyStyles.top;
|
|
35
|
+
body.style.touchAction = bodyStyles.touchAction;
|
|
36
|
+
body.style.width = bodyStyles.width;
|
|
37
|
+
targetWindow.scrollTo(scrollX, scrollY);
|
|
38
|
+
};
|
|
39
|
+
}
|