@chat-de-hp/site 0.2.4 → 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/annotation-middleware.d.ts +4 -0
- package/dist/annotation-middleware.d.ts.map +1 -0
- package/dist/annotation-middleware.js +20 -0
- package/dist/astro.d.ts.map +1 -1
- package/dist/astro.js +2 -0
- package/dist/check.d.ts +21 -0
- package/dist/check.d.ts.map +1 -0
- package/dist/check.js +576 -0
- package/dist/cli.js +51 -11
- package/dist/contracts/forms.d.ts +6 -6
- package/dist/emdash-annotation.d.ts +7 -0
- package/dist/emdash-annotation.d.ts.map +1 -0
- package/dist/emdash-annotation.js +37 -0
- package/dist/internal/annotation-context.d.ts +3 -0
- package/dist/internal/annotation-context.d.ts.map +1 -0
- package/dist/internal/annotation-context.js +14 -0
- package/dist/internal/annotation-integration.d.ts +3 -0
- package/dist/internal/annotation-integration.d.ts.map +1 -0
- package/dist/internal/annotation-integration.js +43 -0
- package/dist/runtime/annotation-capture.d.ts +2 -0
- package/dist/runtime/annotation-capture.d.ts.map +1 -0
- package/dist/runtime/annotation-capture.js +202 -0
- package/dist/runtime/capture-contract.d.ts +62 -0
- package/dist/runtime/capture-contract.d.ts.map +1 -0
- package/dist/runtime/capture-contract.js +107 -0
- 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 +2 -0
- package/dist/runtime/contracts.d.ts.map +1 -1
- package/dist/runtime/contracts.js +2 -1
- package/dist/runtime/element-extractor.d.ts +21 -0
- package/dist/runtime/element-extractor.d.ts.map +1 -0
- package/dist/runtime/element-extractor.js +258 -0
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +1 -0
- package/package.json +26 -1
|
@@ -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,3 +1,5 @@
|
|
|
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";
|
|
1
3
|
export type ChatDeHpExecutionContext = {
|
|
2
4
|
passThroughOnException?(): void;
|
|
3
5
|
waitUntil(promise: Promise<unknown>): void;
|
|
@@ -1 +1 @@
|
|
|
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;IAC5B,MAAM,CAAC,EAAE;QAAE,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;KAAE,CAAC;IACxD,2BAA2B,CAAC,EAAE,MAAM,CAAC;IACrC,EAAE,CAAC,EAAE,kBAAkB,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,gBAAgB,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,2BAA2B,CAAC;CACrD,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,CAAC,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,2BAA2B,CAAC;IACxD,KAAK,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IACxD,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CAC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AAM,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 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const CHAT_DE_HP_ANNOTATION_MODE_HEADER = "x-chat-de-hp-annotation-mode";
|
|
2
|
+
export const SITE_ANNOTATION_END_PARAM = "__chat_de_hp_annotation_end";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type NormalizedRect = {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
};
|
|
7
|
+
export type CmsRef = {
|
|
8
|
+
collection: string;
|
|
9
|
+
id: string;
|
|
10
|
+
field?: string;
|
|
11
|
+
};
|
|
12
|
+
export type ExtractedElement = {
|
|
13
|
+
elementId: string;
|
|
14
|
+
text?: string;
|
|
15
|
+
role: string;
|
|
16
|
+
section?: string;
|
|
17
|
+
bounds: NormalizedRect;
|
|
18
|
+
cmsRef?: CmsRef;
|
|
19
|
+
};
|
|
20
|
+
export declare function extractElements(root: Element): ExtractedElement[];
|
|
21
|
+
//# sourceMappingURL=element-extractor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element-extractor.d.ts","sourceRoot":"","sources":["../../src/runtime/element-extractor.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG;IAC3B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,cAAc,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAuEF,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,GAAG,gBAAgB,EAAE,CAqDjE"}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
const BLOCK_ELEMENTS = new Set([
|
|
2
|
+
"ADDRESS",
|
|
3
|
+
"ARTICLE",
|
|
4
|
+
"ASIDE",
|
|
5
|
+
"BLOCKQUOTE",
|
|
6
|
+
"DD",
|
|
7
|
+
"DIV",
|
|
8
|
+
"DL",
|
|
9
|
+
"DT",
|
|
10
|
+
"FIGCAPTION",
|
|
11
|
+
"FIGURE",
|
|
12
|
+
"FOOTER",
|
|
13
|
+
"FORM",
|
|
14
|
+
"H1",
|
|
15
|
+
"H2",
|
|
16
|
+
"H3",
|
|
17
|
+
"H4",
|
|
18
|
+
"H5",
|
|
19
|
+
"H6",
|
|
20
|
+
"HEADER",
|
|
21
|
+
"LI",
|
|
22
|
+
"MAIN",
|
|
23
|
+
"NAV",
|
|
24
|
+
"OL",
|
|
25
|
+
"P",
|
|
26
|
+
"PRE",
|
|
27
|
+
"SECTION",
|
|
28
|
+
"TABLE",
|
|
29
|
+
"TBODY",
|
|
30
|
+
"TD",
|
|
31
|
+
"TFOOT",
|
|
32
|
+
"TH",
|
|
33
|
+
"THEAD",
|
|
34
|
+
"TR",
|
|
35
|
+
"UL",
|
|
36
|
+
]);
|
|
37
|
+
const NON_RENDERED_ELEMENTS = new Set([
|
|
38
|
+
"LINK",
|
|
39
|
+
"META",
|
|
40
|
+
"NOSCRIPT",
|
|
41
|
+
"SCRIPT",
|
|
42
|
+
"STYLE",
|
|
43
|
+
"TEMPLATE",
|
|
44
|
+
]);
|
|
45
|
+
const MAX_TEXT_LENGTH = 200;
|
|
46
|
+
const TEXTLESS_CONTENT_ELEMENTS = new Set([
|
|
47
|
+
"A",
|
|
48
|
+
"AUDIO",
|
|
49
|
+
"BUTTON",
|
|
50
|
+
"CANVAS",
|
|
51
|
+
"IFRAME",
|
|
52
|
+
"IMG",
|
|
53
|
+
"INPUT",
|
|
54
|
+
"METER",
|
|
55
|
+
"PROGRESS",
|
|
56
|
+
"SELECT",
|
|
57
|
+
"TEXTAREA",
|
|
58
|
+
"VIDEO",
|
|
59
|
+
]);
|
|
60
|
+
export function extractElements(root) {
|
|
61
|
+
const view = root.ownerDocument.defaultView;
|
|
62
|
+
if (!(view && view.innerWidth > 0 && view.innerHeight > 0)) {
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
const elements = [root, ...root.querySelectorAll("*")];
|
|
66
|
+
const candidates = [];
|
|
67
|
+
for (const [documentOrder, element] of elements.entries()) {
|
|
68
|
+
if (isHiddenOrDecorative(element, root)) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const cmsRef = parseCmsRef(element.dataset.emdashRef);
|
|
72
|
+
if (!cmsRef && element.parentElement?.closest("[data-emdash-ref]")) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const text = truncateText(cmsRef ? descendantText(element) : directText(element));
|
|
76
|
+
if (!(cmsRef || text || TEXTLESS_CONTENT_ELEMENTS.has(element.tagName))) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const rect = element.getBoundingClientRect();
|
|
80
|
+
if (!intersectsViewport(rect, view)) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
candidates.push({
|
|
84
|
+
bounds: normalizeRect(rect, view),
|
|
85
|
+
...(cmsRef ? { cmsRef } : {}),
|
|
86
|
+
documentOrder,
|
|
87
|
+
left: rect.left,
|
|
88
|
+
role: element.getAttribute("role") ?? element.tagName.toLowerCase(),
|
|
89
|
+
section: findSection(element),
|
|
90
|
+
...(text ? { text } : {}),
|
|
91
|
+
top: rect.top,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return candidates
|
|
95
|
+
.sort((first, second) => first.top - second.top ||
|
|
96
|
+
first.left - second.left ||
|
|
97
|
+
first.documentOrder - second.documentOrder)
|
|
98
|
+
.map(({ documentOrder: _, left: __, top: ___, ...element }, index) => ({
|
|
99
|
+
...element,
|
|
100
|
+
elementId: `element-${index + 1}`,
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
function findSection(element) {
|
|
104
|
+
return element.parentElement?.closest("[id]")?.id || undefined;
|
|
105
|
+
}
|
|
106
|
+
function intersectsViewport(rect, view) {
|
|
107
|
+
return (rect.width > 0 &&
|
|
108
|
+
rect.height > 0 &&
|
|
109
|
+
rect.bottom > 0 &&
|
|
110
|
+
rect.right > 0 &&
|
|
111
|
+
rect.top < view.innerHeight &&
|
|
112
|
+
rect.left < view.innerWidth);
|
|
113
|
+
}
|
|
114
|
+
function normalizeRect(rect, view) {
|
|
115
|
+
const left = Math.max(0, rect.left);
|
|
116
|
+
const top = Math.max(0, rect.top);
|
|
117
|
+
const right = Math.min(view.innerWidth, rect.right);
|
|
118
|
+
const bottom = Math.min(view.innerHeight, rect.bottom);
|
|
119
|
+
return {
|
|
120
|
+
height: (bottom - top) / view.innerHeight,
|
|
121
|
+
width: (right - left) / view.innerWidth,
|
|
122
|
+
x: left / view.innerWidth,
|
|
123
|
+
y: top / view.innerHeight,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function descendantText(element) {
|
|
127
|
+
const view = element.ownerDocument.defaultView;
|
|
128
|
+
if (!view) {
|
|
129
|
+
return "";
|
|
130
|
+
}
|
|
131
|
+
const segments = [];
|
|
132
|
+
visitTextNodes(element, (textNode) => {
|
|
133
|
+
const rawText = textNode.nodeValue ?? "";
|
|
134
|
+
const parent = textNode.parentElement;
|
|
135
|
+
if (!parent ||
|
|
136
|
+
isHiddenOrDecorative(parent, element) ||
|
|
137
|
+
!intersectsViewport(parent.getBoundingClientRect(), view)) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const text = normalizeText(rawText);
|
|
141
|
+
if (!text) {
|
|
142
|
+
const previous = segments.at(-1);
|
|
143
|
+
if (previous && /\s/u.test(rawText)) {
|
|
144
|
+
previous.trailingSpace = true;
|
|
145
|
+
}
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const boundary = nearestBlockBoundary(parent, element);
|
|
149
|
+
const previous = segments.at(-1);
|
|
150
|
+
if (previous?.boundary === boundary) {
|
|
151
|
+
const separator = previous.trailingSpace || /^\s/u.test(rawText) ? " " : "";
|
|
152
|
+
previous.text += `${separator}${text}`;
|
|
153
|
+
previous.trailingSpace = /\s$/u.test(rawText);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
segments.push({
|
|
157
|
+
boundary,
|
|
158
|
+
text,
|
|
159
|
+
trailingSpace: /\s$/u.test(rawText),
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
return segments.map(({ text }) => text).join(" / ");
|
|
163
|
+
}
|
|
164
|
+
function directText(element) {
|
|
165
|
+
return normalizeText([...element.childNodes]
|
|
166
|
+
.filter((node) => node.nodeType === 3)
|
|
167
|
+
.map((node) => node.nodeValue ?? "")
|
|
168
|
+
.join(" "));
|
|
169
|
+
}
|
|
170
|
+
function nearestBlockBoundary(element, root) {
|
|
171
|
+
let current = element;
|
|
172
|
+
while (current && current !== root) {
|
|
173
|
+
if (BLOCK_ELEMENTS.has(current.tagName)) {
|
|
174
|
+
return current;
|
|
175
|
+
}
|
|
176
|
+
current = current.parentElement;
|
|
177
|
+
}
|
|
178
|
+
return root;
|
|
179
|
+
}
|
|
180
|
+
function normalizeText(text) {
|
|
181
|
+
return text.replaceAll(/\s+/gu, " ").trim();
|
|
182
|
+
}
|
|
183
|
+
function truncateText(text) {
|
|
184
|
+
const characters = [...text];
|
|
185
|
+
if (characters.length <= MAX_TEXT_LENGTH) {
|
|
186
|
+
return text;
|
|
187
|
+
}
|
|
188
|
+
return `${characters
|
|
189
|
+
.slice(0, MAX_TEXT_LENGTH - 1)
|
|
190
|
+
.join("")
|
|
191
|
+
.trimEnd()}…`;
|
|
192
|
+
}
|
|
193
|
+
function isHiddenOrDecorative(element, root) {
|
|
194
|
+
const view = root.ownerDocument.defaultView;
|
|
195
|
+
let current = element;
|
|
196
|
+
while (current) {
|
|
197
|
+
const role = current.getAttribute("role");
|
|
198
|
+
if (NON_RENDERED_ELEMENTS.has(current.tagName) ||
|
|
199
|
+
current.hasAttribute("hidden") ||
|
|
200
|
+
current.getAttribute("aria-hidden") === "true" ||
|
|
201
|
+
role === "none" ||
|
|
202
|
+
role === "presentation") {
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
if (view) {
|
|
206
|
+
const style = view.getComputedStyle(current);
|
|
207
|
+
if (style.display === "none" ||
|
|
208
|
+
style.visibility === "hidden" ||
|
|
209
|
+
style.visibility === "collapse" ||
|
|
210
|
+
style.opacity === "0" ||
|
|
211
|
+
style.contentVisibility === "hidden") {
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (current === root) {
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
current = current.parentElement;
|
|
219
|
+
}
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
function visitTextNodes(element, visit) {
|
|
223
|
+
for (const child of element.childNodes) {
|
|
224
|
+
if (child.nodeType === 3) {
|
|
225
|
+
visit(child);
|
|
226
|
+
}
|
|
227
|
+
else if (child.nodeType === 1) {
|
|
228
|
+
visitTextNodes(child, visit);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
function parseCmsRef(value) {
|
|
233
|
+
if (!value) {
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
236
|
+
try {
|
|
237
|
+
const parsed = JSON.parse(value);
|
|
238
|
+
if (!parsed ||
|
|
239
|
+
typeof parsed !== "object" ||
|
|
240
|
+
!("collection" in parsed) ||
|
|
241
|
+
typeof parsed.collection !== "string" ||
|
|
242
|
+
!("id" in parsed) ||
|
|
243
|
+
typeof parsed.id !== "string") {
|
|
244
|
+
return undefined;
|
|
245
|
+
}
|
|
246
|
+
const field = "field" in parsed && typeof parsed.field === "string"
|
|
247
|
+
? parsed.field
|
|
248
|
+
: undefined;
|
|
249
|
+
return {
|
|
250
|
+
collection: parsed.collection,
|
|
251
|
+
...(field ? { field } : {}),
|
|
252
|
+
id: parsed.id,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
return undefined;
|
|
257
|
+
}
|
|
258
|
+
}
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
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";
|
|
3
4
|
export { createChatDeHpSiteWorker } from "./worker.js";
|
|
4
5
|
//# 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,wBAAwB,EAAE,MAAM,aAAa,CAAC"}
|
|
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,iCAAiC,EAAE,MAAM,gBAAgB,CAAC;AACnE,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.6",
|
|
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,34 @@
|
|
|
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
|
+
"./emdash": {
|
|
30
|
+
"types": "./dist/emdash-annotation.d.ts",
|
|
31
|
+
"default": "./dist/emdash-annotation.js"
|
|
32
|
+
},
|
|
25
33
|
"./runtime": {
|
|
26
34
|
"types": "./dist/runtime/index.d.ts",
|
|
27
35
|
"default": "./dist/runtime/index.js"
|
|
28
36
|
},
|
|
37
|
+
"./runtime/contracts": {
|
|
38
|
+
"types": "./dist/runtime/contracts.d.ts",
|
|
39
|
+
"default": "./dist/runtime/contracts.js"
|
|
40
|
+
},
|
|
41
|
+
"./runtime/annotation-capture": {
|
|
42
|
+
"types": "./dist/runtime/annotation-capture.d.ts",
|
|
43
|
+
"default": "./dist/runtime/annotation-capture.js"
|
|
44
|
+
},
|
|
45
|
+
"./runtime/capture-contract": {
|
|
46
|
+
"types": "./dist/runtime/capture-contract.d.ts",
|
|
47
|
+
"default": "./dist/runtime/capture-contract.js"
|
|
48
|
+
},
|
|
49
|
+
"./runtime/element-extractor": {
|
|
50
|
+
"types": "./dist/runtime/element-extractor.d.ts",
|
|
51
|
+
"default": "./dist/runtime/element-extractor.js"
|
|
52
|
+
},
|
|
29
53
|
"./control-plane": {
|
|
30
54
|
"types": "./dist/control-plane.d.ts",
|
|
31
55
|
"default": "./dist/control-plane.js"
|
|
@@ -66,6 +90,7 @@
|
|
|
66
90
|
"@types/node": "20",
|
|
67
91
|
"astro": "7.0.4",
|
|
68
92
|
"emdash": "0.31.1",
|
|
93
|
+
"happy-dom": "20.11.1",
|
|
69
94
|
"react": "19.2.7",
|
|
70
95
|
"react-dom": "19.2.7",
|
|
71
96
|
"typescript": "5.8.3",
|