@chat-de-hp/site 0.2.5 → 0.2.7
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/astro.js +2 -2
- package/dist/emdash-annotation.d.ts.map +1 -1
- package/dist/emdash-annotation.js +1 -5
- package/dist/internal/annotation-integration.d.ts +1 -1
- package/dist/internal/annotation-integration.d.ts.map +1 -1
- package/dist/internal/annotation-integration.js +3 -7
- package/dist/runtime/annotation-capture.d.ts +1 -1
- package/dist/runtime/annotation-capture.d.ts.map +1 -1
- package/dist/runtime/annotation-capture.js +78 -107
- package/dist/runtime/capture-contract.d.ts +13 -9
- package/dist/runtime/capture-contract.d.ts.map +1 -1
- package/dist/runtime/capture-contract.js +25 -13
- 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/dist/runtime/contracts.d.ts +0 -2
- package/dist/runtime/contracts.d.ts.map +1 -1
- package/dist/runtime/contracts.js +1 -2
- package/dist/runtime/index.d.ts +0 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +0 -1
- package/package.json +1 -5
package/dist/astro.js
CHANGED
|
@@ -3,7 +3,7 @@ import react from "@astrojs/react";
|
|
|
3
3
|
import { d1, r2 } from "@emdash-cms/cloudflare";
|
|
4
4
|
import { defineConfig } from "astro/config";
|
|
5
5
|
import emdash from "emdash/astro";
|
|
6
|
-
import {
|
|
6
|
+
import { createPublicAnnotationsIntegration } from "./internal/annotation-integration.js";
|
|
7
7
|
import { createApprovedAstroPlugins } from "./internal/astro-plugins.js";
|
|
8
8
|
import { resolveSiteDefinition } from "./internal/registry.js";
|
|
9
9
|
const SITE_ASTRO_OPTION_KEYS = [
|
|
@@ -53,7 +53,7 @@ export function createChatDeHpAstroConfig(site, options = {}) {
|
|
|
53
53
|
plugins: plugins,
|
|
54
54
|
storage: r2({ binding: "MEDIA" }),
|
|
55
55
|
}),
|
|
56
|
-
|
|
56
|
+
createPublicAnnotationsIntegration(),
|
|
57
57
|
],
|
|
58
58
|
output: "server",
|
|
59
59
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emdash-annotation.d.ts","sourceRoot":"","sources":["../src/emdash-annotation.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAEhB,WAAW,EACX,mBAAmB,EACpB,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"emdash-annotation.d.ts","sourceRoot":"","sources":["../src/emdash-annotation.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAEhB,WAAW,EACX,mBAAmB,EACpB,MAAM,QAAQ,CAAC;AAGhB,cAAc,QAAQ,CAAC;AAEvB,wBAAsB,mBAAmB,CACvC,CAAC,SAAS,MAAM,EAChB,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,EAC1B,IAAI,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAMlE;AAED,wBAAsB,cAAc,CAClC,CAAC,SAAS,MAAM,EAChB,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,EAC1B,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAU7E"}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { createEditable, getEmDashCollection as getPublishedEmDashCollection, getEmDashEntry as getPublishedEmDashEntry, } from "emdash";
|
|
2
|
-
import { isAnnotationMode } from "./internal/annotation-context.js";
|
|
3
2
|
// oxlint-disable-next-line no-barrel-file -- this compatibility module preserves the existing EmDash API while overriding only its two content queries
|
|
4
3
|
export * from "emdash";
|
|
5
4
|
export async function getEmDashCollection(type, filter) {
|
|
6
5
|
const result = await getPublishedEmDashCollection(type, filter);
|
|
7
|
-
if (!isAnnotationMode()) {
|
|
8
|
-
return result;
|
|
9
|
-
}
|
|
10
6
|
return {
|
|
11
7
|
...result,
|
|
12
8
|
entries: result.entries.map((entry) => annotateEntry(type, entry)),
|
|
@@ -14,7 +10,7 @@ export async function getEmDashCollection(type, filter) {
|
|
|
14
10
|
}
|
|
15
11
|
export async function getEmDashEntry(type, id, options) {
|
|
16
12
|
const result = await getPublishedEmDashEntry(type, id, options);
|
|
17
|
-
if (!
|
|
13
|
+
if (!result.entry) {
|
|
18
14
|
return result;
|
|
19
15
|
}
|
|
20
16
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"annotation-integration.d.ts","sourceRoot":"","sources":["../../src/internal/annotation-integration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAK9C,wBAAgB
|
|
1
|
+
{"version":3,"file":"annotation-integration.d.ts","sourceRoot":"","sources":["../../src/internal/annotation-integration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAK9C,wBAAgB,kCAAkC,IAAI,gBAAgB,CAiBrE"}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
const ANNOTATION_INTEGRATION_NAME = "@chat-de-hp/site/
|
|
2
|
-
export function
|
|
1
|
+
const ANNOTATION_INTEGRATION_NAME = "@chat-de-hp/site/public-annotations";
|
|
2
|
+
export function createPublicAnnotationsIntegration() {
|
|
3
3
|
return {
|
|
4
4
|
hooks: {
|
|
5
|
-
"astro:config:setup": ({
|
|
6
|
-
addMiddleware({
|
|
7
|
-
entrypoint: "@chat-de-hp/site/annotation-middleware",
|
|
8
|
-
order: "pre",
|
|
9
|
-
});
|
|
5
|
+
"astro:config:setup": ({ injectScript, updateConfig }) => {
|
|
10
6
|
injectScript("page", 'import "@chat-de-hp/site/runtime/annotation-capture";');
|
|
11
7
|
updateConfig({
|
|
12
8
|
vite: {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare function startAnnotationCapture(): () => void;
|
|
2
2
|
//# sourceMappingURL=annotation-capture.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"annotation-capture.d.ts","sourceRoot":"","sources":["../../src/runtime/annotation-capture.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"annotation-capture.d.ts","sourceRoot":"","sources":["../../src/runtime/annotation-capture.ts"],"names":[],"mappings":"AAkBA,wBAAgB,sBAAsB,eA2DrC"}
|
|
@@ -1,57 +1,61 @@
|
|
|
1
|
-
import { isExpectedSiteCaptureParentMessage,
|
|
2
|
-
import {
|
|
1
|
+
import { isExpectedSiteCaptureParentMessage, SITE_CAPTURE_BOOT_PAGE_HASH_PARAM, SITE_CAPTURE_BOOT_PARENT_ORIGIN_PARAM, SITE_CAPTURE_MESSAGE_TYPE, SITE_CAPTURE_SESSION_STORAGE_KEY, } from "./capture-contract.js";
|
|
2
|
+
import { freezeCaptureViewport } from "./capture-viewport.js";
|
|
3
3
|
import { extractElements } from "./element-extractor.js";
|
|
4
4
|
let captureFrozen = false;
|
|
5
|
-
let
|
|
6
|
-
function startAnnotationCapture() {
|
|
5
|
+
let resumeViewport = null;
|
|
6
|
+
export function startAnnotationCapture() {
|
|
7
7
|
if (window.parent === window) {
|
|
8
|
-
return;
|
|
8
|
+
return () => { };
|
|
9
9
|
}
|
|
10
10
|
const session = readCaptureSession();
|
|
11
11
|
if (!session) {
|
|
12
|
-
return;
|
|
12
|
+
return () => { };
|
|
13
13
|
}
|
|
14
|
-
|
|
14
|
+
const onMessage = (event) => {
|
|
15
15
|
if (!isExpectedSiteCaptureParentMessage(event, {
|
|
16
|
-
nonce: session.nonce,
|
|
17
16
|
origin: session.parentOrigin,
|
|
18
17
|
source: window.parent,
|
|
19
18
|
})) {
|
|
20
19
|
return;
|
|
21
20
|
}
|
|
21
|
+
if (event.data.type === SITE_CAPTURE_MESSAGE_TYPE.reload) {
|
|
22
|
+
window.location.reload();
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
22
25
|
if (event.data.type === SITE_CAPTURE_MESSAGE_TYPE.end) {
|
|
23
|
-
|
|
26
|
+
cleanup();
|
|
27
|
+
endAnnotationSession(session, true);
|
|
24
28
|
return;
|
|
25
29
|
}
|
|
26
|
-
if (
|
|
30
|
+
if (event.data.type === SITE_CAPTURE_MESSAGE_TYPE.probe) {
|
|
31
|
+
postReady(session);
|
|
27
32
|
return;
|
|
28
33
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
elements,
|
|
36
|
-
nonce: session.nonce,
|
|
37
|
-
pagePath: currentPagePath(),
|
|
38
|
-
type: SITE_CAPTURE_MESSAGE_TYPE.captured,
|
|
39
|
-
});
|
|
40
|
-
void endAnnotationSession(session, false);
|
|
34
|
+
if (event.data.type === SITE_CAPTURE_MESSAGE_TYPE.resume) {
|
|
35
|
+
resumeViewport?.();
|
|
36
|
+
resumeViewport = null;
|
|
37
|
+
captureFrozen = false;
|
|
38
|
+
postReady(session);
|
|
39
|
+
return;
|
|
41
40
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
message: "画面を読み取れませんでした。",
|
|
45
|
-
nonce: session.nonce,
|
|
46
|
-
type: SITE_CAPTURE_MESSAGE_TYPE.error,
|
|
47
|
-
});
|
|
41
|
+
if (captureFrozen) {
|
|
42
|
+
return;
|
|
48
43
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
44
|
+
captureCurrentViewport(session);
|
|
45
|
+
};
|
|
46
|
+
const onBeforeUnload = () => {
|
|
47
|
+
postToParent(session, {
|
|
48
|
+
type: SITE_CAPTURE_MESSAGE_TYPE.loading,
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
window.addEventListener("message", onMessage);
|
|
52
|
+
window.addEventListener("beforeunload", onBeforeUnload);
|
|
53
|
+
const cleanup = () => {
|
|
54
|
+
window.removeEventListener("message", onMessage);
|
|
55
|
+
window.removeEventListener("beforeunload", onBeforeUnload);
|
|
56
|
+
};
|
|
57
|
+
postReady(session);
|
|
58
|
+
return cleanup;
|
|
55
59
|
}
|
|
56
60
|
function readCaptureSession() {
|
|
57
61
|
const bootstrap = readCaptureBootstrap();
|
|
@@ -73,18 +77,14 @@ function readCaptureSession() {
|
|
|
73
77
|
}
|
|
74
78
|
function readCaptureBootstrap() {
|
|
75
79
|
const hash = new URLSearchParams(window.location.hash.slice(1));
|
|
76
|
-
const nonce = hash.get(SITE_CAPTURE_BOOT_NONCE_PARAM);
|
|
77
80
|
const parentOrigin = normalizeOrigin(hash.get(SITE_CAPTURE_BOOT_PARENT_ORIGIN_PARAM));
|
|
78
|
-
if (!
|
|
79
|
-
nonce.length <= 256 &&
|
|
80
|
-
parentOrigin &&
|
|
81
|
-
parentOrigin === readAllowedParentOrigin())) {
|
|
81
|
+
if (!parentOrigin) {
|
|
82
82
|
return null;
|
|
83
83
|
}
|
|
84
84
|
const pageHash = hash.get(SITE_CAPTURE_BOOT_PAGE_HASH_PARAM);
|
|
85
85
|
const nextUrl = `${window.location.pathname}${window.location.search}${pageHash ? `#${pageHash}` : ""}`;
|
|
86
86
|
window.history.replaceState(window.history.state, "", nextUrl);
|
|
87
|
-
return {
|
|
87
|
+
return { parentOrigin };
|
|
88
88
|
}
|
|
89
89
|
function parseStoredSession(value) {
|
|
90
90
|
if (!value) {
|
|
@@ -95,15 +95,8 @@ function parseStoredSession(value) {
|
|
|
95
95
|
if (!parsed || typeof parsed !== "object") {
|
|
96
96
|
return null;
|
|
97
97
|
}
|
|
98
|
-
const nonce = Reflect.get(parsed, "nonce");
|
|
99
98
|
const parentOrigin = normalizeOrigin(Reflect.get(parsed, "parentOrigin"));
|
|
100
|
-
return
|
|
101
|
-
nonce.trim() &&
|
|
102
|
-
nonce.length <= 256 &&
|
|
103
|
-
parentOrigin &&
|
|
104
|
-
parentOrigin === readAllowedParentOrigin()
|
|
105
|
-
? { nonce, parentOrigin }
|
|
106
|
-
: null;
|
|
99
|
+
return parentOrigin ? { parentOrigin } : null;
|
|
107
100
|
}
|
|
108
101
|
catch {
|
|
109
102
|
return null;
|
|
@@ -125,75 +118,53 @@ function normalizeOrigin(value) {
|
|
|
125
118
|
return null;
|
|
126
119
|
}
|
|
127
120
|
}
|
|
128
|
-
function readAllowedParentOrigin() {
|
|
129
|
-
for (const item of document.cookie.split(";")) {
|
|
130
|
-
const separator = item.indexOf("=");
|
|
131
|
-
if (separator < 1) {
|
|
132
|
-
continue;
|
|
133
|
-
}
|
|
134
|
-
if (item.slice(0, separator).trim() === SITE_CAPTURE_PARENT_ORIGIN_COOKIE) {
|
|
135
|
-
try {
|
|
136
|
-
return normalizeOrigin(decodeURIComponent(item.slice(separator + 1).trim()));
|
|
137
|
-
}
|
|
138
|
-
catch {
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return null;
|
|
144
|
-
}
|
|
145
121
|
function currentPagePath() {
|
|
146
122
|
return `${window.location.pathname}${window.location.search}${window.location.hash}`;
|
|
147
123
|
}
|
|
148
|
-
function
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
124
|
+
function captureCurrentViewport(session) {
|
|
125
|
+
try {
|
|
126
|
+
const root = document.body ?? document.documentElement;
|
|
127
|
+
const elements = extractElements(root);
|
|
128
|
+
resumeViewport = freezeCaptureViewport();
|
|
129
|
+
captureFrozen = true;
|
|
130
|
+
postToParent(session, {
|
|
131
|
+
elements,
|
|
132
|
+
pagePath: currentPagePath(),
|
|
133
|
+
type: SITE_CAPTURE_MESSAGE_TYPE.captured,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
postToParent(session, {
|
|
138
|
+
message: "画面を読み取れませんでした。",
|
|
139
|
+
type: SITE_CAPTURE_MESSAGE_TYPE.error,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
161
142
|
}
|
|
162
143
|
function endAnnotationSession(session, notifyParent) {
|
|
163
|
-
|
|
164
|
-
|
|
144
|
+
resumeViewport?.();
|
|
145
|
+
resumeViewport = null;
|
|
146
|
+
captureFrozen = false;
|
|
147
|
+
try {
|
|
148
|
+
window.sessionStorage.removeItem(SITE_CAPTURE_SESSION_STORAGE_KEY);
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
// The capture bridge is inactive after its message listeners are removed.
|
|
152
|
+
}
|
|
153
|
+
if (notifyParent) {
|
|
154
|
+
postToParent(session, {
|
|
155
|
+
type: SITE_CAPTURE_MESSAGE_TYPE.ended,
|
|
156
|
+
});
|
|
165
157
|
}
|
|
166
|
-
endSessionPromise = (async () => {
|
|
167
|
-
try {
|
|
168
|
-
window.sessionStorage.removeItem(SITE_CAPTURE_SESSION_STORAGE_KEY);
|
|
169
|
-
}
|
|
170
|
-
catch {
|
|
171
|
-
// The server-side cookie expiration remains authoritative.
|
|
172
|
-
}
|
|
173
|
-
const endUrl = new URL(window.location.href);
|
|
174
|
-
endUrl.hash = "";
|
|
175
|
-
endUrl.search = "";
|
|
176
|
-
endUrl.searchParams.set(SITE_ANNOTATION_END_PARAM, "1");
|
|
177
|
-
try {
|
|
178
|
-
await window.fetch(endUrl, {
|
|
179
|
-
cache: "no-store",
|
|
180
|
-
credentials: "same-origin",
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
finally {
|
|
184
|
-
if (notifyParent) {
|
|
185
|
-
postToParent(session, {
|
|
186
|
-
nonce: session.nonce,
|
|
187
|
-
type: SITE_CAPTURE_MESSAGE_TYPE.ended,
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
})();
|
|
192
|
-
return endSessionPromise;
|
|
193
158
|
}
|
|
194
159
|
function postToParent(session, message) {
|
|
195
160
|
window.parent.postMessage(message, session.parentOrigin);
|
|
196
161
|
}
|
|
162
|
+
function postReady(session) {
|
|
163
|
+
postToParent(session, {
|
|
164
|
+
pagePath: currentPagePath(),
|
|
165
|
+
type: SITE_CAPTURE_MESSAGE_TYPE.ready,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
197
168
|
if (document.readyState === "loading") {
|
|
198
169
|
document.addEventListener("DOMContentLoaded", startAnnotationCapture, {
|
|
199
170
|
once: true,
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { ExtractedElement } from "./element-extractor.js";
|
|
2
|
-
export declare const SITE_CAPTURE_BOOT_NONCE_PARAM = "__chat_de_hp_capture";
|
|
3
2
|
export declare const SITE_CAPTURE_BOOT_PARENT_ORIGIN_PARAM = "__chat_de_hp_capture_parent";
|
|
4
3
|
export declare const SITE_CAPTURE_BOOT_PAGE_HASH_PARAM = "__chat_de_hp_capture_page_hash";
|
|
5
|
-
export declare const SITE_CAPTURE_PARENT_ORIGIN_COOKIE = "__Host-chat-de-hp-annotation-parent";
|
|
6
4
|
export declare const SITE_CAPTURE_SESSION_STORAGE_KEY = "chat-de-hp:capture-session";
|
|
7
5
|
export declare const SITE_CAPTURE_MESSAGE_TYPE: {
|
|
8
6
|
readonly capture: "chat-de-hp:capture";
|
|
@@ -10,30 +8,36 @@ export declare const SITE_CAPTURE_MESSAGE_TYPE: {
|
|
|
10
8
|
readonly end: "chat-de-hp:end-capture";
|
|
11
9
|
readonly ended: "chat-de-hp:capture-ended";
|
|
12
10
|
readonly error: "chat-de-hp:capture-error";
|
|
11
|
+
readonly loading: "chat-de-hp:capture-loading";
|
|
12
|
+
readonly probe: "chat-de-hp:capture-probe";
|
|
13
13
|
readonly ready: "chat-de-hp:capture-ready";
|
|
14
|
+
readonly reload: "chat-de-hp:reload";
|
|
15
|
+
readonly resume: "chat-de-hp:resume-capture";
|
|
14
16
|
};
|
|
15
17
|
export type SiteCaptureParentMessage = {
|
|
16
|
-
nonce: string;
|
|
17
18
|
type: typeof SITE_CAPTURE_MESSAGE_TYPE.capture;
|
|
18
19
|
} | {
|
|
19
|
-
nonce: string;
|
|
20
20
|
type: typeof SITE_CAPTURE_MESSAGE_TYPE.end;
|
|
21
|
+
} | {
|
|
22
|
+
type: typeof SITE_CAPTURE_MESSAGE_TYPE.probe;
|
|
23
|
+
} | {
|
|
24
|
+
type: typeof SITE_CAPTURE_MESSAGE_TYPE.reload;
|
|
25
|
+
} | {
|
|
26
|
+
type: typeof SITE_CAPTURE_MESSAGE_TYPE.resume;
|
|
21
27
|
};
|
|
22
28
|
export type SiteCaptureFrameMessage = {
|
|
23
|
-
nonce: string;
|
|
24
29
|
pagePath: string;
|
|
25
30
|
type: typeof SITE_CAPTURE_MESSAGE_TYPE.ready;
|
|
26
31
|
} | {
|
|
27
32
|
elements: ExtractedElement[];
|
|
28
|
-
nonce: string;
|
|
29
33
|
pagePath: string;
|
|
30
34
|
type: typeof SITE_CAPTURE_MESSAGE_TYPE.captured;
|
|
31
35
|
} | {
|
|
32
36
|
message: string;
|
|
33
|
-
nonce: string;
|
|
34
37
|
type: typeof SITE_CAPTURE_MESSAGE_TYPE.error;
|
|
35
38
|
} | {
|
|
36
|
-
|
|
39
|
+
type: typeof SITE_CAPTURE_MESSAGE_TYPE.loading;
|
|
40
|
+
} | {
|
|
37
41
|
type: typeof SITE_CAPTURE_MESSAGE_TYPE.ended;
|
|
38
42
|
};
|
|
39
43
|
type CaptureMessageEvent = {
|
|
@@ -42,7 +46,6 @@ type CaptureMessageEvent = {
|
|
|
42
46
|
source: unknown;
|
|
43
47
|
};
|
|
44
48
|
type CaptureMessageExpectation = {
|
|
45
|
-
nonce: string;
|
|
46
49
|
origin: string;
|
|
47
50
|
source: unknown;
|
|
48
51
|
};
|
|
@@ -52,6 +55,7 @@ export declare function isExpectedSiteCaptureParentMessage(event: CaptureMessage
|
|
|
52
55
|
export declare function isExpectedSiteCaptureFrameMessage(event: CaptureMessageEvent, expected: CaptureMessageExpectation): event is CaptureMessageEvent & {
|
|
53
56
|
data: SiteCaptureFrameMessage;
|
|
54
57
|
};
|
|
58
|
+
export declare function isSiteCaptureFrameProtocolMessage(value: unknown): boolean;
|
|
55
59
|
export declare function isSiteCaptureParentMessage(value: unknown): value is SiteCaptureParentMessage;
|
|
56
60
|
export declare function isSiteCaptureFrameMessage(value: unknown): value is SiteCaptureFrameMessage;
|
|
57
61
|
export {};
|
|
@@ -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,
|
|
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,qCAAqC,gCACnB,CAAC;AAChC,eAAO,MAAM,iCAAiC,mCACZ,CAAC;AACnC,eAAO,MAAM,gCAAgC,+BAA+B,CAAC;AAE7E,eAAO,MAAM,yBAAyB;;;;;;;;;;;CAW5B,CAAC;AAEX,MAAM,MAAM,wBAAwB,GAChC;IACE,IAAI,EAAE,OAAO,yBAAyB,CAAC,OAAO,CAAC;CAChD,GACD;IACE,IAAI,EAAE,OAAO,yBAAyB,CAAC,GAAG,CAAC;CAC5C,GACD;IACE,IAAI,EAAE,OAAO,yBAAyB,CAAC,KAAK,CAAC;CAC9C,GACD;IACE,IAAI,EAAE,OAAO,yBAAyB,CAAC,MAAM,CAAC;CAC/C,GACD;IACE,IAAI,EAAE,OAAO,yBAAyB,CAAC,MAAM,CAAC;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lC"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
export const SITE_CAPTURE_BOOT_NONCE_PARAM = "__chat_de_hp_capture";
|
|
2
1
|
export const SITE_CAPTURE_BOOT_PARENT_ORIGIN_PARAM = "__chat_de_hp_capture_parent";
|
|
3
2
|
export const SITE_CAPTURE_BOOT_PAGE_HASH_PARAM = "__chat_de_hp_capture_page_hash";
|
|
4
|
-
export const SITE_CAPTURE_PARENT_ORIGIN_COOKIE = "__Host-chat-de-hp-annotation-parent";
|
|
5
3
|
export const SITE_CAPTURE_SESSION_STORAGE_KEY = "chat-de-hp:capture-session";
|
|
6
4
|
export const SITE_CAPTURE_MESSAGE_TYPE = {
|
|
7
5
|
capture: "chat-de-hp:capture",
|
|
@@ -9,29 +7,45 @@ export const SITE_CAPTURE_MESSAGE_TYPE = {
|
|
|
9
7
|
end: "chat-de-hp:end-capture",
|
|
10
8
|
ended: "chat-de-hp:capture-ended",
|
|
11
9
|
error: "chat-de-hp:capture-error",
|
|
10
|
+
loading: "chat-de-hp:capture-loading",
|
|
11
|
+
probe: "chat-de-hp:capture-probe",
|
|
12
12
|
ready: "chat-de-hp:capture-ready",
|
|
13
|
+
reload: "chat-de-hp:reload",
|
|
14
|
+
resume: "chat-de-hp:resume-capture",
|
|
13
15
|
};
|
|
14
16
|
export function isExpectedSiteCaptureParentMessage(event, expected) {
|
|
15
17
|
return (event.origin === expected.origin &&
|
|
16
18
|
event.source === expected.source &&
|
|
17
|
-
isSiteCaptureParentMessage(event.data)
|
|
18
|
-
event.data.nonce === expected.nonce);
|
|
19
|
+
isSiteCaptureParentMessage(event.data));
|
|
19
20
|
}
|
|
20
21
|
export function isExpectedSiteCaptureFrameMessage(event, expected) {
|
|
21
22
|
return (event.origin === expected.origin &&
|
|
22
23
|
event.source === expected.source &&
|
|
23
|
-
isSiteCaptureFrameMessage(event.data)
|
|
24
|
-
|
|
24
|
+
isSiteCaptureFrameMessage(event.data));
|
|
25
|
+
}
|
|
26
|
+
export function isSiteCaptureFrameProtocolMessage(value) {
|
|
27
|
+
if (!isRecord(value)) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const { type } = value;
|
|
31
|
+
return (type === SITE_CAPTURE_MESSAGE_TYPE.captured ||
|
|
32
|
+
type === SITE_CAPTURE_MESSAGE_TYPE.ended ||
|
|
33
|
+
type === SITE_CAPTURE_MESSAGE_TYPE.error ||
|
|
34
|
+
type === SITE_CAPTURE_MESSAGE_TYPE.loading ||
|
|
35
|
+
type === SITE_CAPTURE_MESSAGE_TYPE.ready);
|
|
25
36
|
}
|
|
26
37
|
export function isSiteCaptureParentMessage(value) {
|
|
27
|
-
if (!isRecord(value)
|
|
38
|
+
if (!isRecord(value)) {
|
|
28
39
|
return false;
|
|
29
40
|
}
|
|
30
41
|
return (value.type === SITE_CAPTURE_MESSAGE_TYPE.capture ||
|
|
31
|
-
value.type === SITE_CAPTURE_MESSAGE_TYPE.end
|
|
42
|
+
value.type === SITE_CAPTURE_MESSAGE_TYPE.end ||
|
|
43
|
+
value.type === SITE_CAPTURE_MESSAGE_TYPE.probe ||
|
|
44
|
+
value.type === SITE_CAPTURE_MESSAGE_TYPE.reload ||
|
|
45
|
+
value.type === SITE_CAPTURE_MESSAGE_TYPE.resume);
|
|
32
46
|
}
|
|
33
47
|
export function isSiteCaptureFrameMessage(value) {
|
|
34
|
-
if (!isRecord(value)
|
|
48
|
+
if (!isRecord(value)) {
|
|
35
49
|
return false;
|
|
36
50
|
}
|
|
37
51
|
if (value.type === SITE_CAPTURE_MESSAGE_TYPE.ready) {
|
|
@@ -45,7 +59,8 @@ export function isSiteCaptureFrameMessage(value) {
|
|
|
45
59
|
if (value.type === SITE_CAPTURE_MESSAGE_TYPE.error) {
|
|
46
60
|
return isNonEmptyString(value.message);
|
|
47
61
|
}
|
|
48
|
-
return value.type === SITE_CAPTURE_MESSAGE_TYPE.ended
|
|
62
|
+
return (value.type === SITE_CAPTURE_MESSAGE_TYPE.ended ||
|
|
63
|
+
value.type === SITE_CAPTURE_MESSAGE_TYPE.loading);
|
|
49
64
|
}
|
|
50
65
|
function isExtractedElement(value) {
|
|
51
66
|
if (!isRecord(value) ||
|
|
@@ -94,9 +109,6 @@ function isPagePath(value) {
|
|
|
94
109
|
!value.startsWith("//") &&
|
|
95
110
|
!value.includes("\\"));
|
|
96
111
|
}
|
|
97
|
-
function isNonce(value) {
|
|
98
|
-
return isNonEmptyString(value) && value.length <= 256;
|
|
99
|
-
}
|
|
100
112
|
function isNonEmptyString(value) {
|
|
101
113
|
return typeof value === "string" && value.trim().length > 0;
|
|
102
114
|
}
|
|
@@ -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
|
+
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export declare const CHAT_DE_HP_ANNOTATION_MODE_HEADER = "x-chat-de-hp-annotation-mode";
|
|
2
|
-
export declare const SITE_ANNOTATION_END_PARAM = "__chat_de_hp_annotation_end";
|
|
3
1
|
export type ChatDeHpExecutionContext = {
|
|
4
2
|
passThroughOnException?(): void;
|
|
5
3
|
waitUntil(promise: Promise<unknown>): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../../src/runtime/contracts.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../../src/runtime/contracts.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,wBAAwB,GAAG;IACrC,sBAAsB,CAAC,IAAI,IAAI,CAAC;IAChC,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;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AE,MAAM,CAAC;YAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;SACtB,CAAC;KACH,GACA,OAAO,CAAC,OAAO,CAAC,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,cAAc,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,YAAY,CAAC,EAAE;QACb,kBAAkB,CAAC,EAAE,MAAM,CAAC;QAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,CACJ,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,eAAe,EACpB,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG;IACxC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,SAAS,oBAAoB,EAAE,CAAC;CACzC,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,UAAU,EAAE,SAAS,2BAA2B,EAAE,CAAC;CACpD,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,CACH,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,eAAe,EACpB,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,QAAQ,CAAC,CAAC;CACtB,CAAC"}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export const SITE_ANNOTATION_END_PARAM = "__chat_de_hp_annotation_end";
|
|
1
|
+
export {};
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { PluginBridge } from "@emdash-cms/cloudflare/sandbox";
|
|
2
2
|
export type { ChatDeHpExecutionContext, ChatDeHpRuntimeContribution, ChatDeHpRuntimeRoute, ChatDeHpSiteEnv, GeneratedSiteRuntime, } from "./contracts.js";
|
|
3
|
-
export { CHAT_DE_HP_ANNOTATION_MODE_HEADER } from "./contracts.js";
|
|
4
3
|
export { createChatDeHpSiteWorker } from "./worker.js";
|
|
5
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAE9D,YAAY,EACV,wBAAwB,EACxB,2BAA2B,EAC3B,oBAAoB,EACpB,eAAe,EACf,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAE9D,YAAY,EACV,wBAAwB,EACxB,2BAA2B,EAC3B,oBAAoB,EACpB,eAAe,EACf,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/runtime/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chat-de-hp/site",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Managed Astro site runtime and primitive composition for Chat de HP",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,10 +22,6 @@
|
|
|
22
22
|
"types": "./dist/astro.d.ts",
|
|
23
23
|
"default": "./dist/astro.js"
|
|
24
24
|
},
|
|
25
|
-
"./annotation-middleware": {
|
|
26
|
-
"types": "./dist/annotation-middleware.d.ts",
|
|
27
|
-
"default": "./dist/annotation-middleware.js"
|
|
28
|
-
},
|
|
29
25
|
"./emdash": {
|
|
30
26
|
"types": "./dist/emdash-annotation.d.ts",
|
|
31
27
|
"default": "./dist/emdash-annotation.js"
|