@replohq/canopy-sdk 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/_vendor/replo-utils/lib/errors.d.ts +83 -0
- package/_vendor/replo-utils/lib/fonts.mjs +2 -40
- package/_vendor/replo-utils/lib/json.mjs +1 -1
- package/_vendor/replo-utils/lib/misc.mjs +2 -2
- package/_vendor/schemas/agentTools/customIntegrations/loaders/levanta.d.ts +49 -0
- package/_vendor/schemas/agentTools/customIntegrations/loaders/levanta.mjs +36 -0
- package/_vendor/schemas/agentTools/customIntegrations/loaders/product.d.ts +340 -0
- package/_vendor/schemas/agentTools/customIntegrations/loaders/product.mjs +51 -0
- package/_vendor/schemas/agentTools/customIntegrations/loaders/yotpo.d.ts +37 -0
- package/_vendor/schemas/agentTools/customIntegrations/loaders/yotpo.mjs +37 -0
- package/{cart/cart-schema.js → _vendor/schemas/cart.mjs} +17 -26
- package/_vendor/schemas/designLibrary.d.ts +4 -4
- package/_vendor/schemas/errors.d.ts +438 -0
- package/_vendor/schemas/errors.mjs +932 -0
- package/_vendor/schemas/generated/errors.d.ts +61 -0
- package/_vendor/schemas/generated/selectMode.d.ts +102 -0
- package/{loaders/loader-keys.d.ts → _vendor/schemas/loaderKeys.d.ts} +4 -4
- package/{loaders/loader-keys.js → _vendor/schemas/loaderKeys.mjs} +7 -8
- package/_vendor/schemas/objectType.d.ts +1038 -0
- package/_vendor/schemas/objectType.mjs +2 -0
- package/_vendor/schemas/registry.d.ts +539 -0
- package/_vendor/schemas/sandboxFiles.d.ts +36 -0
- package/_vendor/schemas/savedStyles.d.ts +2 -2
- package/_vendor/schemas/selectMode.d.ts +471 -0
- package/_vendor/schemas/selectMode.mjs +120 -4
- package/_vendor/schemas/sellingPlan.d.ts +60 -0
- package/_vendor/schemas/sellingPlan.mjs +1 -0
- package/cart/buy-now-action.js +3 -3
- package/cart/buy-now-action.js.map +2 -2
- package/cart/cart-provider.js +2 -2
- package/cart/cart-provider.js.map +2 -2
- package/cart/cart-types.d.ts +2 -1
- package/cart/cart-types.js.map +2 -2
- package/cart/hooks/use-add-to-cart.js +1 -1
- package/cart/hooks/use-add-to-cart.js.map +2 -2
- package/cart/hooks/use-buy-now.js +2 -2
- package/cart/hooks/use-buy-now.js.map +2 -2
- package/cart/utils/variant-to-cart-line.d.ts +1 -2
- package/cart/utils/variant-to-cart-line.js.map +1 -1
- package/chunk-4XLTENDR.mjs +33 -0
- package/chunk-A7EUNWRQ.mjs +765 -0
- package/{chunk-ME5W2TJM.mjs → chunk-OCB5XQYL.mjs} +2 -2
- package/chunk-QFYIXADC.mjs +42 -0
- package/editor/LinkInterceptor.js +4 -0
- package/editor/LinkInterceptor.js.map +2 -2
- package/editor/select-mode/EditorSelection.js +74 -1
- package/editor/select-mode/EditorSelection.js.map +2 -2
- package/editor/select-mode/descriptor/elementDescriptor.d.ts +13 -2
- package/editor/select-mode/descriptor/elementDescriptor.js +19 -31
- package/editor/select-mode/descriptor/elementDescriptor.js.map +2 -2
- package/editor/select-mode/descriptor/styleExtraction.d.ts +3 -0
- package/editor/select-mode/descriptor/styleExtraction.js +271 -0
- package/editor/select-mode/descriptor/styleExtraction.js.map +7 -0
- package/editor/select-mode/displayModeStore.d.ts +10 -0
- package/editor/select-mode/displayModeStore.js +47 -0
- package/editor/select-mode/displayModeStore.js.map +7 -0
- package/editor/select-mode/fast-refresh-relay.d.ts +3 -0
- package/editor/select-mode/fast-refresh-relay.js +35 -0
- package/editor/select-mode/fast-refresh-relay.js.map +7 -0
- package/editor/select-mode/fiber.d.ts +17 -0
- package/editor/select-mode/fiber.js +103 -34
- package/editor/select-mode/fiber.js.map +2 -2
- package/editor/select-mode/hooks/useEditModeStateMachine.d.ts +20 -0
- package/editor/select-mode/hooks/useEditModeStateMachine.js +226 -0
- package/editor/select-mode/hooks/useEditModeStateMachine.js.map +7 -0
- package/editor/select-mode/hooks/useOptimisticOverrides.d.ts +20 -0
- package/editor/select-mode/hooks/useOptimisticOverrides.js +284 -0
- package/editor/select-mode/hooks/useOptimisticOverrides.js.map +7 -0
- package/editor/select-mode/hooks/useParentMessaging.d.ts +17 -2
- package/editor/select-mode/hooks/useParentMessaging.js +66 -1
- package/editor/select-mode/hooks/useParentMessaging.js.map +2 -2
- package/editor/select-mode/hooks/useSelectModeController.js +5 -6
- package/editor/select-mode/hooks/useSelectModeController.js.map +2 -2
- package/editor/select-mode/hooks/useSelectionHover.js +16 -1
- package/editor/select-mode/hooks/useSelectionHover.js.map +2 -2
- package/editor/select-mode/hooks/useSelectionInteractions.d.ts +7 -2
- package/editor/select-mode/hooks/useSelectionInteractions.js +57 -18
- package/editor/select-mode/hooks/useSelectionInteractions.js.map +2 -2
- package/editor/select-mode/hooks/useSiblingResolution.d.ts +6 -0
- package/editor/select-mode/hooks/useSiblingResolution.js +59 -0
- package/editor/select-mode/hooks/useSiblingResolution.js.map +7 -0
- package/editor/select-mode/inlineTextMarks.d.ts +6 -0
- package/editor/select-mode/inlineTextMarks.js +25 -0
- package/editor/select-mode/inlineTextMarks.js.map +7 -0
- package/editor/select-mode/interactions/selectionGeometry.js +4 -0
- package/editor/select-mode/interactions/selectionGeometry.js.map +2 -2
- package/editor/select-mode/selectionFrame.d.ts +5 -0
- package/editor/select-mode/selectionFrame.js +25 -1
- package/editor/select-mode/selectionFrame.js.map +2 -2
- package/editor/select-mode/symbolicate.js +32 -10
- package/editor/select-mode/symbolicate.js.map +2 -2
- package/editor/select-mode/tiptapInlineEditor.d.ts +23 -0
- package/editor/select-mode/tiptapInlineEditor.js +120 -0
- package/editor/select-mode/tiptapInlineEditor.js.map +7 -0
- package/gateways/canopy-api.d.ts +3 -3
- package/gateways/canopy-api.js +3 -3
- package/gateways/canopy-api.js.map +2 -2
- package/loaders/collection-loader.d.ts +1 -1
- package/loaders/collection-loader.js +1 -1
- package/loaders/collection-loader.js.map +2 -2
- package/loaders/collection-products-loader.d.ts +1 -1
- package/loaders/collection-products-loader.js +1 -1
- package/loaders/collection-products-loader.js.map +2 -2
- package/loaders/invoke-loader.d.ts +2 -2
- package/loaders/invoke-loader.js +2 -2
- package/loaders/invoke-loader.js.map +2 -2
- package/loaders/levanta-product-loader.d.ts +1 -1
- package/loaders/levanta-product-loader.js +1 -1
- package/loaders/levanta-product-loader.js.map +2 -2
- package/loaders/okendo-reviews-loader.js +1 -1
- package/loaders/okendo-reviews-loader.js.map +2 -2
- package/loaders/prefetch-loaders.d.ts +1 -1
- package/loaders/prefetch-loaders.js.map +1 -1
- package/loaders/product-loader.d.ts +1 -1
- package/loaders/product-loader.js +1 -1
- package/loaders/product-loader.js.map +2 -2
- package/loaders/rebuy-recommendations-loader.js +1 -1
- package/loaders/rebuy-recommendations-loader.js.map +2 -2
- package/loaders/yotpo-review-aggregate-loader.d.ts +1 -1
- package/loaders/yotpo-review-aggregate-loader.js +1 -1
- package/loaders/yotpo-review-aggregate-loader.js.map +2 -2
- package/loaders/yotpo-reviews-loader.d.ts +1 -1
- package/loaders/yotpo-reviews-loader.js +1 -1
- package/loaders/yotpo-reviews-loader.js.map +2 -2
- package/package.json +9 -1
- package/cart/cart-schema.js.map +0 -7
- package/lib/canopy-error.d.ts +0 -25
- package/lib/canopy-error.js +0 -24
- package/lib/canopy-error.js.map +0 -7
- package/loaders/loader-keys.js.map +0 -7
- package/loaders/loader-schemas.d.ts +0 -755
- package/loaders/loader-schemas.js +0 -257
- package/loaders/loader-schemas.js.map +0 -7
- package/{cart/cart-schema.d.ts → _vendor/schemas/cart.d.ts} +0 -0
- package/{chunk-NCKKAFF7.mjs → chunk-ILGEM42C.mjs} +7 -7
|
@@ -16,18 +16,24 @@ import {
|
|
|
16
16
|
import { showSelectionFrame, showSelectionFrames } from "../selectionFrame";
|
|
17
17
|
import { IDLE_SESSION } from "../selectModeSession";
|
|
18
18
|
import { symbolicateSelectedElement } from "../symbolicate";
|
|
19
|
+
import { isTextEditableElement } from "./useEditModeStateMachine";
|
|
20
|
+
import { getSourceLocationSiblingSelectors } from "./useSiblingResolution";
|
|
21
|
+
const DOUBLE_CLICK_THRESHOLD_MS = 500;
|
|
19
22
|
async function maybeSymbolicate(data) {
|
|
20
23
|
return data.kind === "react-element" ? symbolicateSelectedElement(data) : data;
|
|
21
24
|
}
|
|
22
25
|
function useSelectionInteractions({
|
|
23
26
|
displayMode,
|
|
24
|
-
|
|
27
|
+
editingElementRef,
|
|
28
|
+
interactionSessionRef,
|
|
29
|
+
onBeginEditing
|
|
25
30
|
}) {
|
|
26
31
|
useEffect(() => {
|
|
27
32
|
if (displayMode !== "selection") {
|
|
28
33
|
return;
|
|
29
34
|
}
|
|
30
35
|
let dragAnimationFrameId = null;
|
|
36
|
+
let lastClick = null;
|
|
31
37
|
let dragCandidates = [];
|
|
32
38
|
const stopDragAnimation = () => {
|
|
33
39
|
if (dragAnimationFrameId === null) {
|
|
@@ -41,7 +47,11 @@ function useSelectionInteractions({
|
|
|
41
47
|
} = {}) => {
|
|
42
48
|
const currentSession = interactionSessionRef.current;
|
|
43
49
|
stopDragAnimation();
|
|
44
|
-
if (
|
|
50
|
+
if (currentSession.type !== "drag") {
|
|
51
|
+
dragCandidates = [];
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (notifyParentDragCleared && currentSession.hasExceededThreshold) {
|
|
45
55
|
window.parent.postMessage(
|
|
46
56
|
{
|
|
47
57
|
type: "replo:select:dragRectUpdated",
|
|
@@ -124,6 +134,9 @@ function useSelectionInteractions({
|
|
|
124
134
|
dragAnimationFrameId = requestAnimationFrame(syncDragRectToViewport);
|
|
125
135
|
};
|
|
126
136
|
const handlePointerDown = (event) => {
|
|
137
|
+
if (editingElementRef?.current && event.target instanceof Node && editingElementRef.current.contains(event.target)) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
127
140
|
event.preventDefault();
|
|
128
141
|
event.stopPropagation();
|
|
129
142
|
const scrollOffset = getDocumentScrollOffset();
|
|
@@ -170,15 +183,45 @@ function useSelectionInteractions({
|
|
|
170
183
|
targetElement,
|
|
171
184
|
pointerEvent
|
|
172
185
|
}) => {
|
|
173
|
-
const selectionElement = getNearestSelectableElement(targetElement)
|
|
186
|
+
const selectionElement = getNearestSelectableElement(targetElement);
|
|
174
187
|
const targetRect = selectionElement.getBoundingClientRect();
|
|
188
|
+
const clickPosition = {
|
|
189
|
+
x: pointerEvent.clientX,
|
|
190
|
+
y: pointerEvent.clientY
|
|
191
|
+
};
|
|
192
|
+
const scrollOffset = getDocumentScrollOffset();
|
|
193
|
+
showSelectionFrame({
|
|
194
|
+
variant: "element",
|
|
195
|
+
pageRect: {
|
|
196
|
+
x: targetRect.left + scrollOffset.left,
|
|
197
|
+
y: targetRect.top + scrollOffset.top,
|
|
198
|
+
width: targetRect.width,
|
|
199
|
+
height: targetRect.height
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
const now = pointerEvent.timeStamp;
|
|
203
|
+
const previousClick = lastClick;
|
|
204
|
+
if (previousClick && previousClick.target === selectionElement && now - previousClick.time <= DOUBLE_CLICK_THRESHOLD_MS && isTextEditableElement(selectionElement)) {
|
|
205
|
+
lastClick = null;
|
|
206
|
+
onBeginEditing({
|
|
207
|
+
element: selectionElement,
|
|
208
|
+
descriptorPromise: previousClick.descriptorPromise
|
|
209
|
+
});
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
175
212
|
const data = buildElementDescriptor({
|
|
176
213
|
element: selectionElement,
|
|
177
|
-
clickPosition
|
|
178
|
-
|
|
179
|
-
y: pointerEvent.clientY
|
|
180
|
-
}
|
|
214
|
+
clickPosition,
|
|
215
|
+
siblingSelectors: selectionElement instanceof HTMLElement ? getSourceLocationSiblingSelectors({ element: selectionElement }) : []
|
|
181
216
|
});
|
|
217
|
+
lastClick = {
|
|
218
|
+
descriptorPromise: Promise.resolve(data),
|
|
219
|
+
target: selectionElement,
|
|
220
|
+
time: now
|
|
221
|
+
};
|
|
222
|
+
if (!selectionElement.isConnected) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
182
225
|
interactionSessionRef.current = {
|
|
183
226
|
type: "element",
|
|
184
227
|
element: selectionElement,
|
|
@@ -188,16 +231,6 @@ function useSelectionInteractions({
|
|
|
188
231
|
},
|
|
189
232
|
data
|
|
190
233
|
};
|
|
191
|
-
const scrollOffset = getDocumentScrollOffset();
|
|
192
|
-
showSelectionFrame({
|
|
193
|
-
variant: "element",
|
|
194
|
-
pageRect: {
|
|
195
|
-
x: targetRect.left + scrollOffset.left,
|
|
196
|
-
y: targetRect.top + scrollOffset.top,
|
|
197
|
-
width: targetRect.width,
|
|
198
|
-
height: targetRect.height
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
234
|
void maybeSymbolicate(data).then((symbolicated) => {
|
|
202
235
|
window.parent.postMessage(
|
|
203
236
|
{
|
|
@@ -209,6 +242,9 @@ function useSelectionInteractions({
|
|
|
209
242
|
});
|
|
210
243
|
};
|
|
211
244
|
const handlePointerUp = (event) => {
|
|
245
|
+
if (editingElementRef?.current && event.target instanceof Node && editingElementRef.current.contains(event.target)) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
212
248
|
const snapshot = interactionSessionRef.current;
|
|
213
249
|
const wasDragging = snapshot.type === "drag" ? snapshot.hasExceededThreshold : false;
|
|
214
250
|
const dragStart = snapshot.type === "drag" ? snapshot.dragStart : null;
|
|
@@ -291,6 +327,9 @@ function useSelectionInteractions({
|
|
|
291
327
|
);
|
|
292
328
|
};
|
|
293
329
|
const handleClick = (event) => {
|
|
330
|
+
if (editingElementRef?.current && event.target instanceof Node && editingElementRef.current.contains(event.target)) {
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
294
333
|
event.preventDefault();
|
|
295
334
|
event.stopPropagation();
|
|
296
335
|
};
|
|
@@ -323,7 +362,7 @@ function useSelectionInteractions({
|
|
|
323
362
|
window.removeEventListener("resize", handleViewportChangeDuringDrag);
|
|
324
363
|
resetDragState();
|
|
325
364
|
};
|
|
326
|
-
}, [displayMode, interactionSessionRef]);
|
|
365
|
+
}, [displayMode, editingElementRef, interactionSessionRef, onBeginEditing]);
|
|
327
366
|
}
|
|
328
367
|
export {
|
|
329
368
|
useSelectionInteractions
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../editor/select-mode/hooks/useSelectionInteractions.ts"],
|
|
4
|
-
"sourcesContent": ["import type { MutableRefObject } from \"react\";\nimport type { DisplayMode, SelectableData } from \"schemas/generated/selectMode\";\nimport type { DragCandidate } from \"../interactions/selectionGeometry\";\nimport type { SelectModeInteractionSession } from \"../selectModeSession\";\n\nimport { useEffect } from \"react\";\n\nimport {\n buildElementDescriptor,\n getNearestSelectableElement,\n} from \"../descriptor/elementDescriptor\";\nimport {\n collectDragCandidates,\n getCandidatesInSelection,\n getDocumentScrollOffset,\n getDragPositionFromClient,\n getElementAnchor,\n getPageRectFromViewportRect,\n getViewportRectFromPageRect,\n getViewportSelectionRect,\n} from \"../interactions/selectionGeometry\";\nimport { showSelectionFrame, showSelectionFrames } from \"../selectionFrame\";\nimport { IDLE_SESSION } from \"../selectModeSession\";\nimport { symbolicateSelectedElement } from \"../symbolicate\";\n\n// React fibers carry only Turbopack chunk paths; resolving them to the\n// user's source file is async and only meaningful for \"react-element\"\n// kinds. Plan selectables already point at the right thing.\nasync function maybeSymbolicate(data: SelectableData): Promise<SelectableData> {\n return data.kind === \"react-element\"\n ? symbolicateSelectedElement(data)\n : data;\n}\n\n/**\n * Owns the iframe-side pointer interactions that drive selection:\n *\n * - On `pointerdown` we open a `drag` session (storing both client + page\n * coords plus the current scroll offset). We don't yet know if this will\n * become a click or an actual drag.\n * - On `pointermove` we update the drag rect and post `DRAG_RECT_UPDATED`\n * to the parent so the live drag rectangle can render. We only flip\n * `hasExceededThreshold` once the rect grows past 6\u00D76 px so that a tiny\n * accidental drag still resolves as a click.\n * - On `pointerup` we either:\n * - resolve as an `ELEMENT_SELECTED` (single click / sub-threshold drag)\n * - resolve as an `AREA_SELECTED` (drag past threshold), filtering the\n * candidates snapshotted at drag start against the final rectangle to\n * enumerate which descendants the user enclosed.\n * - During an active drag a `requestAnimationFrame` loop keeps the rect in\n * sync with the page scroll so the rectangle visually \"sticks\" to the\n * page rather than the viewport.\n *\n * We capture-listen and `preventDefault`/`stopPropagation` clicks so the\n * underlying page can't navigate or trigger handlers while the user is\n * working in selection mode.\n *\n * @author Kevin O'Connell 2026-04-17\n */\nexport function useSelectionInteractions({\n displayMode,\n interactionSessionRef,\n}: {\n displayMode: DisplayMode;\n interactionSessionRef: MutableRefObject<SelectModeInteractionSession>;\n}) {\n // eslint-disable-next-line replo/no-use-effect -- Legacy effect - may or may not be necessary\n useEffect(() => {\n if (displayMode !== \"selection\") {\n return;\n }\n\n let dragAnimationFrameId: number | null = null;\n // Snapshot of the page's meaningful elements + their page rects, taken\n // once when a drag begins so per-move hit-testing avoids a full-DOM scan.\n let dragCandidates: DragCandidate[] = [];\n\n const stopDragAnimation = () => {\n if (dragAnimationFrameId === null) {\n return;\n }\n\n cancelAnimationFrame(dragAnimationFrameId);\n dragAnimationFrameId = null;\n };\n\n // `notifyParentDragCleared` posts a null drag rect so the parent tears\n // down the live drag overlay. The area-commit path suppresses it: the\n // parent maps a null drag rect to `selection = none`, which round-trips\n // back as `setSelectionType(\"none\")` and wipes the in-iframe frames we're\n // about to paint. The follow-up `areaSelected` supersedes the drag overlay\n // on its own, so the null post is pure collateral damage there.\n const resetDragState = ({\n notifyParentDragCleared = true,\n }: { notifyParentDragCleared?: boolean } = {}) => {\n const currentSession = interactionSessionRef.current;\n\n stopDragAnimation();\n\n if (\n notifyParentDragCleared &&\n currentSession.type === \"drag\" &&\n currentSession.hasExceededThreshold\n ) {\n window.parent.postMessage(\n {\n type: \"replo:select:dragRectUpdated\",\n dragRect: null,\n selectionRects: [],\n },\n \"*\",\n );\n }\n\n dragCandidates = [];\n interactionSessionRef.current = IDLE_SESSION;\n };\n\n const postCurrentDragRect = () => {\n const session = interactionSessionRef.current;\n if (session.type !== \"drag\") {\n return;\n }\n\n const rect = getViewportSelectionRect({\n dragStart: session.dragStart,\n dragCurrent: session.dragCurrent,\n scrollOffset: session.scrollOffset,\n });\n\n if (\n rect.width <= 6 &&\n rect.height <= 6 &&\n !session.hasExceededThreshold\n ) {\n return;\n }\n\n if (!session.hasExceededThreshold) {\n interactionSessionRef.current = {\n ...session,\n hasExceededThreshold: true,\n };\n }\n\n // Cheap hit-test against the candidates we snapshotted at drag start,\n // projected back to viewport coords so the parent can paint a live\n // highlight on each element the drag will capture. No DOM scan here.\n const selectionPageRect = getPageRectFromViewportRect({\n rect,\n scrollOffset: session.scrollOffset,\n });\n const selectionRects = getCandidatesInSelection({\n candidates: dragCandidates,\n selectionPageRect,\n }).map((candidate) => ({\n id: candidate.id,\n rect: getViewportRectFromPageRect({\n rect: candidate.pageRect,\n scrollOffset: session.scrollOffset,\n }),\n }));\n\n window.parent.postMessage(\n {\n type: \"replo:select:dragRectUpdated\",\n dragRect: rect,\n selectionRects,\n },\n \"*\",\n );\n };\n\n const syncDragRectToViewport = () => {\n const session = interactionSessionRef.current;\n if (session.type !== \"drag\") {\n dragAnimationFrameId = null;\n return;\n }\n\n const nextScrollOffset = getDocumentScrollOffset();\n const nextDragCurrent = getDragPositionFromClient({\n clientX: session.dragCurrent.clientX,\n clientY: session.dragCurrent.clientY,\n scrollOffset: nextScrollOffset,\n });\n\n if (\n nextDragCurrent.pageX !== session.dragCurrent.pageX ||\n nextDragCurrent.pageY !== session.dragCurrent.pageY\n ) {\n interactionSessionRef.current = {\n ...session,\n dragCurrent: nextDragCurrent,\n scrollOffset: nextScrollOffset,\n };\n postCurrentDragRect();\n } else {\n interactionSessionRef.current = {\n ...session,\n scrollOffset: nextScrollOffset,\n };\n }\n\n dragAnimationFrameId = requestAnimationFrame(syncDragRectToViewport);\n };\n\n const handlePointerDown = (event: PointerEvent) => {\n event.preventDefault();\n event.stopPropagation();\n\n const scrollOffset = getDocumentScrollOffset();\n const dragStart = getDragPositionFromClient({\n clientX: event.clientX,\n clientY: event.clientY,\n scrollOffset,\n });\n interactionSessionRef.current = {\n type: \"drag\",\n dragStart,\n dragCurrent: dragStart,\n scrollOffset,\n hasExceededThreshold: false,\n };\n dragCandidates = collectDragCandidates(scrollOffset);\n\n if (dragAnimationFrameId === null) {\n dragAnimationFrameId = requestAnimationFrame(syncDragRectToViewport);\n }\n };\n\n const handlePointerMove = (event: PointerEvent) => {\n const session = interactionSessionRef.current;\n if (session.type !== \"drag\") {\n return;\n }\n\n interactionSessionRef.current = {\n ...session,\n dragCurrent: getDragPositionFromClient({\n clientX: event.clientX,\n clientY: event.clientY,\n scrollOffset: getDocumentScrollOffset(),\n }),\n };\n postCurrentDragRect();\n };\n\n const handleViewportChangeDuringDrag = () => {\n const session = interactionSessionRef.current;\n if (session.type !== \"drag\" || dragAnimationFrameId !== null) {\n return;\n }\n\n dragAnimationFrameId = requestAnimationFrame(syncDragRectToViewport);\n };\n\n const commitElementSelection = ({\n targetElement,\n pointerEvent,\n }: {\n targetElement: Element;\n pointerEvent: PointerEvent;\n }) => {\n const selectionElement =\n getNearestSelectableElement(targetElement) ?? targetElement;\n const targetRect = selectionElement.getBoundingClientRect();\n const data = buildElementDescriptor({\n element: selectionElement,\n clickPosition: {\n x: pointerEvent.clientX,\n y: pointerEvent.clientY,\n },\n });\n interactionSessionRef.current = {\n type: \"element\",\n element: selectionElement,\n clickPosition: {\n x: pointerEvent.clientX - targetRect.left,\n y: pointerEvent.clientY - targetRect.top,\n },\n data,\n };\n\n // Paint the in-iframe selection frame synchronously for instant\n // feedback \u2014 symbolicate is a network roundtrip and we don't want\n // the visual selection to wait on it.\n const scrollOffset = getDocumentScrollOffset();\n showSelectionFrame({\n variant: \"element\",\n pageRect: {\n x: targetRect.left + scrollOffset.left,\n y: targetRect.top + scrollOffset.top,\n width: targetRect.width,\n height: targetRect.height,\n },\n });\n\n // Resolve compiled Turbopack chunk paths to the original `.tsx` paths\n // via Next.js's dev-only `/__nextjs_original-stack-frames` endpoint\n // before posting. Without this the parent receives a chunk URL and\n // the agent prompt points at bundled output instead of user source.\n void maybeSymbolicate(data).then((symbolicated) => {\n window.parent.postMessage(\n {\n type: \"replo:select:elementSelected\",\n data: symbolicated,\n },\n \"*\",\n );\n });\n };\n\n const handlePointerUp = (event: PointerEvent) => {\n const snapshot = interactionSessionRef.current;\n const wasDragging =\n snapshot.type === \"drag\" ? snapshot.hasExceededThreshold : false;\n const dragStart = snapshot.type === \"drag\" ? snapshot.dragStart : null;\n const dragCurrent =\n snapshot.type === \"drag\" ? snapshot.dragCurrent : null;\n const scrollOffset =\n snapshot.type === \"drag\"\n ? snapshot.scrollOffset\n : getDocumentScrollOffset();\n // `resetDragState` clears `dragCandidates`, so grab them first \u2014 the\n // final committed set is the same cached candidates the live preview\n // used, so preview and result never disagree.\n const candidates = dragCandidates;\n\n // Suppress the null drag-rect post: if this resolves to an area\n // selection it would otherwise flash the parent to `selection = none`\n // and wipe the frames we paint below. Click/empty-drag paths don't\n // depend on it (a sub-threshold drag never posted a rect to clear).\n resetDragState({ notifyParentDragCleared: false });\n\n if (!dragStart || snapshot.type !== \"drag\") {\n const targetElement = event.target;\n if (!(targetElement instanceof Element)) {\n return;\n }\n\n commitElementSelection({\n targetElement,\n pointerEvent: event,\n });\n return;\n }\n\n const resolvedDragCurrent = dragCurrent ?? dragStart;\n const selectionRect = getViewportSelectionRect({\n dragStart,\n dragCurrent: resolvedDragCurrent,\n scrollOffset,\n });\n\n if (!wasDragging) {\n const targetElement = event.target;\n if (!(targetElement instanceof Element)) {\n return;\n }\n\n commitElementSelection({\n targetElement,\n pointerEvent: event,\n });\n return;\n }\n\n const pageRect = getPageRectFromViewportRect({\n rect: selectionRect,\n scrollOffset,\n });\n\n const selectedCandidates = getCandidatesInSelection({\n candidates,\n selectionPageRect: pageRect,\n });\n const items = selectedCandidates.map((candidate) => {\n return buildElementDescriptor({\n element: candidate.element,\n clickPosition: getElementAnchor({\n element: candidate.element,\n selectionRect,\n }),\n });\n });\n\n interactionSessionRef.current = {\n type: \"area\",\n pageRect,\n items,\n };\n\n // Highlight each captured element so the committed area selection\n // \"sticks\" inside the iframe \u2014 matching how a single click stays\n // outlined \u2014 rather than drawing one faint box over the drag region.\n showSelectionFrames({\n frames: selectedCandidates.map((candidate) => ({\n variant: \"area\" as const,\n pageRect: {\n x: candidate.pageRect.x,\n y: candidate.pageRect.y,\n width: candidate.pageRect.width,\n height: candidate.pageRect.height,\n },\n })),\n });\n\n void Promise.all(items.map(maybeSymbolicate)).then(\n (symbolicatedItems) => {\n window.parent.postMessage(\n {\n type: \"replo:select:areaSelected\",\n rect: selectionRect,\n items: symbolicatedItems,\n },\n \"*\",\n );\n },\n );\n };\n\n const handleClick = (event: MouseEvent) => {\n event.preventDefault();\n event.stopPropagation();\n };\n\n const handlePointerCancel = () => {\n resetDragState();\n };\n\n const handleWindowBlur = () => {\n resetDragState();\n };\n\n document.addEventListener(\"pointerdown\", handlePointerDown, true);\n document.addEventListener(\"pointermove\", handlePointerMove, true);\n document.addEventListener(\"pointerup\", handlePointerUp, true);\n document.addEventListener(\"pointercancel\", handlePointerCancel, true);\n document.addEventListener(\"click\", handleClick, true);\n document.addEventListener(\"scroll\", handleViewportChangeDuringDrag, true);\n window.addEventListener(\"blur\", handleWindowBlur);\n window.addEventListener(\"resize\", handleViewportChangeDuringDrag);\n\n return () => {\n document.removeEventListener(\"pointerdown\", handlePointerDown, true);\n document.removeEventListener(\"pointermove\", handlePointerMove, true);\n document.removeEventListener(\"pointerup\", handlePointerUp, true);\n document.removeEventListener(\"pointercancel\", handlePointerCancel, true);\n document.removeEventListener(\"click\", handleClick, true);\n document.removeEventListener(\n \"scroll\",\n handleViewportChangeDuringDrag,\n true,\n );\n window.removeEventListener(\"blur\", handleWindowBlur);\n window.removeEventListener(\"resize\", handleViewportChangeDuringDrag);\n resetDragState();\n };\n }, [displayMode, interactionSessionRef]);\n}\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import type { MutableRefObject } from \"react\";\nimport type {\n DisplayMode,\n SelectableData,\n SelectModeClickPosition,\n} from \"schemas/generated/selectMode\";\nimport type { DragCandidate } from \"../interactions/selectionGeometry\";\nimport type { SelectModeInteractionSession } from \"../selectModeSession\";\n\nimport { useEffect } from \"react\";\n\nimport {\n buildElementDescriptor,\n getNearestSelectableElement,\n} from \"../descriptor/elementDescriptor\";\nimport {\n collectDragCandidates,\n getCandidatesInSelection,\n getDocumentScrollOffset,\n getDragPositionFromClient,\n getElementAnchor,\n getPageRectFromViewportRect,\n getViewportRectFromPageRect,\n getViewportSelectionRect,\n} from \"../interactions/selectionGeometry\";\nimport { showSelectionFrame, showSelectionFrames } from \"../selectionFrame\";\nimport { IDLE_SESSION } from \"../selectModeSession\";\nimport { symbolicateSelectedElement } from \"../symbolicate\";\nimport { isTextEditableElement } from \"./useEditModeStateMachine\";\nimport { getSourceLocationSiblingSelectors } from \"./useSiblingResolution\";\n\nconst DOUBLE_CLICK_THRESHOLD_MS = 500;\n\n// React fibers carry only Turbopack chunk paths; resolving them to the\n// user's source file is async and only meaningful for \"react-element\"\n// kinds. Plan selectables already point at the right thing.\nasync function maybeSymbolicate(data: SelectableData): Promise<SelectableData> {\n return data.kind === \"react-element\"\n ? symbolicateSelectedElement(data)\n : data;\n}\n\n/**\n * Owns the iframe-side pointer interactions that drive selection:\n *\n * - On `pointerdown` we open a `drag` session (storing both client + page\n * coords plus the current scroll offset). We don't yet know if this will\n * become a click or an actual drag.\n * - On `pointermove` we update the drag rect and post `DRAG_RECT_UPDATED`\n * to the parent so the live drag rectangle can render. We only flip\n * `hasExceededThreshold` once the rect grows past 6\u00D76 px so that a tiny\n * accidental drag still resolves as a click.\n * - On `pointerup` we either:\n * - resolve as an `ELEMENT_SELECTED` (single click / sub-threshold drag)\n * - resolve as an `AREA_SELECTED` (drag past threshold), filtering the\n * candidates snapshotted at drag start against the final rectangle to\n * enumerate which descendants the user enclosed.\n * - During an active drag a `requestAnimationFrame` loop keeps the rect in\n * sync with the page scroll so the rectangle visually \"sticks\" to the\n * page rather than the viewport.\n *\n * We capture-listen and `preventDefault`/`stopPropagation` clicks so the\n * underlying page can't navigate or trigger handlers while the user is\n * working in selection mode.\n *\n * @author Kevin O'Connell 2026-04-17\n */\nexport function useSelectionInteractions({\n displayMode,\n editingElementRef,\n interactionSessionRef,\n onBeginEditing,\n}: {\n displayMode: DisplayMode;\n editingElementRef?: MutableRefObject<HTMLElement | null>;\n interactionSessionRef: MutableRefObject<SelectModeInteractionSession>;\n onBeginEditing: (args: {\n element: Element;\n descriptorPromise: Promise<SelectableData>;\n }) => void;\n}) {\n // eslint-disable-next-line replo/no-use-effect -- Legacy effect - may or may not be necessary\n useEffect(() => {\n if (displayMode !== \"selection\") {\n return;\n }\n\n let dragAnimationFrameId: number | null = null;\n let lastClick: {\n descriptorPromise: Promise<SelectableData>;\n target: Element;\n time: number;\n } | null = null;\n // Snapshot of the page's meaningful elements + their page rects, taken\n // once when a drag begins so per-move hit-testing avoids a full-DOM scan.\n let dragCandidates: DragCandidate[] = [];\n\n const stopDragAnimation = () => {\n if (dragAnimationFrameId === null) {\n return;\n }\n\n cancelAnimationFrame(dragAnimationFrameId);\n dragAnimationFrameId = null;\n };\n\n // `notifyParentDragCleared` posts a null drag rect so the parent tears\n // down the live drag overlay. The area-commit path suppresses it: the\n // parent maps a null drag rect to `selection = none`, which round-trips\n // back as `setSelectionType(\"none\")` and wipes the in-iframe frames we're\n // about to paint. The follow-up `areaSelected` supersedes the drag overlay\n // on its own, so the null post is pure collateral damage there.\n const resetDragState = ({\n notifyParentDragCleared = true,\n }: { notifyParentDragCleared?: boolean } = {}) => {\n const currentSession = interactionSessionRef.current;\n\n stopDragAnimation();\n\n if (currentSession.type !== \"drag\") {\n dragCandidates = [];\n return;\n }\n\n if (notifyParentDragCleared && currentSession.hasExceededThreshold) {\n window.parent.postMessage(\n {\n type: \"replo:select:dragRectUpdated\",\n dragRect: null,\n selectionRects: [],\n },\n \"*\",\n );\n }\n\n dragCandidates = [];\n interactionSessionRef.current = IDLE_SESSION;\n };\n\n const postCurrentDragRect = () => {\n const session = interactionSessionRef.current;\n if (session.type !== \"drag\") {\n return;\n }\n\n const rect = getViewportSelectionRect({\n dragStart: session.dragStart,\n dragCurrent: session.dragCurrent,\n scrollOffset: session.scrollOffset,\n });\n\n if (\n rect.width <= 6 &&\n rect.height <= 6 &&\n !session.hasExceededThreshold\n ) {\n return;\n }\n\n if (!session.hasExceededThreshold) {\n interactionSessionRef.current = {\n ...session,\n hasExceededThreshold: true,\n };\n }\n\n // Cheap hit-test against the candidates we snapshotted at drag start,\n // projected back to viewport coords so the parent can paint a live\n // highlight on each element the drag will capture. No DOM scan here.\n const selectionPageRect = getPageRectFromViewportRect({\n rect,\n scrollOffset: session.scrollOffset,\n });\n const selectionRects = getCandidatesInSelection({\n candidates: dragCandidates,\n selectionPageRect,\n }).map((candidate) => ({\n id: candidate.id,\n rect: getViewportRectFromPageRect({\n rect: candidate.pageRect,\n scrollOffset: session.scrollOffset,\n }),\n }));\n\n window.parent.postMessage(\n {\n type: \"replo:select:dragRectUpdated\",\n dragRect: rect,\n selectionRects,\n },\n \"*\",\n );\n };\n\n const syncDragRectToViewport = () => {\n const session = interactionSessionRef.current;\n if (session.type !== \"drag\") {\n dragAnimationFrameId = null;\n return;\n }\n\n const nextScrollOffset = getDocumentScrollOffset();\n const nextDragCurrent = getDragPositionFromClient({\n clientX: session.dragCurrent.clientX,\n clientY: session.dragCurrent.clientY,\n scrollOffset: nextScrollOffset,\n });\n\n if (\n nextDragCurrent.pageX !== session.dragCurrent.pageX ||\n nextDragCurrent.pageY !== session.dragCurrent.pageY\n ) {\n interactionSessionRef.current = {\n ...session,\n dragCurrent: nextDragCurrent,\n scrollOffset: nextScrollOffset,\n };\n postCurrentDragRect();\n } else {\n interactionSessionRef.current = {\n ...session,\n scrollOffset: nextScrollOffset,\n };\n }\n\n dragAnimationFrameId = requestAnimationFrame(syncDragRectToViewport);\n };\n\n const handlePointerDown = (event: PointerEvent) => {\n if (\n editingElementRef?.current &&\n event.target instanceof Node &&\n editingElementRef.current.contains(event.target)\n ) {\n return;\n }\n event.preventDefault();\n event.stopPropagation();\n\n const scrollOffset = getDocumentScrollOffset();\n const dragStart = getDragPositionFromClient({\n clientX: event.clientX,\n clientY: event.clientY,\n scrollOffset,\n });\n interactionSessionRef.current = {\n type: \"drag\",\n dragStart,\n dragCurrent: dragStart,\n scrollOffset,\n hasExceededThreshold: false,\n };\n dragCandidates = collectDragCandidates(scrollOffset);\n\n if (dragAnimationFrameId === null) {\n dragAnimationFrameId = requestAnimationFrame(syncDragRectToViewport);\n }\n };\n\n const handlePointerMove = (event: PointerEvent) => {\n const session = interactionSessionRef.current;\n if (session.type !== \"drag\") {\n return;\n }\n\n interactionSessionRef.current = {\n ...session,\n dragCurrent: getDragPositionFromClient({\n clientX: event.clientX,\n clientY: event.clientY,\n scrollOffset: getDocumentScrollOffset(),\n }),\n };\n postCurrentDragRect();\n };\n\n const handleViewportChangeDuringDrag = () => {\n const session = interactionSessionRef.current;\n if (session.type !== \"drag\" || dragAnimationFrameId !== null) {\n return;\n }\n\n dragAnimationFrameId = requestAnimationFrame(syncDragRectToViewport);\n };\n\n const commitElementSelection = ({\n targetElement,\n pointerEvent,\n }: {\n targetElement: Element;\n pointerEvent: PointerEvent;\n }) => {\n const selectionElement = getNearestSelectableElement(targetElement);\n const targetRect = selectionElement.getBoundingClientRect();\n const clickPosition: SelectModeClickPosition = {\n x: pointerEvent.clientX,\n y: pointerEvent.clientY,\n };\n\n // Paint the in-iframe selection frame synchronously for instant\n // feedback \u2014 symbolicate is a network roundtrip and we don't want\n // the visual selection to wait on it.\n const scrollOffset = getDocumentScrollOffset();\n showSelectionFrame({\n variant: \"element\",\n pageRect: {\n x: targetRect.left + scrollOffset.left,\n y: targetRect.top + scrollOffset.top,\n width: targetRect.width,\n height: targetRect.height,\n },\n });\n\n const now = pointerEvent.timeStamp;\n const previousClick = lastClick;\n if (\n previousClick &&\n previousClick.target === selectionElement &&\n now - previousClick.time <= DOUBLE_CLICK_THRESHOLD_MS &&\n isTextEditableElement(selectionElement)\n ) {\n lastClick = null;\n onBeginEditing({\n element: selectionElement,\n descriptorPromise: previousClick.descriptorPromise,\n });\n return;\n }\n\n // NOTE (Noah, 2026-07-24): Commit the selection immediately rather than\n // deferring it behind the double-click window. A single click always\n // selects, and a double-click is just \"select + edit\", so there's nothing\n // to suppress \u2014 waiting only added a full DOUBLE_CLICK_THRESHOLD_MS of\n // latency to every click and left `interactionSessionRef` non-element in\n // the gap. Double-click is still detected via the `lastClick` timestamp\n // above; the follow-up click reuses this descriptor to open the editor.\n const data = buildElementDescriptor({\n element: selectionElement,\n clickPosition,\n siblingSelectors:\n selectionElement instanceof HTMLElement\n ? getSourceLocationSiblingSelectors({ element: selectionElement })\n : [],\n });\n lastClick = {\n descriptorPromise: Promise.resolve(data),\n target: selectionElement,\n time: now,\n };\n\n if (!selectionElement.isConnected) {\n return;\n }\n interactionSessionRef.current = {\n type: \"element\",\n element: selectionElement,\n clickPosition: {\n x: pointerEvent.clientX - targetRect.left,\n y: pointerEvent.clientY - targetRect.top,\n },\n data,\n };\n void maybeSymbolicate(data).then((symbolicated) => {\n window.parent.postMessage(\n {\n type: \"replo:select:elementSelected\",\n data: symbolicated,\n },\n \"*\",\n );\n });\n };\n\n const handlePointerUp = (event: PointerEvent) => {\n // Clicks inside the element being edited belong to the inline editor, not\n // select mode. Without this guard the double-click detection below re-runs\n // `onBeginEditing` on the same element (e.g. when repositioning the\n // caret), rebuilding the editor over itself and wiping the content.\n // Mirrors the guards in `handlePointerDown` and `handleClick`.\n if (\n editingElementRef?.current &&\n event.target instanceof Node &&\n editingElementRef.current.contains(event.target)\n ) {\n return;\n }\n const snapshot = interactionSessionRef.current;\n const wasDragging =\n snapshot.type === \"drag\" ? snapshot.hasExceededThreshold : false;\n const dragStart = snapshot.type === \"drag\" ? snapshot.dragStart : null;\n const dragCurrent =\n snapshot.type === \"drag\" ? snapshot.dragCurrent : null;\n const scrollOffset =\n snapshot.type === \"drag\"\n ? snapshot.scrollOffset\n : getDocumentScrollOffset();\n // `resetDragState` clears `dragCandidates`, so grab them first \u2014 the\n // final committed set is the same cached candidates the live preview\n // used, so preview and result never disagree.\n const candidates = dragCandidates;\n\n // Suppress the null drag-rect post: if this resolves to an area\n // selection it would otherwise flash the parent to `selection = none`\n // and wipe the frames we paint below. Click/empty-drag paths don't\n // depend on it (a sub-threshold drag never posted a rect to clear).\n resetDragState({ notifyParentDragCleared: false });\n\n if (!dragStart || snapshot.type !== \"drag\") {\n const targetElement = event.target;\n if (!(targetElement instanceof Element)) {\n return;\n }\n\n commitElementSelection({\n targetElement,\n pointerEvent: event,\n });\n return;\n }\n\n const resolvedDragCurrent = dragCurrent ?? dragStart;\n const selectionRect = getViewportSelectionRect({\n dragStart,\n dragCurrent: resolvedDragCurrent,\n scrollOffset,\n });\n\n if (!wasDragging) {\n const targetElement = event.target;\n if (!(targetElement instanceof Element)) {\n return;\n }\n\n commitElementSelection({\n targetElement,\n pointerEvent: event,\n });\n return;\n }\n\n const pageRect = getPageRectFromViewportRect({\n rect: selectionRect,\n scrollOffset,\n });\n\n const selectedCandidates = getCandidatesInSelection({\n candidates,\n selectionPageRect: pageRect,\n });\n const items = selectedCandidates.map((candidate) => {\n return buildElementDescriptor({\n element: candidate.element,\n clickPosition: getElementAnchor({\n element: candidate.element,\n selectionRect,\n }),\n });\n });\n\n interactionSessionRef.current = {\n type: \"area\",\n pageRect,\n items,\n };\n\n // Highlight each captured element so the committed area selection\n // \"sticks\" inside the iframe \u2014 matching how a single click stays\n // outlined \u2014 rather than drawing one faint box over the drag region.\n showSelectionFrames({\n frames: selectedCandidates.map((candidate) => ({\n variant: \"area\" as const,\n pageRect: {\n x: candidate.pageRect.x,\n y: candidate.pageRect.y,\n width: candidate.pageRect.width,\n height: candidate.pageRect.height,\n },\n })),\n });\n\n void Promise.all(items.map(maybeSymbolicate)).then(\n (symbolicatedItems) => {\n window.parent.postMessage(\n {\n type: \"replo:select:areaSelected\",\n rect: selectionRect,\n items: symbolicatedItems,\n },\n \"*\",\n );\n },\n );\n };\n\n const handleClick = (event: MouseEvent) => {\n if (\n editingElementRef?.current &&\n event.target instanceof Node &&\n editingElementRef.current.contains(event.target)\n ) {\n return;\n }\n event.preventDefault();\n event.stopPropagation();\n };\n\n const handlePointerCancel = () => {\n resetDragState();\n };\n\n const handleWindowBlur = () => {\n resetDragState();\n };\n\n document.addEventListener(\"pointerdown\", handlePointerDown, true);\n document.addEventListener(\"pointermove\", handlePointerMove, true);\n document.addEventListener(\"pointerup\", handlePointerUp, true);\n document.addEventListener(\"pointercancel\", handlePointerCancel, true);\n document.addEventListener(\"click\", handleClick, true);\n document.addEventListener(\"scroll\", handleViewportChangeDuringDrag, true);\n window.addEventListener(\"blur\", handleWindowBlur);\n window.addEventListener(\"resize\", handleViewportChangeDuringDrag);\n\n return () => {\n document.removeEventListener(\"pointerdown\", handlePointerDown, true);\n document.removeEventListener(\"pointermove\", handlePointerMove, true);\n document.removeEventListener(\"pointerup\", handlePointerUp, true);\n document.removeEventListener(\"pointercancel\", handlePointerCancel, true);\n document.removeEventListener(\"click\", handleClick, true);\n document.removeEventListener(\n \"scroll\",\n handleViewportChangeDuringDrag,\n true,\n );\n window.removeEventListener(\"blur\", handleWindowBlur);\n window.removeEventListener(\"resize\", handleViewportChangeDuringDrag);\n resetDragState();\n };\n }, [displayMode, editingElementRef, interactionSessionRef, onBeginEditing]);\n}\n"],
|
|
5
|
+
"mappings": "AASA,SAAS,iBAAiB;AAE1B;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,oBAAoB,2BAA2B;AACxD,SAAS,oBAAoB;AAC7B,SAAS,kCAAkC;AAC3C,SAAS,6BAA6B;AACtC,SAAS,yCAAyC;AAElD,MAAM,4BAA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e;AAAA,IACjB;AAAA,EACF,GAAG,CAAC,aAAa,mBAAmB,uBAAuB,cAAc,CAAC;AAC5E;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { buildSelector } from "../descriptor/elementDescriptor";
|
|
2
|
+
import { getHostSourceIdentity } from "../fiber";
|
|
3
|
+
const sourceIdentityCache = /* @__PURE__ */ new WeakMap();
|
|
4
|
+
function getSourceIdentityKey(element) {
|
|
5
|
+
const cached = sourceIdentityCache.get(element);
|
|
6
|
+
if (cached !== void 0) {
|
|
7
|
+
return cached;
|
|
8
|
+
}
|
|
9
|
+
const identity = getHostSourceIdentity(element);
|
|
10
|
+
if (!identity) {
|
|
11
|
+
sourceIdentityCache.set(element, null);
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
const key = [
|
|
15
|
+
identity.filePath,
|
|
16
|
+
identity.lineNumber,
|
|
17
|
+
identity.columnNumber ?? "",
|
|
18
|
+
identity.tagName
|
|
19
|
+
].join(":");
|
|
20
|
+
sourceIdentityCache.set(element, key);
|
|
21
|
+
return key;
|
|
22
|
+
}
|
|
23
|
+
function getSourceLocationSiblingElements({
|
|
24
|
+
element
|
|
25
|
+
}) {
|
|
26
|
+
if (!(element instanceof HTMLElement) || !document.body) {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
const selectedLocationKey = getSourceIdentityKey(element);
|
|
30
|
+
if (!selectedLocationKey) {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
const siblings = [];
|
|
34
|
+
const treeWalker = document.createTreeWalker(
|
|
35
|
+
document.body,
|
|
36
|
+
NodeFilter.SHOW_ELEMENT
|
|
37
|
+
);
|
|
38
|
+
let currentNode = treeWalker.nextNode();
|
|
39
|
+
while (currentNode) {
|
|
40
|
+
if (currentNode instanceof HTMLElement && currentNode !== element) {
|
|
41
|
+
const currentLocationKey = getSourceIdentityKey(currentNode);
|
|
42
|
+
if (currentLocationKey === selectedLocationKey) {
|
|
43
|
+
siblings.push(currentNode);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
currentNode = treeWalker.nextNode();
|
|
47
|
+
}
|
|
48
|
+
return siblings;
|
|
49
|
+
}
|
|
50
|
+
function getSourceLocationSiblingSelectors({
|
|
51
|
+
element
|
|
52
|
+
}) {
|
|
53
|
+
return getSourceLocationSiblingElements({ element }).map(buildSelector);
|
|
54
|
+
}
|
|
55
|
+
export {
|
|
56
|
+
getSourceLocationSiblingElements,
|
|
57
|
+
getSourceLocationSiblingSelectors
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=useSiblingResolution.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../editor/select-mode/hooks/useSiblingResolution.ts"],
|
|
4
|
+
"sourcesContent": ["import { buildSelector } from \"../descriptor/elementDescriptor\";\nimport { getHostSourceIdentity } from \"../fiber\";\n\nconst sourceIdentityCache = new WeakMap<HTMLElement, string | null>();\n\nfunction getSourceIdentityKey(element: HTMLElement): string | null {\n const cached = sourceIdentityCache.get(element);\n if (cached !== undefined) {\n return cached;\n }\n const identity = getHostSourceIdentity(element);\n if (!identity) {\n sourceIdentityCache.set(element, null);\n return null;\n }\n const key = [\n identity.filePath,\n identity.lineNumber,\n identity.columnNumber ?? \"\",\n identity.tagName,\n ].join(\":\");\n sourceIdentityCache.set(element, key);\n return key;\n}\n\nexport function getSourceLocationSiblingElements({\n element,\n}: {\n element: Element;\n}): HTMLElement[] {\n if (!(element instanceof HTMLElement) || !document.body) {\n return [];\n }\n\n const selectedLocationKey = getSourceIdentityKey(element);\n if (!selectedLocationKey) {\n return [];\n }\n\n const siblings: HTMLElement[] = [];\n const treeWalker = document.createTreeWalker(\n document.body,\n NodeFilter.SHOW_ELEMENT,\n );\n\n let currentNode = treeWalker.nextNode();\n while (currentNode) {\n if (currentNode instanceof HTMLElement && currentNode !== element) {\n const currentLocationKey = getSourceIdentityKey(currentNode);\n if (currentLocationKey === selectedLocationKey) {\n siblings.push(currentNode);\n }\n }\n currentNode = treeWalker.nextNode();\n }\n\n return siblings;\n}\n\nexport function getSourceLocationSiblingSelectors({\n element,\n}: {\n element: Element;\n}): string[] {\n return getSourceLocationSiblingElements({ element }).map(buildSelector);\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,qBAAqB;AAC9B,SAAS,6BAA6B;AAEtC,MAAM,sBAAsB,oBAAI,QAAoC;AAEpE,SAAS,qBAAqB,SAAqC;AACjE,QAAM,SAAS,oBAAoB,IAAI,OAAO;AAC9C,MAAI,WAAW,QAAW;AACxB,WAAO;AAAA,EACT;AACA,QAAM,WAAW,sBAAsB,OAAO;AAC9C,MAAI,CAAC,UAAU;AACb,wBAAoB,IAAI,SAAS,IAAI;AACrC,WAAO;AAAA,EACT;AACA,QAAM,MAAM;AAAA,IACV,SAAS;AAAA,IACT,SAAS;AAAA,IACT,SAAS,gBAAgB;AAAA,IACzB,SAAS;AAAA,EACX,EAAE,KAAK,GAAG;AACV,sBAAoB,IAAI,SAAS,GAAG;AACpC,SAAO;AACT;AAEO,SAAS,iCAAiC;AAAA,EAC/C;AACF,GAEkB;AAChB,MAAI,EAAE,mBAAmB,gBAAgB,CAAC,SAAS,MAAM;AACvD,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,sBAAsB,qBAAqB,OAAO;AACxD,MAAI,CAAC,qBAAqB;AACxB,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,WAA0B,CAAC;AACjC,QAAM,aAAa,SAAS;AAAA,IAC1B,SAAS;AAAA,IACT,WAAW;AAAA,EACb;AAEA,MAAI,cAAc,WAAW,SAAS;AACtC,SAAO,aAAa;AAClB,QAAI,uBAAuB,eAAe,gBAAgB,SAAS;AACjE,YAAM,qBAAqB,qBAAqB,WAAW;AAC3D,UAAI,uBAAuB,qBAAqB;AAC9C,iBAAS,KAAK,WAAW;AAAA,MAC3B;AAAA,IACF;AACA,kBAAc,WAAW,SAAS;AAAA,EACpC;AAEA,SAAO;AACT;AAEO,SAAS,kCAAkC;AAAA,EAChD;AACF,GAEa;AACX,SAAO,iCAAiC,EAAE,QAAQ,CAAC,EAAE,IAAI,aAAa;AACxE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function isInlineTextMarkElement(element: Element): boolean;
|
|
2
|
+
/**
|
|
3
|
+
* Walk up past nested inline text marks so selection targets the host
|
|
4
|
+
* element (e.g. `<p>hello <em>world</em></p>` → the `<p>`).
|
|
5
|
+
*/
|
|
6
|
+
export declare function skipInlineTextMarkElements(element: Element): Element;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const INLINE_TEXT_MARK_TAGS = /* @__PURE__ */ new Set([
|
|
2
|
+
"b",
|
|
3
|
+
"strong",
|
|
4
|
+
"em",
|
|
5
|
+
"i",
|
|
6
|
+
"s",
|
|
7
|
+
"strike",
|
|
8
|
+
"u",
|
|
9
|
+
"mark"
|
|
10
|
+
]);
|
|
11
|
+
function isInlineTextMarkElement(element) {
|
|
12
|
+
return INLINE_TEXT_MARK_TAGS.has(element.tagName.toLowerCase());
|
|
13
|
+
}
|
|
14
|
+
function skipInlineTextMarkElements(element) {
|
|
15
|
+
let current = element;
|
|
16
|
+
while (isInlineTextMarkElement(current) && current.parentElement && current.parentElement !== document.documentElement && current.parentElement !== document.body) {
|
|
17
|
+
current = current.parentElement;
|
|
18
|
+
}
|
|
19
|
+
return current;
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
isInlineTextMarkElement,
|
|
23
|
+
skipInlineTextMarkElements
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=inlineTextMarks.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../editor/select-mode/inlineTextMarks.ts"],
|
|
4
|
+
"sourcesContent": ["// NOTE (Noah, 2026-07-23): TipTap / inline JSX marks are not independently\n// selectable \u2014 clicking bold/italic text should select the host block, not\n// the <strong>/<em> wrapper. Keep in sync with tiptapInlineEditor marks.\nconst INLINE_TEXT_MARK_TAGS = new Set([\n \"b\",\n \"strong\",\n \"em\",\n \"i\",\n \"s\",\n \"strike\",\n \"u\",\n \"mark\",\n]);\n\nexport function isInlineTextMarkElement(element: Element): boolean {\n return INLINE_TEXT_MARK_TAGS.has(element.tagName.toLowerCase());\n}\n\n/**\n * Walk up past nested inline text marks so selection targets the host\n * element (e.g. `<p>hello <em>world</em></p>` \u2192 the `<p>`).\n */\nexport function skipInlineTextMarkElements(element: Element): Element {\n let current = element;\n while (\n isInlineTextMarkElement(current) &&\n current.parentElement &&\n current.parentElement !== document.documentElement &&\n current.parentElement !== document.body\n ) {\n current = current.parentElement;\n }\n return current;\n}\n"],
|
|
5
|
+
"mappings": "AAGA,MAAM,wBAAwB,oBAAI,IAAI;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAEM,SAAS,wBAAwB,SAA2B;AACjE,SAAO,sBAAsB,IAAI,QAAQ,QAAQ,YAAY,CAAC;AAChE;AAMO,SAAS,2BAA2B,SAA2B;AACpE,MAAI,UAAU;AACd,SACE,wBAAwB,OAAO,KAC/B,QAAQ,iBACR,QAAQ,kBAAkB,SAAS,mBACnC,QAAQ,kBAAkB,SAAS,MACnC;AACA,cAAU,QAAQ;AAAA,EACpB;AACA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isIntersecting, isRectEnclosing } from "../../../_vendor/replo-utils/lib/geometry.mjs";
|
|
2
2
|
import { v4 as uuidv4 } from "uuid";
|
|
3
|
+
import { isInlineTextMarkElement } from "../inlineTextMarks";
|
|
3
4
|
const SELECTION_TOLERANCE_PX = 4;
|
|
4
5
|
function normalizeSelectionRect({
|
|
5
6
|
startX,
|
|
@@ -88,6 +89,9 @@ function isMeaningfulElement(element, elementRect) {
|
|
|
88
89
|
if (["html", "body", "script", "style", "meta", "link"].includes(tagName)) {
|
|
89
90
|
return false;
|
|
90
91
|
}
|
|
92
|
+
if (isInlineTextMarkElement(element)) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
91
95
|
if (elementRect.width < 4 || elementRect.height < 4) {
|
|
92
96
|
return false;
|
|
93
97
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../editor/select-mode/interactions/selectionGeometry.ts"],
|
|
4
|
-
"sourcesContent": ["import type {\n SelectModeBoundingRect,\n SelectModeClickPosition,\n} from \"schemas/generated/selectMode\";\n\nimport { isIntersecting, isRectEnclosing } from \"replo-utils/lib/geometry\";\nimport { v4 as uuidv4 } from \"uuid\";\n\nexport type DragPosition = {\n clientX: number;\n clientY: number;\n pageX: number;\n pageY: number;\n};\n\nexport type ScrollOffset = {\n left: number;\n top: number;\n};\n\nexport type SelectedAreaState = {\n pageRect: SelectModeBoundingRect;\n};\n\n// NOTE (Noah, 2026-04-21): A small fudge factor so elements\n// that visually appear to touch the selection rect (but whose bounding\n// box is a pixel or two off due to borders/sub-pixel rendering) still get\n// included.\nconst SELECTION_TOLERANCE_PX = 4;\n\nfunction normalizeSelectionRect({\n startX,\n startY,\n endX,\n endY,\n}: {\n startX: number;\n startY: number;\n endX: number;\n endY: number;\n}): SelectModeBoundingRect {\n const left = Math.min(startX, endX);\n const right = Math.max(startX, endX);\n const top = Math.min(startY, endY);\n const bottom = Math.max(startY, endY);\n\n return {\n x: left,\n y: top,\n width: right - left,\n height: bottom - top,\n top,\n right,\n bottom,\n left,\n };\n}\n\n/**\n * @author Kevin O'Connell 2026-04-17\n */\nexport function getDragPositionFromClient({\n clientX,\n clientY,\n scrollOffset,\n}: {\n clientX: number;\n clientY: number;\n scrollOffset: ScrollOffset;\n}): DragPosition {\n return {\n clientX,\n clientY,\n pageX: clientX + scrollOffset.left,\n pageY: clientY + scrollOffset.top,\n };\n}\n\n/**\n * @author Kevin O'Connell 2026-04-17\n */\nexport function getDocumentScrollOffset(): ScrollOffset {\n const scrollingElement = document.scrollingElement;\n return {\n left: scrollingElement?.scrollLeft ?? window.scrollX,\n top: scrollingElement?.scrollTop ?? window.scrollY,\n };\n}\n\n/**\n * @author Kevin O'Connell 2026-04-17\n */\nexport function getViewportSelectionRect({\n dragStart,\n dragCurrent,\n scrollOffset,\n}: {\n dragStart: DragPosition;\n dragCurrent: DragPosition;\n scrollOffset: ScrollOffset;\n}): SelectModeBoundingRect {\n return normalizeSelectionRect({\n startX: dragStart.pageX - scrollOffset.left,\n startY: dragStart.pageY - scrollOffset.top,\n endX: dragCurrent.pageX - scrollOffset.left,\n endY: dragCurrent.pageY - scrollOffset.top,\n });\n}\n\n/**\n * @author Kevin O'Connell 2026-04-17\n */\nexport function getPageRectFromViewportRect({\n rect,\n scrollOffset,\n}: {\n rect: SelectModeBoundingRect;\n scrollOffset: ScrollOffset;\n}): SelectModeBoundingRect {\n return {\n x: rect.x + scrollOffset.left,\n y: rect.y + scrollOffset.top,\n width: rect.width,\n height: rect.height,\n left: rect.left + scrollOffset.left,\n top: rect.top + scrollOffset.top,\n right: rect.right + scrollOffset.left,\n bottom: rect.bottom + scrollOffset.top,\n };\n}\n\n/**\n * @author Kevin O'Connell 2026-04-17\n */\nexport function getViewportRectFromPageRect({\n rect,\n scrollOffset,\n}: {\n rect: SelectModeBoundingRect;\n scrollOffset: ScrollOffset;\n}): SelectModeBoundingRect {\n return {\n x: rect.x - scrollOffset.left,\n y: rect.y - scrollOffset.top,\n width: rect.width,\n height: rect.height,\n left: rect.left - scrollOffset.left,\n top: rect.top - scrollOffset.top,\n right: rect.right - scrollOffset.left,\n bottom: rect.bottom - scrollOffset.top,\n };\n}\n\nfunction isMeaningfulElement(\n element: Element,\n elementRect: SelectModeBoundingRect,\n): boolean {\n const tagName = element.tagName.toLowerCase();\n if ([\"html\", \"body\", \"script\", \"style\", \"meta\", \"link\"].includes(tagName)) {\n return false;\n }\n\n if (elementRect.width < 4 || elementRect.height < 4) {\n return false;\n }\n\n return true;\n}\n\n/**\n * A drag captures an element when their boxes overlap (within\n * `tolerancePx`) \u2014 but NOT when the drag sits entirely inside the\n * element. The latter case is the user dragging *within* a large\n * container (a section, `<main>`, `<body>`) to lasso its children; the\n * container itself isn't a thing they're trying to select, so we drop it.\n */\nexport function doesRectIntersectSelection({\n elementRect,\n selectionRect,\n tolerancePx,\n}: {\n elementRect: SelectModeBoundingRect;\n selectionRect: SelectModeBoundingRect;\n tolerancePx: number;\n}) {\n return (\n isIntersecting(elementRect, selectionRect, { tolerance: tolerancePx }) &&\n !isRectEnclosing(elementRect, selectionRect)\n );\n}\n\n// A meaningful element plus its page-coordinate rect and a stable id,\n// snapshotted once when a drag begins. Page coordinates are scroll-\n// invariant, so per-move hit-testing never needs to re-measure.\nexport type DragCandidate = {\n id: string;\n element: Element;\n pageRect: SelectModeBoundingRect;\n};\n\n/**\n * Snapshots every meaningful element and its page rect when a drag begins.\n * Each candidate gets a stable id so the parent overlay can key its\n * live highlights without remounting them as the drag moves.\n */\nexport function collectDragCandidates(\n scrollOffset: ScrollOffset,\n): DragCandidate[] {\n const candidates: DragCandidate[] = [];\n for (const element of Array.from(document.querySelectorAll(\"*\"))) {\n const viewportRect = getElementBoundingRect(element);\n if (!isMeaningfulElement(element, viewportRect)) {\n continue;\n }\n candidates.push({\n id: uuidv4(),\n element,\n pageRect: getPageRectFromViewportRect({\n rect: viewportRect,\n scrollOffset,\n }),\n });\n }\n return candidates;\n}\n\n/**\n * Drop a child whose parent is also selected and every one of that\n * parent's *candidate* children is selected: the parent already represents\n * the whole group, so the children are redundant. Returns only the\n * candidates that survive the collapse.\n *\n * Only children that are themselves drag candidates count toward \"fully\n * covered\". A parent's DOM children can include decorative / non-selectable\n * elements (and `.children` excludes text nodes); those can never be\n * selected, so counting them would wedge the check permanently false and\n * the collapse would never fire.\n *\n * Membership is read once up front, so the collapse cascades up the tree\n * in a single pass \u2014 a parent kept this round is itself dropped when *its*\n * parent is likewise fully covered, leaving only the topmost ancestor of\n * any fully-enclosed subtree.\n */\nfunction collapseFullyCoveredChildren({\n candidates,\n selected,\n}: {\n candidates: DragCandidate[];\n selected: DragCandidate[];\n}): DragCandidate[] {\n const candidateElements = new Set(\n candidates.map((candidate) => candidate.element),\n );\n const selectedElements = new Set(\n selected.map((candidate) => candidate.element),\n );\n return selected.filter((candidate) => {\n const parent = candidate.element.parentElement;\n if (!parent || !selectedElements.has(parent)) {\n return true;\n }\n const everyCandidateChildSelected = Array.from(parent.children)\n .filter((child) => candidateElements.has(child))\n .every((child) => selectedElements.has(child));\n return !everyCandidateChildSelected;\n });\n}\n\n/**\n * Cheap per-move hit-test against the pre-collected candidates: keep the\n * ones whose page rect overlaps the selection (excluding any that wholly\n * enclose it), then collapse any fully-covered parent/children group down\n * to just the parent (see `collapseFullyCoveredChildren`). Does no DOM\n * queries or re-measures of geometry \u2014 the only DOM reads are cheap\n * parent/child structural lookups.\n *\n * Because the collapse depends on which siblings are currently captured,\n * elements legitimately move in and out of the result as the drag grows or\n * shrinks: a child drops out the moment the drag swallows its last sibling\n * (the parent takes over), and reappears if the drag retreats.\n */\nexport function getCandidatesInSelection({\n candidates,\n selectionPageRect,\n}: {\n candidates: DragCandidate[];\n selectionPageRect: SelectModeBoundingRect;\n}): DragCandidate[] {\n const intersecting = candidates.filter((candidate) => {\n return doesRectIntersectSelection({\n elementRect: candidate.pageRect,\n selectionRect: selectionPageRect,\n tolerancePx: SELECTION_TOLERANCE_PX,\n });\n });\n\n return collapseFullyCoveredChildren({ candidates, selected: intersecting });\n}\n\n/**\n * Picks a \"click position\" for an element that fell inside an area\n * selection. We use the corner of the element nearest the top-left of the\n * selection rect, clamped to the element's own bounds. This anchor is what\n * lets the selected-element overlay continue to track the element when the\n * user scrolls (`useSelectionScrollSync` re-projects relative to it).\n *\n * @author Kevin O'Connell 2026-04-17\n */\nexport function getElementAnchor({\n element,\n selectionRect,\n}: {\n element: Element;\n selectionRect: SelectModeBoundingRect;\n}): SelectModeClickPosition {\n const rect = element.getBoundingClientRect();\n\n return {\n x: Math.min(Math.max(selectionRect.left, rect.left), rect.right),\n y: Math.min(Math.max(selectionRect.top, rect.top), rect.bottom),\n };\n}\n\n/**\n * @author Kevin O'Connell 2026-04-17\n */\nexport function getElementBoundingRect(\n element: Element,\n): SelectModeBoundingRect {\n const rect = element.getBoundingClientRect();\n\n return {\n x: rect.x,\n y: rect.y,\n width: rect.width,\n height: rect.height,\n top: rect.top,\n right: rect.right,\n bottom: rect.bottom,\n left: rect.left,\n };\n}\n"],
|
|
5
|
-
"mappings": "AAKA,SAAS,gBAAgB,uBAAuB;AAChD,SAAS,MAAM,cAAc;
|
|
4
|
+
"sourcesContent": ["import type {\n SelectModeBoundingRect,\n SelectModeClickPosition,\n} from \"schemas/generated/selectMode\";\n\nimport { isIntersecting, isRectEnclosing } from \"replo-utils/lib/geometry\";\nimport { v4 as uuidv4 } from \"uuid\";\n\nimport { isInlineTextMarkElement } from \"../inlineTextMarks\";\n\nexport type DragPosition = {\n clientX: number;\n clientY: number;\n pageX: number;\n pageY: number;\n};\n\nexport type ScrollOffset = {\n left: number;\n top: number;\n};\n\nexport type SelectedAreaState = {\n pageRect: SelectModeBoundingRect;\n};\n\n// NOTE (Noah, 2026-04-21): A small fudge factor so elements\n// that visually appear to touch the selection rect (but whose bounding\n// box is a pixel or two off due to borders/sub-pixel rendering) still get\n// included.\nconst SELECTION_TOLERANCE_PX = 4;\n\nfunction normalizeSelectionRect({\n startX,\n startY,\n endX,\n endY,\n}: {\n startX: number;\n startY: number;\n endX: number;\n endY: number;\n}): SelectModeBoundingRect {\n const left = Math.min(startX, endX);\n const right = Math.max(startX, endX);\n const top = Math.min(startY, endY);\n const bottom = Math.max(startY, endY);\n\n return {\n x: left,\n y: top,\n width: right - left,\n height: bottom - top,\n top,\n right,\n bottom,\n left,\n };\n}\n\n/**\n * @author Kevin O'Connell 2026-04-17\n */\nexport function getDragPositionFromClient({\n clientX,\n clientY,\n scrollOffset,\n}: {\n clientX: number;\n clientY: number;\n scrollOffset: ScrollOffset;\n}): DragPosition {\n return {\n clientX,\n clientY,\n pageX: clientX + scrollOffset.left,\n pageY: clientY + scrollOffset.top,\n };\n}\n\n/**\n * @author Kevin O'Connell 2026-04-17\n */\nexport function getDocumentScrollOffset(): ScrollOffset {\n const scrollingElement = document.scrollingElement;\n return {\n left: scrollingElement?.scrollLeft ?? window.scrollX,\n top: scrollingElement?.scrollTop ?? window.scrollY,\n };\n}\n\n/**\n * @author Kevin O'Connell 2026-04-17\n */\nexport function getViewportSelectionRect({\n dragStart,\n dragCurrent,\n scrollOffset,\n}: {\n dragStart: DragPosition;\n dragCurrent: DragPosition;\n scrollOffset: ScrollOffset;\n}): SelectModeBoundingRect {\n return normalizeSelectionRect({\n startX: dragStart.pageX - scrollOffset.left,\n startY: dragStart.pageY - scrollOffset.top,\n endX: dragCurrent.pageX - scrollOffset.left,\n endY: dragCurrent.pageY - scrollOffset.top,\n });\n}\n\n/**\n * @author Kevin O'Connell 2026-04-17\n */\nexport function getPageRectFromViewportRect({\n rect,\n scrollOffset,\n}: {\n rect: SelectModeBoundingRect;\n scrollOffset: ScrollOffset;\n}): SelectModeBoundingRect {\n return {\n x: rect.x + scrollOffset.left,\n y: rect.y + scrollOffset.top,\n width: rect.width,\n height: rect.height,\n left: rect.left + scrollOffset.left,\n top: rect.top + scrollOffset.top,\n right: rect.right + scrollOffset.left,\n bottom: rect.bottom + scrollOffset.top,\n };\n}\n\n/**\n * @author Kevin O'Connell 2026-04-17\n */\nexport function getViewportRectFromPageRect({\n rect,\n scrollOffset,\n}: {\n rect: SelectModeBoundingRect;\n scrollOffset: ScrollOffset;\n}): SelectModeBoundingRect {\n return {\n x: rect.x - scrollOffset.left,\n y: rect.y - scrollOffset.top,\n width: rect.width,\n height: rect.height,\n left: rect.left - scrollOffset.left,\n top: rect.top - scrollOffset.top,\n right: rect.right - scrollOffset.left,\n bottom: rect.bottom - scrollOffset.top,\n };\n}\n\nfunction isMeaningfulElement(\n element: Element,\n elementRect: SelectModeBoundingRect,\n): boolean {\n const tagName = element.tagName.toLowerCase();\n if ([\"html\", \"body\", \"script\", \"style\", \"meta\", \"link\"].includes(tagName)) {\n return false;\n }\n\n if (isInlineTextMarkElement(element)) {\n return false;\n }\n\n if (elementRect.width < 4 || elementRect.height < 4) {\n return false;\n }\n\n return true;\n}\n\n/**\n * A drag captures an element when their boxes overlap (within\n * `tolerancePx`) \u2014 but NOT when the drag sits entirely inside the\n * element. The latter case is the user dragging *within* a large\n * container (a section, `<main>`, `<body>`) to lasso its children; the\n * container itself isn't a thing they're trying to select, so we drop it.\n */\nexport function doesRectIntersectSelection({\n elementRect,\n selectionRect,\n tolerancePx,\n}: {\n elementRect: SelectModeBoundingRect;\n selectionRect: SelectModeBoundingRect;\n tolerancePx: number;\n}) {\n return (\n isIntersecting(elementRect, selectionRect, { tolerance: tolerancePx }) &&\n !isRectEnclosing(elementRect, selectionRect)\n );\n}\n\n// A meaningful element plus its page-coordinate rect and a stable id,\n// snapshotted once when a drag begins. Page coordinates are scroll-\n// invariant, so per-move hit-testing never needs to re-measure.\nexport type DragCandidate = {\n id: string;\n element: Element;\n pageRect: SelectModeBoundingRect;\n};\n\n/**\n * Snapshots every meaningful element and its page rect when a drag begins.\n * Each candidate gets a stable id so the parent overlay can key its\n * live highlights without remounting them as the drag moves.\n */\nexport function collectDragCandidates(\n scrollOffset: ScrollOffset,\n): DragCandidate[] {\n const candidates: DragCandidate[] = [];\n for (const element of Array.from(document.querySelectorAll(\"*\"))) {\n const viewportRect = getElementBoundingRect(element);\n if (!isMeaningfulElement(element, viewportRect)) {\n continue;\n }\n candidates.push({\n id: uuidv4(),\n element,\n pageRect: getPageRectFromViewportRect({\n rect: viewportRect,\n scrollOffset,\n }),\n });\n }\n return candidates;\n}\n\n/**\n * Drop a child whose parent is also selected and every one of that\n * parent's *candidate* children is selected: the parent already represents\n * the whole group, so the children are redundant. Returns only the\n * candidates that survive the collapse.\n *\n * Only children that are themselves drag candidates count toward \"fully\n * covered\". A parent's DOM children can include decorative / non-selectable\n * elements (and `.children` excludes text nodes); those can never be\n * selected, so counting them would wedge the check permanently false and\n * the collapse would never fire.\n *\n * Membership is read once up front, so the collapse cascades up the tree\n * in a single pass \u2014 a parent kept this round is itself dropped when *its*\n * parent is likewise fully covered, leaving only the topmost ancestor of\n * any fully-enclosed subtree.\n */\nfunction collapseFullyCoveredChildren({\n candidates,\n selected,\n}: {\n candidates: DragCandidate[];\n selected: DragCandidate[];\n}): DragCandidate[] {\n const candidateElements = new Set(\n candidates.map((candidate) => candidate.element),\n );\n const selectedElements = new Set(\n selected.map((candidate) => candidate.element),\n );\n return selected.filter((candidate) => {\n const parent = candidate.element.parentElement;\n if (!parent || !selectedElements.has(parent)) {\n return true;\n }\n const everyCandidateChildSelected = Array.from(parent.children)\n .filter((child) => candidateElements.has(child))\n .every((child) => selectedElements.has(child));\n return !everyCandidateChildSelected;\n });\n}\n\n/**\n * Cheap per-move hit-test against the pre-collected candidates: keep the\n * ones whose page rect overlaps the selection (excluding any that wholly\n * enclose it), then collapse any fully-covered parent/children group down\n * to just the parent (see `collapseFullyCoveredChildren`). Does no DOM\n * queries or re-measures of geometry \u2014 the only DOM reads are cheap\n * parent/child structural lookups.\n *\n * Because the collapse depends on which siblings are currently captured,\n * elements legitimately move in and out of the result as the drag grows or\n * shrinks: a child drops out the moment the drag swallows its last sibling\n * (the parent takes over), and reappears if the drag retreats.\n */\nexport function getCandidatesInSelection({\n candidates,\n selectionPageRect,\n}: {\n candidates: DragCandidate[];\n selectionPageRect: SelectModeBoundingRect;\n}): DragCandidate[] {\n const intersecting = candidates.filter((candidate) => {\n return doesRectIntersectSelection({\n elementRect: candidate.pageRect,\n selectionRect: selectionPageRect,\n tolerancePx: SELECTION_TOLERANCE_PX,\n });\n });\n\n return collapseFullyCoveredChildren({ candidates, selected: intersecting });\n}\n\n/**\n * Picks a \"click position\" for an element that fell inside an area\n * selection. We use the corner of the element nearest the top-left of the\n * selection rect, clamped to the element's own bounds. This anchor is what\n * lets the selected-element overlay continue to track the element when the\n * user scrolls (`useSelectionScrollSync` re-projects relative to it).\n *\n * @author Kevin O'Connell 2026-04-17\n */\nexport function getElementAnchor({\n element,\n selectionRect,\n}: {\n element: Element;\n selectionRect: SelectModeBoundingRect;\n}): SelectModeClickPosition {\n const rect = element.getBoundingClientRect();\n\n return {\n x: Math.min(Math.max(selectionRect.left, rect.left), rect.right),\n y: Math.min(Math.max(selectionRect.top, rect.top), rect.bottom),\n };\n}\n\n/**\n * @author Kevin O'Connell 2026-04-17\n */\nexport function getElementBoundingRect(\n element: Element,\n): SelectModeBoundingRect {\n const rect = element.getBoundingClientRect();\n\n return {\n x: rect.x,\n y: rect.y,\n width: rect.width,\n height: rect.height,\n top: rect.top,\n right: rect.right,\n bottom: rect.bottom,\n left: rect.left,\n };\n}\n"],
|
|
5
|
+
"mappings": "AAKA,SAAS,gBAAgB,uBAAuB;AAChD,SAAS,MAAM,cAAc;AAE7B,SAAS,+BAA+B;AAsBxC,MAAM,yBAAyB;AAE/B,SAAS,uBAAuB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAK2B;AACzB,QAAM,OAAO,KAAK,IAAI,QAAQ,IAAI;AAClC,QAAM,QAAQ,KAAK,IAAI,QAAQ,IAAI;AACnC,QAAM,MAAM,KAAK,IAAI,QAAQ,IAAI;AACjC,QAAM,SAAS,KAAK,IAAI,QAAQ,IAAI;AAEpC,SAAO;AAAA,IACL,GAAG;AAAA,IACH,GAAG;AAAA,IACH,OAAO,QAAQ;AAAA,IACf,QAAQ,SAAS;AAAA,IACjB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAKO,SAAS,0BAA0B;AAAA,EACxC;AAAA,EACA;AAAA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AAA,IACT;AACA,UAAM,8BAA8B,MAAM,KAAK,OAAO,QAAQ,EAC3D,OAAO,CAAC,UAAU,kBAAkB,IAAI,KAAK,CAAC,EAC9C,MAAM,CAAC,UAAU,iBAAiB,IAAI,KAAK,CAAC;AAC/C,WAAO,CAAC;AAAA,EACV,CAAC;AACH;AAeO,SAAS,yBAAyB;AAAA,EACvC;AAAA,EACA;AACF,GAGoB;AAClB,QAAM,eAAe,WAAW,OAAO,CAAC,cAAc;AACpD,WAAO,2BAA2B;AAAA,MAChC,aAAa,UAAU;AAAA,MACvB,eAAe;AAAA,MACf,aAAa;AAAA,IACf,CAAC;AAAA,EACH,CAAC;AAED,SAAO,6BAA6B,EAAE,YAAY,UAAU,aAAa,CAAC;AAC5E;AAWO,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA;AACF,GAG4B;AAC1B,QAAM,OAAO,QAAQ,sBAAsB;AAE3C,SAAO;AAAA,IACL,GAAG,KAAK,IAAI,KAAK,IAAI,cAAc,MAAM,KAAK,IAAI,GAAG,KAAK,KAAK;AAAA,IAC/D,GAAG,KAAK,IAAI,KAAK,IAAI,cAAc,KAAK,KAAK,GAAG,GAAG,KAAK,MAAM;AAAA,EAChE;AACF;AAKO,SAAS,uBACd,SACwB;AACxB,QAAM,OAAO,QAAQ,sBAAsB;AAE3C,SAAO;AAAA,IACL,GAAG,KAAK;AAAA,IACR,GAAG,KAAK;AAAA,IACR,OAAO,KAAK;AAAA,IACZ,QAAQ,KAAK;AAAA,IACb,KAAK,KAAK;AAAA,IACV,OAAO,KAAK;AAAA,IACZ,QAAQ,KAAK;AAAA,IACb,MAAM,KAAK;AAAA,EACb;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -39,6 +39,11 @@ type SelectionFrameSpec = {
|
|
|
39
39
|
pageRect: SelectionFramePageRect;
|
|
40
40
|
variant: SelectionFrameVariant;
|
|
41
41
|
};
|
|
42
|
+
/**
|
|
43
|
+
* Toggle the brighter inline-edit border and re-color any frames already on
|
|
44
|
+
* screen so the change is immediate, not deferred to the next redraw.
|
|
45
|
+
*/
|
|
46
|
+
export declare function setSelectionFrameEditing(editing: boolean): void;
|
|
42
47
|
/**
|
|
43
48
|
* Position selection frames at the given *page* coordinates, one node per
|
|
44
49
|
* spec. Page coords don't shift during scroll, so the caller is free to
|
|
@@ -1,12 +1,35 @@
|
|
|
1
1
|
const FUCHSIA_HEX = "#c026d3";
|
|
2
|
+
const EDITING_FUCHSIA_HEX = "#e879f9";
|
|
2
3
|
const FRAMES_CONTAINER_ID = "replo-select-mode-selection-frames";
|
|
4
|
+
let isEditing = false;
|
|
5
|
+
function getFrameBorderHex() {
|
|
6
|
+
return isEditing ? EDITING_FUCHSIA_HEX : FUCHSIA_HEX;
|
|
7
|
+
}
|
|
3
8
|
function applyVariantStyle({
|
|
4
9
|
frame,
|
|
5
10
|
variant
|
|
6
11
|
}) {
|
|
7
|
-
frame.style.border = `2px solid ${
|
|
12
|
+
frame.style.border = `2px solid ${getFrameBorderHex()}`;
|
|
8
13
|
frame.style.background = variant === "area" ? "rgba(192, 38, 211, 0.08)" : "transparent";
|
|
9
14
|
}
|
|
15
|
+
function setSelectionFrameEditing(editing) {
|
|
16
|
+
if (isEditing === editing) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
isEditing = editing;
|
|
20
|
+
if (typeof document === "undefined") {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const container = document.getElementById(FRAMES_CONTAINER_ID);
|
|
24
|
+
if (!(container instanceof HTMLDivElement)) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
for (const child of container.children) {
|
|
28
|
+
if (child instanceof HTMLDivElement) {
|
|
29
|
+
child.style.borderColor = getFrameBorderHex();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
10
33
|
function getOrCreateContainer() {
|
|
11
34
|
if (typeof document === "undefined") {
|
|
12
35
|
return null;
|
|
@@ -92,6 +115,7 @@ function hideSelectionFrame() {
|
|
|
92
115
|
}
|
|
93
116
|
export {
|
|
94
117
|
hideSelectionFrame,
|
|
118
|
+
setSelectionFrameEditing,
|
|
95
119
|
showSelectionFrame,
|
|
96
120
|
showSelectionFrames
|
|
97
121
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../editor/select-mode/selectionFrame.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * In-iframe selection frame renderer.\n *\n * Lives in the canopy iframe (not in agent-ui) because the previous\n * parent-side overlay had to be re-anchored on every scroll frame via\n * postMessage hop -> Zustand update -> React reconciliation, which\n * shows up as visible lag when the user scrolls quickly.\n *\n * By rendering directly inside the canopy iframe's document we get two\n * properties for free:\n *\n * 1. `position: absolute` + page coordinates means the document's own\n * scroll naturally translates the frames \u2014 zero JavaScript per\n * scroll frame, the browser composites them with the underlying page\n * content.\n * 2. No bridge serialization: the only cost when selection commits is\n * a handful of style writes on the frame nodes.\n *\n * A single click resolves to one frame; an area drag resolves to one\n * frame per captured element, so the renderer keeps a pool of nodes\n * under a shared container and reconciles it on each call (reusing\n * existing nodes when the count is stable, which keeps the single-frame\n * scroll-sync hot path a couple of style writes rather than a DOM churn).\n *\n * The canopy iframe loads a customer page and doesn't include lattice /\n * tailwind, so styling is intentionally vanilla inline CSS rather than\n * Tailwind classes.\n *\n * @author Kevin O'Connell 2026-05-26\n */\n\n// Matches `--color-fuchsia` (Tailwind v4 `fuchsia-600`) used by agent-ui\n// so the in-iframe frame is visually consistent with the rest of the\n// select-mode UI.\nconst FUCHSIA_HEX = \"#c026d3\";\n\nconst FRAMES_CONTAINER_ID = \"replo-select-mode-selection-frames\";\n\ntype SelectionFrameVariant = \"element\" | \"area\";\n\ntype SelectionFramePageRect = {\n x: number;\n y: number;\n width: number;\n height: number;\n};\n\ntype SelectionFrameSpec = {\n pageRect: SelectionFramePageRect;\n variant: SelectionFrameVariant;\n};\n\nfunction applyVariantStyle({\n frame,\n variant,\n}: {\n frame: HTMLDivElement;\n variant: SelectionFrameVariant;\n}) {\n // Both variants use the same bright fuchsia border so a single click and\n // each member of an area selection read as equally \"selected\"; the area\n // members carry a faint fill so a cluster still reads as a group.\n frame.style.border = `2px solid ${
|
|
5
|
-
"mappings": "AAkCA,MAAM,cAAc;
|
|
4
|
+
"sourcesContent": ["/**\n * In-iframe selection frame renderer.\n *\n * Lives in the canopy iframe (not in agent-ui) because the previous\n * parent-side overlay had to be re-anchored on every scroll frame via\n * postMessage hop -> Zustand update -> React reconciliation, which\n * shows up as visible lag when the user scrolls quickly.\n *\n * By rendering directly inside the canopy iframe's document we get two\n * properties for free:\n *\n * 1. `position: absolute` + page coordinates means the document's own\n * scroll naturally translates the frames \u2014 zero JavaScript per\n * scroll frame, the browser composites them with the underlying page\n * content.\n * 2. No bridge serialization: the only cost when selection commits is\n * a handful of style writes on the frame nodes.\n *\n * A single click resolves to one frame; an area drag resolves to one\n * frame per captured element, so the renderer keeps a pool of nodes\n * under a shared container and reconciles it on each call (reusing\n * existing nodes when the count is stable, which keeps the single-frame\n * scroll-sync hot path a couple of style writes rather than a DOM churn).\n *\n * The canopy iframe loads a customer page and doesn't include lattice /\n * tailwind, so styling is intentionally vanilla inline CSS rather than\n * Tailwind classes.\n *\n * @author Kevin O'Connell 2026-05-26\n */\n\n// Matches `--color-fuchsia` (Tailwind v4 `fuchsia-600`) used by agent-ui\n// so the in-iframe frame is visually consistent with the rest of the\n// select-mode UI.\nconst FUCHSIA_HEX = \"#c026d3\";\n\n// Brighter fuchsia (`fuchsia-400`) used while a text block is being inline\n// edited, so the active edit target stands out from a plain selection.\nconst EDITING_FUCHSIA_HEX = \"#e879f9\";\n\nconst FRAMES_CONTAINER_ID = \"replo-select-mode-selection-frames\";\n\n// Whether an inline text edit is in progress. Module-level so every frame\n// redraw (including the scroll-sync hot path) picks up the brighter color\n// without threading the flag through each call.\nlet isEditing = false;\n\nfunction getFrameBorderHex(): string {\n return isEditing ? EDITING_FUCHSIA_HEX : FUCHSIA_HEX;\n}\n\ntype SelectionFrameVariant = \"element\" | \"area\";\n\ntype SelectionFramePageRect = {\n x: number;\n y: number;\n width: number;\n height: number;\n};\n\ntype SelectionFrameSpec = {\n pageRect: SelectionFramePageRect;\n variant: SelectionFrameVariant;\n};\n\nfunction applyVariantStyle({\n frame,\n variant,\n}: {\n frame: HTMLDivElement;\n variant: SelectionFrameVariant;\n}) {\n // Both variants use the same bright fuchsia border so a single click and\n // each member of an area selection read as equally \"selected\"; the area\n // members carry a faint fill so a cluster still reads as a group. While\n // inline editing, the border brightens to mark the active edit target.\n frame.style.border = `2px solid ${getFrameBorderHex()}`;\n frame.style.background =\n variant === \"area\" ? \"rgba(192, 38, 211, 0.08)\" : \"transparent\";\n}\n\n/**\n * Toggle the brighter inline-edit border and re-color any frames already on\n * screen so the change is immediate, not deferred to the next redraw.\n */\nexport function setSelectionFrameEditing(editing: boolean) {\n if (isEditing === editing) {\n return;\n }\n isEditing = editing;\n if (typeof document === \"undefined\") {\n return;\n }\n const container = document.getElementById(FRAMES_CONTAINER_ID);\n if (!(container instanceof HTMLDivElement)) {\n return;\n }\n for (const child of container.children) {\n if (child instanceof HTMLDivElement) {\n child.style.borderColor = getFrameBorderHex();\n }\n }\n}\n\nfunction getOrCreateContainer(): HTMLDivElement | null {\n if (typeof document === \"undefined\") {\n return null;\n }\n const existing = document.getElementById(FRAMES_CONTAINER_ID);\n if (existing instanceof HTMLDivElement) {\n return existing;\n }\n if (!document.body) {\n return null;\n }\n const container = document.createElement(\"div\");\n container.id = FRAMES_CONTAINER_ID;\n container.setAttribute(\"aria-hidden\", \"true\");\n container.style.cssText = [\n \"position: absolute\",\n \"top: 0\",\n \"left: 0\",\n \"width: 0\",\n \"height: 0\",\n \"margin: 0\",\n \"padding: 0\",\n \"pointer-events: none\",\n \"z-index: 2147483646\",\n ].join(\";\");\n document.body.append(container);\n return container;\n}\n\nfunction createFrameNode(): HTMLDivElement {\n const frame = document.createElement(\"div\");\n frame.setAttribute(\"aria-hidden\", \"true\");\n frame.style.cssText = [\n \"position: absolute\",\n \"top: 0\",\n \"left: 0\",\n \"box-sizing: border-box\",\n \"border-radius: 2px\",\n \"pointer-events: none\",\n \"margin: 0\",\n \"padding: 0\",\n ].join(\";\");\n return frame;\n}\n\n/**\n * Position selection frames at the given *page* coordinates, one node per\n * spec. Page coords don't shift during scroll, so the caller is free to\n * call this once at commit time and let the browser handle the rest of the\n * scroll lifetime. Reconciles the node pool against `frames.length` so a\n * repeated single-frame call (scroll sync) just repositions one node.\n *\n * @author Kevin O'Connell 2026-05-26\n */\nexport function showSelectionFrames({\n frames,\n}: {\n frames: SelectionFrameSpec[];\n}) {\n const container = getOrCreateContainer();\n if (!container) {\n return;\n }\n\n while (container.childElementCount > frames.length) {\n container.lastElementChild?.remove();\n }\n while (container.childElementCount < frames.length) {\n container.append(createFrameNode());\n }\n\n frames.forEach((spec, index) => {\n const frame = container.children[index];\n if (!(frame instanceof HTMLDivElement)) {\n return;\n }\n applyVariantStyle({ frame, variant: spec.variant });\n frame.style.left = `${spec.pageRect.x}px`;\n frame.style.top = `${spec.pageRect.y}px`;\n frame.style.width = `${spec.pageRect.width}px`;\n frame.style.height = `${spec.pageRect.height}px`;\n });\n}\n\n/**\n * Convenience wrapper for the single-frame (element click) case.\n *\n * @author Kevin O'Connell 2026-05-26\n */\nexport function showSelectionFrame({\n pageRect,\n variant,\n}: {\n pageRect: SelectionFramePageRect;\n variant: SelectionFrameVariant;\n}) {\n showSelectionFrames({ frames: [{ pageRect, variant }] });\n}\n\n/**\n * @author Kevin O'Connell 2026-05-26\n */\nexport function hideSelectionFrame() {\n if (typeof document === \"undefined\") {\n return;\n }\n const container = document.getElementById(FRAMES_CONTAINER_ID);\n if (container instanceof HTMLDivElement) {\n container.replaceChildren();\n }\n}\n"],
|
|
5
|
+
"mappings": "AAkCA,MAAM,cAAc;AAIpB,MAAM,sBAAsB;AAE5B,MAAM,sBAAsB;AAK5B,I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