@replohq/canopy-sdk 0.1.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/json.d.ts +6 -0
- package/_vendor/replo-utils/lib/misc.d.ts +128 -0
- package/_vendor/replo-utils/lib/misc.mjs +1 -0
- package/_vendor/replo-utils/lib/object.d.ts +31 -0
- package/_vendor/replo-utils/lib/parse.d.ts +15 -0
- 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 +334 -0
- package/_vendor/schemas/agentTools/customIntegrations/loaders/product.mjs +50 -0
- package/_vendor/schemas/cart.d.ts +198 -0
- package/_vendor/schemas/cart.mjs +83 -0
- package/_vendor/schemas/errors.d.ts +428 -0
- package/_vendor/schemas/errors.mjs +955 -0
- package/_vendor/schemas/generated/errors.d.ts +61 -0
- package/_vendor/schemas/generated/selectMode.d.ts +95 -0
- package/_vendor/schemas/generated/selectMode.mjs +1 -0
- package/_vendor/schemas/loaderKeys.d.ts +39 -0
- package/_vendor/schemas/loaderKeys.mjs +23 -0
- package/_vendor/schemas/objectType.d.ts +895 -0
- package/_vendor/schemas/objectType.mjs +2 -0
- package/_vendor/schemas/registry.d.ts +243 -0
- package/_vendor/schemas/sandboxFiles.d.ts +35 -0
- package/_vendor/schemas/selectMode.d.ts +507 -0
- package/_vendor/schemas/selectMode.mjs +194 -0
- package/_vendor/schemas/sellingPlan.d.ts +60 -0
- package/_vendor/schemas/sellingPlan.mjs +1 -0
- package/analytics/analytics-provider.d.ts +13 -0
- package/analytics/analytics-provider.js +104 -0
- package/analytics/analytics-provider.js.map +7 -0
- package/analytics/analytics-sink.d.ts +20 -0
- package/analytics/analytics-sink.js +1 -0
- package/analytics/analytics-sink.js.map +7 -0
- package/analytics/hooks/use-product-viewed-analytics.d.ts +23 -0
- package/analytics/hooks/use-product-viewed-analytics.js +34 -0
- package/analytics/hooks/use-product-viewed-analytics.js.map +7 -0
- package/analytics/sinks/ga4-sink.d.ts +15 -0
- package/analytics/sinks/ga4-sink.js +52 -0
- package/analytics/sinks/ga4-sink.js.map +7 -0
- package/analytics/sinks/meta-sink.d.ts +14 -0
- package/analytics/sinks/meta-sink.js +44 -0
- package/analytics/sinks/meta-sink.js.map +7 -0
- package/analytics/sinks/pinterest-sink.d.ts +14 -0
- package/analytics/sinks/pinterest-sink.js +76 -0
- package/analytics/sinks/pinterest-sink.js.map +7 -0
- package/analytics/sinks/reddit-sink.d.ts +14 -0
- package/analytics/sinks/reddit-sink.js +80 -0
- package/analytics/sinks/reddit-sink.js.map +7 -0
- package/analytics/sinks/replo-sink.d.ts +14 -0
- package/analytics/sinks/replo-sink.js +57 -0
- package/analytics/sinks/replo-sink.js.map +7 -0
- package/analytics/sinks/snapchat-sink.d.ts +14 -0
- package/analytics/sinks/snapchat-sink.js +67 -0
- package/analytics/sinks/snapchat-sink.js.map +7 -0
- package/analytics/sinks/tiktok-sink.d.ts +14 -0
- package/analytics/sinks/tiktok-sink.js +79 -0
- package/analytics/sinks/tiktok-sink.js.map +7 -0
- package/analytics/sinks/window-sink.d.ts +18 -0
- package/analytics/sinks/window-sink.js +46 -0
- package/analytics/sinks/window-sink.js.map +7 -0
- package/analytics/utils/analytics-utils.d.ts +7 -0
- package/analytics/utils/analytics-utils.js +130 -0
- package/analytics/utils/analytics-utils.js.map +7 -0
- package/analytics/utils/navigation-tracker.d.ts +16 -0
- package/analytics/utils/navigation-tracker.js +44 -0
- package/analytics/utils/navigation-tracker.js.map +7 -0
- package/cart/buy-now-action.d.ts +21 -0
- package/cart/buy-now-action.js +104 -0
- package/cart/buy-now-action.js.map +7 -0
- package/cart/cart-actions.d.ts +63 -0
- package/cart/cart-actions.js +90 -0
- package/cart/cart-actions.js.map +7 -0
- package/cart/cart-loader.d.ts +9 -0
- package/cart/cart-loader.js +11 -0
- package/cart/cart-loader.js.map +7 -0
- package/cart/cart-provider.d.ts +85 -0
- package/cart/cart-provider.js +358 -0
- package/cart/cart-provider.js.map +7 -0
- package/cart/cart-types.d.ts +154 -0
- package/cart/cart-types.js +16 -0
- package/cart/cart-types.js.map +7 -0
- package/cart/gateways/cart-gateway.d.ts +10 -0
- package/cart/gateways/cart-gateway.js +19 -0
- package/cart/gateways/cart-gateway.js.map +7 -0
- package/cart/gateways/cookie-cart-gateway.d.ts +28 -0
- package/cart/gateways/cookie-cart-gateway.js +109 -0
- package/cart/gateways/cookie-cart-gateway.js.map +7 -0
- package/cart/gateways/default-cart-gateway.d.ts +19 -0
- package/cart/gateways/default-cart-gateway.js +30 -0
- package/cart/gateways/default-cart-gateway.js.map +7 -0
- package/cart/gateways/resolver-cart-gateway.d.ts +2 -0
- package/cart/gateways/resolver-cart-gateway.js +106 -0
- package/cart/gateways/resolver-cart-gateway.js.map +7 -0
- package/cart/gateways/stripe-cart-gateway.d.ts +19 -0
- package/cart/gateways/stripe-cart-gateway.js +28 -0
- package/cart/gateways/stripe-cart-gateway.js.map +7 -0
- package/cart/gateways/stripe-constants.d.ts +1 -0
- package/cart/gateways/stripe-constants.js +5 -0
- package/cart/gateways/stripe-constants.js.map +7 -0
- package/cart/hooks/use-add-to-cart.d.ts +63 -0
- package/cart/hooks/use-add-to-cart.js +120 -0
- package/cart/hooks/use-add-to-cart.js.map +7 -0
- package/cart/hooks/use-buy-now.d.ts +49 -0
- package/cart/hooks/use-buy-now.js +62 -0
- package/cart/hooks/use-buy-now.js.map +7 -0
- package/cart/utils/cart-utils.d.ts +31 -0
- package/cart/utils/cart-utils.js +48 -0
- package/cart/utils/cart-utils.js.map +7 -0
- package/cart/utils/cookie-cart-persistence.d.ts +55 -0
- package/cart/utils/cookie-cart-persistence.js +153 -0
- package/cart/utils/cookie-cart-persistence.js.map +7 -0
- package/cart/utils/variant-to-cart-line.d.ts +124 -0
- package/cart/utils/variant-to-cart-line.js +202 -0
- package/cart/utils/variant-to-cart-line.js.map +7 -0
- package/chunk-46YU2W6T.mjs +538 -0
- package/chunk-4TZVNC3W.mjs +33 -0
- package/chunk-INHK6MYI.mjs +1598 -0
- package/editor/ClientErrorBoundary.d.ts +7 -0
- package/editor/ClientErrorBoundary.js +48 -0
- package/editor/ClientErrorBoundary.js.map +7 -0
- package/editor/LinkInterceptor.d.ts +1 -0
- package/editor/LinkInterceptor.js +124 -0
- package/editor/LinkInterceptor.js.map +7 -0
- package/editor/posthog-relay.d.ts +10 -0
- package/editor/posthog-relay.js +60 -0
- package/editor/posthog-relay.js.map +7 -0
- package/editor/select-mode/EditorSelection.d.ts +24 -0
- package/editor/select-mode/EditorSelection.js +34 -0
- package/editor/select-mode/EditorSelection.js.map +7 -0
- package/editor/select-mode/descriptor/elementDescriptor.d.ts +15 -0
- package/editor/select-mode/descriptor/elementDescriptor.js +213 -0
- package/editor/select-mode/descriptor/elementDescriptor.js.map +7 -0
- package/editor/select-mode/fiber.d.ts +52 -0
- package/editor/select-mode/fiber.js +269 -0
- package/editor/select-mode/fiber.js.map +7 -0
- package/editor/select-mode/hooks/useCrosshairCursor.d.ts +12 -0
- package/editor/select-mode/hooks/useCrosshairCursor.js +20 -0
- package/editor/select-mode/hooks/useCrosshairCursor.js.map +7 -0
- package/editor/select-mode/hooks/useParentMessaging.d.ts +24 -0
- package/editor/select-mode/hooks/useParentMessaging.js +33 -0
- package/editor/select-mode/hooks/useParentMessaging.js.map +7 -0
- package/editor/select-mode/hooks/useSelectModeController.d.ts +8 -0
- package/editor/select-mode/hooks/useSelectModeController.js +49 -0
- package/editor/select-mode/hooks/useSelectModeController.js.map +7 -0
- package/editor/select-mode/hooks/useSelectionHover.d.ts +22 -0
- package/editor/select-mode/hooks/useSelectionHover.js +98 -0
- package/editor/select-mode/hooks/useSelectionHover.js.map +7 -0
- package/editor/select-mode/hooks/useSelectionInteractions.d.ts +32 -0
- package/editor/select-mode/hooks/useSelectionInteractions.js +293 -0
- package/editor/select-mode/hooks/useSelectionInteractions.js.map +7 -0
- package/editor/select-mode/hooks/useSelectionScrollSync.d.ts +28 -0
- package/editor/select-mode/hooks/useSelectionScrollSync.js +77 -0
- package/editor/select-mode/hooks/useSelectionScrollSync.js.map +7 -0
- package/editor/select-mode/interactions/selectionGeometry.d.ts +80 -0
- package/editor/select-mode/interactions/selectionGeometry.js +160 -0
- package/editor/select-mode/interactions/selectionGeometry.js.map +7 -0
- package/editor/select-mode/selectModeSession.d.ts +21 -0
- package/editor/select-mode/selectModeSession.js +7 -0
- package/editor/select-mode/selectModeSession.js.map +7 -0
- package/editor/select-mode/selectionFrame.d.ts +48 -0
- package/editor/select-mode/selectionFrame.js +74 -0
- package/editor/select-mode/selectionFrame.js.map +7 -0
- package/editor/select-mode/symbolicate.d.ts +3 -0
- package/editor/select-mode/symbolicate.js +139 -0
- package/editor/select-mode/symbolicate.js.map +7 -0
- package/env.d.ts +13 -0
- package/env.js +20 -0
- package/env.js.map +7 -0
- package/gateways/canopy-api.d.ts +84 -0
- package/gateways/canopy-api.js +203 -0
- package/gateways/canopy-api.js.map +7 -0
- package/hooks/use-client-value.d.ts +10 -0
- package/hooks/use-client-value.js +12 -0
- package/hooks/use-client-value.js.map +7 -0
- package/hooks/use-formatted-price.d.ts +15 -0
- package/hooks/use-formatted-price.js +19 -0
- package/hooks/use-formatted-price.js.map +7 -0
- package/lib/get-query-client.d.ts +2 -0
- package/lib/get-query-client.js +34 -0
- package/lib/get-query-client.js.map +7 -0
- package/lib/integration-utils.d.ts +2 -0
- package/lib/integration-utils.js +9 -0
- package/lib/integration-utils.js.map +7 -0
- package/lib/shopify-utils.d.ts +16 -0
- package/lib/shopify-utils.js +11 -0
- package/lib/shopify-utils.js.map +7 -0
- package/lib/url-utils.d.ts +4 -0
- package/lib/url-utils.js +8 -0
- package/lib/url-utils.js.map +7 -0
- package/loaders/collection-loader.d.ts +11 -0
- package/loaders/collection-loader.js +53 -0
- package/loaders/collection-loader.js.map +7 -0
- package/loaders/collection-products-loader.d.ts +12 -0
- package/loaders/collection-products-loader.js +56 -0
- package/loaders/collection-products-loader.js.map +7 -0
- package/loaders/invoke-loader-action.d.ts +11 -0
- package/loaders/invoke-loader-action.js +14 -0
- package/loaders/invoke-loader-action.js.map +7 -0
- package/loaders/invoke-loader-server.d.ts +18 -0
- package/loaders/invoke-loader-server.js +35 -0
- package/loaders/invoke-loader-server.js.map +7 -0
- package/loaders/invoke-loader.d.ts +14 -0
- package/loaders/invoke-loader.js +36 -0
- package/loaders/invoke-loader.js.map +7 -0
- package/loaders/levanta-product-loader.d.ts +11 -0
- package/loaders/levanta-product-loader.js +53 -0
- package/loaders/levanta-product-loader.js.map +7 -0
- package/loaders/loader-error-boundary.d.ts +25 -0
- package/loaders/loader-error-boundary.js +24 -0
- package/loaders/loader-error-boundary.js.map +7 -0
- package/loaders/okendo-review-aggregate-loader.d.ts +17 -0
- package/loaders/okendo-review-aggregate-loader.js +56 -0
- package/loaders/okendo-review-aggregate-loader.js.map +7 -0
- package/loaders/okendo-reviews-loader.d.ts +23 -0
- package/loaders/okendo-reviews-loader.js +54 -0
- package/loaders/okendo-reviews-loader.js.map +7 -0
- package/loaders/prefetch-loaders.d.ts +33 -0
- package/loaders/prefetch-loaders.js +46 -0
- package/loaders/prefetch-loaders.js.map +7 -0
- package/loaders/product-loader.d.ts +11 -0
- package/loaders/product-loader.js +53 -0
- package/loaders/product-loader.js.map +7 -0
- package/loaders/rebuy-recommendations-loader.d.ts +159 -0
- package/loaders/rebuy-recommendations-loader.js +57 -0
- package/loaders/rebuy-recommendations-loader.js.map +7 -0
- package/loaders/smile-earning-rules-loader.d.ts +19 -0
- package/loaders/smile-earning-rules-loader.js +44 -0
- package/loaders/smile-earning-rules-loader.js.map +7 -0
- package/loaders/smile-rewards-loader.d.ts +19 -0
- package/loaders/smile-rewards-loader.js +44 -0
- package/loaders/smile-rewards-loader.js.map +7 -0
- package/loaders/smile-vip-tiers-loader.d.ts +18 -0
- package/loaders/smile-vip-tiers-loader.js +43 -0
- package/loaders/smile-vip-tiers-loader.js.map +7 -0
- package/package.json +29 -0
- package/providers/query-provider.d.ts +1 -0
- package/providers/query-provider.js +12 -0
- package/providers/query-provider.js.map +7 -0
- package/providers/replo-provider.d.ts +1 -0
- package/providers/replo-provider.js +20 -0
- package/providers/replo-provider.js.map +7 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { SelectModeBoundingRect, SelectModeClickPosition } from "../../../_vendor/schemas/generated/selectMode";
|
|
2
|
+
export type DragPosition = {
|
|
3
|
+
clientX: number;
|
|
4
|
+
clientY: number;
|
|
5
|
+
pageX: number;
|
|
6
|
+
pageY: number;
|
|
7
|
+
};
|
|
8
|
+
export type ScrollOffset = {
|
|
9
|
+
left: number;
|
|
10
|
+
top: number;
|
|
11
|
+
};
|
|
12
|
+
export type SelectedAreaState = {
|
|
13
|
+
pageRect: SelectModeBoundingRect;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* @author Kevin O'Connell 2026-04-17
|
|
17
|
+
*/
|
|
18
|
+
export declare function getDragPositionFromClient({ clientX, clientY, scrollOffset, }: {
|
|
19
|
+
clientX: number;
|
|
20
|
+
clientY: number;
|
|
21
|
+
scrollOffset: ScrollOffset;
|
|
22
|
+
}): DragPosition;
|
|
23
|
+
/**
|
|
24
|
+
* @author Kevin O'Connell 2026-04-17
|
|
25
|
+
*/
|
|
26
|
+
export declare function getDocumentScrollOffset(): ScrollOffset;
|
|
27
|
+
/**
|
|
28
|
+
* @author Kevin O'Connell 2026-04-17
|
|
29
|
+
*/
|
|
30
|
+
export declare function getViewportSelectionRect({ dragStart, dragCurrent, scrollOffset, }: {
|
|
31
|
+
dragStart: DragPosition;
|
|
32
|
+
dragCurrent: DragPosition;
|
|
33
|
+
scrollOffset: ScrollOffset;
|
|
34
|
+
}): SelectModeBoundingRect;
|
|
35
|
+
/**
|
|
36
|
+
* @author Kevin O'Connell 2026-04-17
|
|
37
|
+
*/
|
|
38
|
+
export declare function getPageRectFromViewportRect({ rect, scrollOffset, }: {
|
|
39
|
+
rect: SelectModeBoundingRect;
|
|
40
|
+
scrollOffset: ScrollOffset;
|
|
41
|
+
}): SelectModeBoundingRect;
|
|
42
|
+
/**
|
|
43
|
+
* @author Kevin O'Connell 2026-04-17
|
|
44
|
+
*/
|
|
45
|
+
export declare function getViewportRectFromPageRect({ rect, scrollOffset, }: {
|
|
46
|
+
rect: SelectModeBoundingRect;
|
|
47
|
+
scrollOffset: ScrollOffset;
|
|
48
|
+
}): SelectModeBoundingRect;
|
|
49
|
+
/**
|
|
50
|
+
* Returns the visible elements whose bounding rect is fully contained
|
|
51
|
+
* (within `SELECTION_TOLERANCE_PX`) by the user-drawn
|
|
52
|
+
* `selectionRect`.
|
|
53
|
+
*
|
|
54
|
+
* After containment filtering we de-duplicate ancestor wrappers that
|
|
55
|
+
* share the same bounds as one of their descendants — without this we'd
|
|
56
|
+
* emit both `<div>` and its only child `<button>` for a selection that
|
|
57
|
+
* visually contains a single button. We keep the descendant (the more
|
|
58
|
+
* specific element) by dropping any ancestor that has a same-bounds
|
|
59
|
+
* descendant in `candidates`.
|
|
60
|
+
*
|
|
61
|
+
* @author Kevin O'Connell 2026-04-17
|
|
62
|
+
*/
|
|
63
|
+
export declare function getElementsInRect(selectionRect: SelectModeBoundingRect): Element[];
|
|
64
|
+
/**
|
|
65
|
+
* Picks a "click position" for an element that fell inside an area
|
|
66
|
+
* selection. We use the corner of the element nearest the top-left of the
|
|
67
|
+
* selection rect, clamped to the element's own bounds. This anchor is what
|
|
68
|
+
* lets the selected-element overlay continue to track the element when the
|
|
69
|
+
* user scrolls (`useSelectionScrollSync` re-projects relative to it).
|
|
70
|
+
*
|
|
71
|
+
* @author Kevin O'Connell 2026-04-17
|
|
72
|
+
*/
|
|
73
|
+
export declare function getElementAnchor({ element, selectionRect, }: {
|
|
74
|
+
element: Element;
|
|
75
|
+
selectionRect: SelectModeBoundingRect;
|
|
76
|
+
}): SelectModeClickPosition;
|
|
77
|
+
/**
|
|
78
|
+
* @author Kevin O'Connell 2026-04-17
|
|
79
|
+
*/
|
|
80
|
+
export declare function getElementBoundingRect(element: Element): SelectModeBoundingRect;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
const SELECTION_TOLERANCE_PX = 4;
|
|
2
|
+
function normalizeSelectionRect({
|
|
3
|
+
startX,
|
|
4
|
+
startY,
|
|
5
|
+
endX,
|
|
6
|
+
endY
|
|
7
|
+
}) {
|
|
8
|
+
const left = Math.min(startX, endX);
|
|
9
|
+
const right = Math.max(startX, endX);
|
|
10
|
+
const top = Math.min(startY, endY);
|
|
11
|
+
const bottom = Math.max(startY, endY);
|
|
12
|
+
return {
|
|
13
|
+
x: left,
|
|
14
|
+
y: top,
|
|
15
|
+
width: right - left,
|
|
16
|
+
height: bottom - top,
|
|
17
|
+
top,
|
|
18
|
+
right,
|
|
19
|
+
bottom,
|
|
20
|
+
left
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function getDragPositionFromClient({
|
|
24
|
+
clientX,
|
|
25
|
+
clientY,
|
|
26
|
+
scrollOffset
|
|
27
|
+
}) {
|
|
28
|
+
return {
|
|
29
|
+
clientX,
|
|
30
|
+
clientY,
|
|
31
|
+
pageX: clientX + scrollOffset.left,
|
|
32
|
+
pageY: clientY + scrollOffset.top
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function getDocumentScrollOffset() {
|
|
36
|
+
const scrollingElement = document.scrollingElement;
|
|
37
|
+
return {
|
|
38
|
+
left: scrollingElement?.scrollLeft ?? window.scrollX,
|
|
39
|
+
top: scrollingElement?.scrollTop ?? window.scrollY
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function getViewportSelectionRect({
|
|
43
|
+
dragStart,
|
|
44
|
+
dragCurrent,
|
|
45
|
+
scrollOffset
|
|
46
|
+
}) {
|
|
47
|
+
return normalizeSelectionRect({
|
|
48
|
+
startX: dragStart.pageX - scrollOffset.left,
|
|
49
|
+
startY: dragStart.pageY - scrollOffset.top,
|
|
50
|
+
endX: dragCurrent.pageX - scrollOffset.left,
|
|
51
|
+
endY: dragCurrent.pageY - scrollOffset.top
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function getPageRectFromViewportRect({
|
|
55
|
+
rect,
|
|
56
|
+
scrollOffset
|
|
57
|
+
}) {
|
|
58
|
+
return {
|
|
59
|
+
x: rect.x + scrollOffset.left,
|
|
60
|
+
y: rect.y + scrollOffset.top,
|
|
61
|
+
width: rect.width,
|
|
62
|
+
height: rect.height,
|
|
63
|
+
left: rect.left + scrollOffset.left,
|
|
64
|
+
top: rect.top + scrollOffset.top,
|
|
65
|
+
right: rect.right + scrollOffset.left,
|
|
66
|
+
bottom: rect.bottom + scrollOffset.top
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function getViewportRectFromPageRect({
|
|
70
|
+
rect,
|
|
71
|
+
scrollOffset
|
|
72
|
+
}) {
|
|
73
|
+
return {
|
|
74
|
+
x: rect.x - scrollOffset.left,
|
|
75
|
+
y: rect.y - scrollOffset.top,
|
|
76
|
+
width: rect.width,
|
|
77
|
+
height: rect.height,
|
|
78
|
+
left: rect.left - scrollOffset.left,
|
|
79
|
+
top: rect.top - scrollOffset.top,
|
|
80
|
+
right: rect.right - scrollOffset.left,
|
|
81
|
+
bottom: rect.bottom - scrollOffset.top
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function isMeaningfulElement(element) {
|
|
85
|
+
const tagName = element.tagName.toLowerCase();
|
|
86
|
+
if (["html", "body", "script", "style", "meta", "link"].includes(tagName)) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
const elementRect = element.getBoundingClientRect();
|
|
90
|
+
if (elementRect.width < 4 || elementRect.height < 4) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
function isRectContainedWithinSelection({
|
|
96
|
+
elementRect,
|
|
97
|
+
selectionRect,
|
|
98
|
+
tolerancePx
|
|
99
|
+
}) {
|
|
100
|
+
return elementRect.left >= selectionRect.left - tolerancePx && elementRect.right <= selectionRect.right + tolerancePx && elementRect.top >= selectionRect.top - tolerancePx && elementRect.bottom <= selectionRect.bottom + tolerancePx;
|
|
101
|
+
}
|
|
102
|
+
function getElementsInRect(selectionRect) {
|
|
103
|
+
const candidates = Array.from(document.querySelectorAll("*")).filter(isMeaningfulElement).map((element) => {
|
|
104
|
+
return {
|
|
105
|
+
element,
|
|
106
|
+
elementRect: element.getBoundingClientRect()
|
|
107
|
+
};
|
|
108
|
+
}).filter(({ elementRect }) => {
|
|
109
|
+
return isRectContainedWithinSelection({
|
|
110
|
+
elementRect,
|
|
111
|
+
selectionRect,
|
|
112
|
+
tolerancePx: SELECTION_TOLERANCE_PX
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
return candidates.filter(({ element, elementRect }, index, allCandidates) => {
|
|
116
|
+
return !allCandidates.some((otherCandidate, otherIndex) => {
|
|
117
|
+
if (index === otherIndex) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
const sameBounds = Math.abs(otherCandidate.elementRect.left - elementRect.left) < 1 && Math.abs(otherCandidate.elementRect.top - elementRect.top) < 1 && Math.abs(otherCandidate.elementRect.width - elementRect.width) < 1 && Math.abs(otherCandidate.elementRect.height - elementRect.height) < 1;
|
|
121
|
+
return sameBounds && element.contains(otherCandidate.element) && element !== otherCandidate.element;
|
|
122
|
+
});
|
|
123
|
+
}).map(({ element }) => {
|
|
124
|
+
return element;
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
function getElementAnchor({
|
|
128
|
+
element,
|
|
129
|
+
selectionRect
|
|
130
|
+
}) {
|
|
131
|
+
const rect = element.getBoundingClientRect();
|
|
132
|
+
return {
|
|
133
|
+
x: Math.min(Math.max(selectionRect.left, rect.left), rect.right),
|
|
134
|
+
y: Math.min(Math.max(selectionRect.top, rect.top), rect.bottom)
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function getElementBoundingRect(element) {
|
|
138
|
+
const rect = element.getBoundingClientRect();
|
|
139
|
+
return {
|
|
140
|
+
x: rect.x,
|
|
141
|
+
y: rect.y,
|
|
142
|
+
width: rect.width,
|
|
143
|
+
height: rect.height,
|
|
144
|
+
top: rect.top,
|
|
145
|
+
right: rect.right,
|
|
146
|
+
bottom: rect.bottom,
|
|
147
|
+
left: rect.left
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
export {
|
|
151
|
+
getDocumentScrollOffset,
|
|
152
|
+
getDragPositionFromClient,
|
|
153
|
+
getElementAnchor,
|
|
154
|
+
getElementBoundingRect,
|
|
155
|
+
getElementsInRect,
|
|
156
|
+
getPageRectFromViewportRect,
|
|
157
|
+
getViewportRectFromPageRect,
|
|
158
|
+
getViewportSelectionRect
|
|
159
|
+
};
|
|
160
|
+
//# sourceMappingURL=selectionGeometry.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../editor/select-mode/interactions/selectionGeometry.ts"],
|
|
4
|
+
"sourcesContent": ["import type {\n SelectModeBoundingRect,\n SelectModeClickPosition,\n} from \"schemas/generated/selectMode\";\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 (Kevin O'Connell, 2026-04-21): A small fudge factor so elements\n// that visually appear contained in the selection rect (but whose bounding\n// box overflows by a pixel or two due to borders/sub-pixel rendering)\n// still get 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(element: Element): boolean {\n const tagName = element.tagName.toLowerCase();\n if ([\"html\", \"body\", \"script\", \"style\", \"meta\", \"link\"].includes(tagName)) {\n return false;\n }\n\n const elementRect = element.getBoundingClientRect();\n if (elementRect.width < 4 || elementRect.height < 4) {\n return false;\n }\n\n return true;\n}\n\nfunction isRectContainedWithinSelection({\n elementRect,\n selectionRect,\n tolerancePx,\n}: {\n elementRect: DOMRect;\n selectionRect: SelectModeBoundingRect;\n tolerancePx: number;\n}) {\n return (\n elementRect.left >= selectionRect.left - tolerancePx &&\n elementRect.right <= selectionRect.right + tolerancePx &&\n elementRect.top >= selectionRect.top - tolerancePx &&\n elementRect.bottom <= selectionRect.bottom + tolerancePx\n );\n}\n\n/**\n * Returns the visible elements whose bounding rect is fully contained\n * (within `SELECTION_TOLERANCE_PX`) by the user-drawn\n * `selectionRect`.\n *\n * After containment filtering we de-duplicate ancestor wrappers that\n * share the same bounds as one of their descendants \u2014 without this we'd\n * emit both `<div>` and its only child `<button>` for a selection that\n * visually contains a single button. We keep the descendant (the more\n * specific element) by dropping any ancestor that has a same-bounds\n * descendant in `candidates`.\n *\n * @author Kevin O'Connell 2026-04-17\n */\nexport function getElementsInRect(\n selectionRect: SelectModeBoundingRect,\n): Element[] {\n const candidates = Array.from(document.querySelectorAll(\"*\"))\n .filter(isMeaningfulElement)\n .map((element) => {\n return {\n element,\n elementRect: element.getBoundingClientRect(),\n };\n })\n .filter(({ elementRect }) => {\n return isRectContainedWithinSelection({\n elementRect,\n selectionRect,\n tolerancePx: SELECTION_TOLERANCE_PX,\n });\n });\n\n return candidates\n .filter(({ element, elementRect }, index, allCandidates) => {\n return !allCandidates.some((otherCandidate, otherIndex) => {\n if (index === otherIndex) {\n return false;\n }\n\n const sameBounds =\n Math.abs(otherCandidate.elementRect.left - elementRect.left) < 1 &&\n Math.abs(otherCandidate.elementRect.top - elementRect.top) < 1 &&\n Math.abs(otherCandidate.elementRect.width - elementRect.width) < 1 &&\n Math.abs(otherCandidate.elementRect.height - elementRect.height) < 1;\n\n return (\n sameBounds &&\n element.contains(otherCandidate.element) &&\n element !== otherCandidate.element\n );\n });\n })\n .map(({ element }) => {\n return element;\n });\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": "AAyBA,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,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AAe,YAAY,OAAO,YAAY,IAAI,IAAI,KAC/D,KAAK,IAAI,eAAe,YAAY,MAAM,YAAY,GAAG,IAAI,KAC7D,KAAK,IAAI,eAAe,YAAY,QAAQ,YAAY,KAAK,IAAI,KACjE,KAAK,IAAI,eAAe,YAAY,SAAS,YAAY,MAAM,IAAI;AAErE,aACE,cACA,QAAQ,SAAS,eAAe,OAAO,KACvC,YAAY,eAAe;AAAA,IAE/B,CAAC;AAAA,EACH,CAAC,EACA,IAAI,CAAC,EAAE,QAAQ,MAAM;AACpB,WAAO;AAAA,EACT,CAAC;AACL;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
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { SelectableData, SelectModeBoundingRect, SelectModeClickPosition, SelectModeSelectionType } from "../../_vendor/schemas/generated/selectMode";
|
|
2
|
+
import type { DragPosition, ScrollOffset } from "./interactions/selectionGeometry";
|
|
3
|
+
export type SelectModeInteractionSession = {
|
|
4
|
+
type: Extract<SelectModeSelectionType, "none">;
|
|
5
|
+
} | {
|
|
6
|
+
type: Extract<SelectModeSelectionType, "drag">;
|
|
7
|
+
dragStart: DragPosition;
|
|
8
|
+
dragCurrent: DragPosition;
|
|
9
|
+
scrollOffset: ScrollOffset;
|
|
10
|
+
hasExceededThreshold: boolean;
|
|
11
|
+
} | {
|
|
12
|
+
type: Extract<SelectModeSelectionType, "element">;
|
|
13
|
+
element: Element;
|
|
14
|
+
clickPosition: SelectModeClickPosition | null;
|
|
15
|
+
data: SelectableData;
|
|
16
|
+
} | {
|
|
17
|
+
type: Extract<SelectModeSelectionType, "area">;
|
|
18
|
+
pageRect: SelectModeBoundingRect;
|
|
19
|
+
items: SelectableData[];
|
|
20
|
+
};
|
|
21
|
+
export declare const IDLE_SESSION: SelectModeInteractionSession;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../editor/select-mode/selectModeSession.ts"],
|
|
4
|
+
"sourcesContent": ["import type {\n SelectableData,\n SelectModeBoundingRect,\n SelectModeClickPosition,\n SelectModeSelectionType,\n} from \"schemas/generated/selectMode\";\nimport type {\n DragPosition,\n ScrollOffset,\n} from \"./interactions/selectionGeometry\";\n\n// NOTE (Kevin O'Connell, 2026-04-22, REPL-26014): SDK-internal liveness\n// state for the active drag/select interaction. Looks like a near-\n// duplicate of agent-ui's `SelectModeSelection` (now in\n// `schemas/selectMode.ts`), but deliberately not lifted into\n// `packages/schemas` for two reasons:\n//\n// 1. The `element` variant carries `element: Element` \u2014 a live DOM\n// ref. Zod has no way to model that; `z.custom<Element>()` would\n// regress to `any` in the generated `.ts` (see the `ZodCustom`\n// branch in `packages/schemas/zod/generateTypeDefinition.ts`),\n// which would lose the strong typing the rest of the SDK relies\n// on when it reads `session.element.getBoundingClientRect()`,\n// etc.\n// 2. There is no second consumer. This type is used only inside\n// `packages/canopy-sdk/editor/select-mode/`; the parent side\n// (agent-ui) consumes the serialized `SelectModeSelection`\n// instead. Lifting it would move a single-package-internal type\n// into a shared package without any cross-package reader.\n//\n// What we *do* share with the schema is the discriminator vocabulary:\n// the literals come from `SelectModeSelectionType` (generated from\n// `selectModeSelectionTypeSchema` in `schemas/selectMode.ts`), so\n// adding or renaming a selection variant is a TS error here, in\n// `SelectModeSelection`, and in `SelectModeEditSelectionMetadata`.\nexport type SelectModeInteractionSession =\n | { type: Extract<SelectModeSelectionType, \"none\"> }\n | {\n type: Extract<SelectModeSelectionType, \"drag\">;\n dragStart: DragPosition;\n dragCurrent: DragPosition;\n scrollOffset: ScrollOffset;\n hasExceededThreshold: boolean;\n }\n | {\n type: Extract<SelectModeSelectionType, \"element\">;\n element: Element;\n clickPosition: SelectModeClickPosition | null;\n data: SelectableData;\n }\n | {\n type: Extract<SelectModeSelectionType, \"area\">;\n pageRect: SelectModeBoundingRect;\n items: SelectableData[];\n };\n\nexport const IDLE_SESSION: SelectModeInteractionSession = {\n type: \"none\",\n};\n"],
|
|
5
|
+
"mappings": "AAwDO,MAAM,eAA6C;AAAA,EACxD,MAAM;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-iframe selection frame renderer.
|
|
3
|
+
*
|
|
4
|
+
* Lives in the canopy iframe (not in agent-ui) because the previous
|
|
5
|
+
* parent-side overlay had to be re-anchored on every scroll frame via
|
|
6
|
+
* postMessage hop -> Zustand update -> React reconciliation, which
|
|
7
|
+
* shows up as visible lag when the user scrolls quickly.
|
|
8
|
+
*
|
|
9
|
+
* By rendering directly inside the canopy iframe's document we get two
|
|
10
|
+
* properties for free:
|
|
11
|
+
*
|
|
12
|
+
* 1. `position: absolute` + page coordinates means the document's own
|
|
13
|
+
* scroll naturally translates the frame — zero JavaScript per
|
|
14
|
+
* scroll frame, the browser composites it with the underlying page
|
|
15
|
+
* content.
|
|
16
|
+
* 2. No bridge serialization: the only cost when selection commits is
|
|
17
|
+
* a handful of style writes on a single DOM node.
|
|
18
|
+
*
|
|
19
|
+
* The canopy iframe loads a customer page and doesn't include lattice /
|
|
20
|
+
* tailwind, so styling is intentionally vanilla inline CSS rather than
|
|
21
|
+
* Tailwind classes.
|
|
22
|
+
*
|
|
23
|
+
* @author Kevin O'Connell 2026-05-26
|
|
24
|
+
*/
|
|
25
|
+
type SelectionFrameVariant = "element" | "area";
|
|
26
|
+
type SelectionFramePageRect = {
|
|
27
|
+
x: number;
|
|
28
|
+
y: number;
|
|
29
|
+
width: number;
|
|
30
|
+
height: number;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Position the singleton selection frame at the given *page*
|
|
34
|
+
* coordinates. Page coords don't shift during scroll, so the caller is
|
|
35
|
+
* free to call this once at commit time and let the browser handle the
|
|
36
|
+
* rest of the scroll lifetime.
|
|
37
|
+
*
|
|
38
|
+
* @author Kevin O'Connell 2026-05-26
|
|
39
|
+
*/
|
|
40
|
+
export declare function showSelectionFrame({ pageRect, variant, }: {
|
|
41
|
+
pageRect: SelectionFramePageRect;
|
|
42
|
+
variant: SelectionFrameVariant;
|
|
43
|
+
}): void;
|
|
44
|
+
/**
|
|
45
|
+
* @author Kevin O'Connell 2026-05-26
|
|
46
|
+
*/
|
|
47
|
+
export declare function hideSelectionFrame(): void;
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const FUCHSIA_HEX = "#c026d3";
|
|
2
|
+
const FRAME_ELEMENT_ID = "replo-select-mode-selection-frame";
|
|
3
|
+
function applyVariantStyle({
|
|
4
|
+
frame,
|
|
5
|
+
variant
|
|
6
|
+
}) {
|
|
7
|
+
if (variant === "area") {
|
|
8
|
+
frame.style.border = `1px solid ${FUCHSIA_HEX}`;
|
|
9
|
+
frame.style.background = "rgba(192, 38, 211, 0.08)";
|
|
10
|
+
} else {
|
|
11
|
+
frame.style.border = `2px solid ${FUCHSIA_HEX}`;
|
|
12
|
+
frame.style.background = "transparent";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function getOrCreateFrame() {
|
|
16
|
+
if (typeof document === "undefined") {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
const existing = document.getElementById(FRAME_ELEMENT_ID);
|
|
20
|
+
if (existing instanceof HTMLDivElement) {
|
|
21
|
+
return existing;
|
|
22
|
+
}
|
|
23
|
+
const frame = document.createElement("div");
|
|
24
|
+
frame.id = FRAME_ELEMENT_ID;
|
|
25
|
+
frame.setAttribute("aria-hidden", "true");
|
|
26
|
+
frame.style.cssText = [
|
|
27
|
+
"position: absolute",
|
|
28
|
+
"top: 0",
|
|
29
|
+
"left: 0",
|
|
30
|
+
"width: 0",
|
|
31
|
+
"height: 0",
|
|
32
|
+
"pointer-events: none",
|
|
33
|
+
"box-sizing: border-box",
|
|
34
|
+
"border-radius: 2px",
|
|
35
|
+
"z-index: 2147483646",
|
|
36
|
+
"display: none",
|
|
37
|
+
"margin: 0",
|
|
38
|
+
"padding: 0"
|
|
39
|
+
].join(";");
|
|
40
|
+
if (!document.body) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
document.body.append(frame);
|
|
44
|
+
return frame;
|
|
45
|
+
}
|
|
46
|
+
function showSelectionFrame({
|
|
47
|
+
pageRect,
|
|
48
|
+
variant
|
|
49
|
+
}) {
|
|
50
|
+
const frame = getOrCreateFrame();
|
|
51
|
+
if (!frame) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
applyVariantStyle({ frame, variant });
|
|
55
|
+
frame.style.left = `${pageRect.x}px`;
|
|
56
|
+
frame.style.top = `${pageRect.y}px`;
|
|
57
|
+
frame.style.width = `${pageRect.width}px`;
|
|
58
|
+
frame.style.height = `${pageRect.height}px`;
|
|
59
|
+
frame.style.display = "block";
|
|
60
|
+
}
|
|
61
|
+
function hideSelectionFrame() {
|
|
62
|
+
if (typeof document === "undefined") {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const frame = document.getElementById(FRAME_ELEMENT_ID);
|
|
66
|
+
if (frame instanceof HTMLDivElement) {
|
|
67
|
+
frame.style.display = "none";
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export {
|
|
71
|
+
hideSelectionFrame,
|
|
72
|
+
showSelectionFrame
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=selectionFrame.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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 frame \u2014 zero JavaScript per\n * scroll frame, the browser composites it 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 a single DOM node.\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 FRAME_ELEMENT_ID = \"replo-select-mode-selection-frame\";\n\ntype SelectionFrameVariant = \"element\" | \"area\";\n\ntype SelectionFramePageRect = {\n x: number;\n y: number;\n width: number;\n height: number;\n};\n\nfunction applyVariantStyle({\n frame,\n variant,\n}: {\n frame: HTMLDivElement;\n variant: SelectionFrameVariant;\n}) {\n if (variant === \"area\") {\n frame.style.border = `1px solid ${FUCHSIA_HEX}`;\n frame.style.background = \"rgba(192, 38, 211, 0.08)\";\n } else {\n frame.style.border = `2px solid ${FUCHSIA_HEX}`;\n frame.style.background = \"transparent\";\n }\n}\n\nfunction getOrCreateFrame(): HTMLDivElement | null {\n if (typeof document === \"undefined\") {\n return null;\n }\n const existing = document.getElementById(FRAME_ELEMENT_ID);\n if (existing instanceof HTMLDivElement) {\n return existing;\n }\n const frame = document.createElement(\"div\");\n frame.id = FRAME_ELEMENT_ID;\n frame.setAttribute(\"aria-hidden\", \"true\");\n frame.style.cssText = [\n \"position: absolute\",\n \"top: 0\",\n \"left: 0\",\n \"width: 0\",\n \"height: 0\",\n \"pointer-events: none\",\n \"box-sizing: border-box\",\n \"border-radius: 2px\",\n \"z-index: 2147483646\",\n \"display: none\",\n \"margin: 0\",\n \"padding: 0\",\n ].join(\";\");\n if (!document.body) {\n return null;\n }\n document.body.append(frame);\n return frame;\n}\n\n/**\n * Position the singleton selection frame at the given *page*\n * coordinates. Page coords don't shift during scroll, so the caller is\n * free to call this once at commit time and let the browser handle the\n * rest of the scroll lifetime.\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 const frame = getOrCreateFrame();\n if (!frame) {\n return;\n }\n applyVariantStyle({ frame, variant });\n frame.style.left = `${pageRect.x}px`;\n frame.style.top = `${pageRect.y}px`;\n frame.style.width = `${pageRect.width}px`;\n frame.style.height = `${pageRect.height}px`;\n frame.style.display = \"block\";\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 frame = document.getElementById(FRAME_ELEMENT_ID);\n if (frame instanceof HTMLDivElement) {\n frame.style.display = \"none\";\n }\n}\n"],
|
|
5
|
+
"mappings": "AA4BA,MAAM,cAAc;AAEpB,MAAM,mBAAmB;AAWzB,SAAS,kBAAkB;AAAA,EACzB;AAAA,EACA;AACF,GAGG;AACD,MAAI,YAAY,QAAQ;AACtB,UAAM,MAAM,SAAS,aAAa,WAAW;AAC7C,UAAM,MAAM,aAA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1
|
+
import type { SelectedElement } from "../../_vendor/schemas/generated/selectMode";
|
|
2
|
+
export declare function symbolicateSelectedElement(selectedElement: SelectedElement): Promise<SelectedElement>;
|
|
3
|
+
export declare function symbolicateSelectedElements(elements: SelectedElement[]): Promise<SelectedElement[]>;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
const SYMBOLICATE_ENDPOINT = "/__nextjs_original-stack-frames";
|
|
2
|
+
function isLikelyCompiledLocation(location) {
|
|
3
|
+
if (!location) {
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
const filePath = location.filePath;
|
|
7
|
+
return filePath.includes(".next") || filePath.includes("/chunks/") || filePath.includes("webpack-internal:") || filePath.includes("turbopack:") || filePath.endsWith(".js") || filePath.startsWith("about:");
|
|
8
|
+
}
|
|
9
|
+
function isServerChunk(filePath) {
|
|
10
|
+
return filePath.startsWith("about://React/Server") || filePath.includes("/server/chunks/") || filePath.includes(".next-dev/dev/server/") || filePath.includes(".next/server/");
|
|
11
|
+
}
|
|
12
|
+
function normalizeFilePathForSymbolicator(filePath) {
|
|
13
|
+
let normalized = filePath;
|
|
14
|
+
if (normalized.startsWith("about://React/Server/")) {
|
|
15
|
+
normalized = normalized.slice("about://React/Server/".length);
|
|
16
|
+
}
|
|
17
|
+
return normalized.replace(/\?\d+$/, "");
|
|
18
|
+
}
|
|
19
|
+
function toNextStackFrame(location) {
|
|
20
|
+
return {
|
|
21
|
+
file: normalizeFilePathForSymbolicator(location.filePath),
|
|
22
|
+
methodName: location.componentName ?? null,
|
|
23
|
+
arguments: [],
|
|
24
|
+
line1: location.lineNumber,
|
|
25
|
+
column1: location.columnNumber ?? null
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function extractResolvedFrame(entry) {
|
|
29
|
+
if (!entry || entry.status !== "fulfilled") {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return entry.value?.originalStackFrame ?? null;
|
|
33
|
+
}
|
|
34
|
+
async function postFrames({
|
|
35
|
+
frames,
|
|
36
|
+
isServer
|
|
37
|
+
}) {
|
|
38
|
+
if (frames.length === 0) {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const response = await fetch(SYMBOLICATE_ENDPOINT, {
|
|
43
|
+
method: "POST",
|
|
44
|
+
headers: { "content-type": "application/json" },
|
|
45
|
+
body: JSON.stringify({
|
|
46
|
+
frames,
|
|
47
|
+
isServer,
|
|
48
|
+
isEdgeServer: false,
|
|
49
|
+
isAppDirectory: true
|
|
50
|
+
})
|
|
51
|
+
});
|
|
52
|
+
if (!response.ok) {
|
|
53
|
+
console.log("[selectMode] symbolicate: endpoint returned non-OK status", {
|
|
54
|
+
status: response.status,
|
|
55
|
+
isServer
|
|
56
|
+
});
|
|
57
|
+
return frames.map(() => null);
|
|
58
|
+
}
|
|
59
|
+
const parsed = await response.json();
|
|
60
|
+
if (Array.isArray(parsed)) {
|
|
61
|
+
return parsed;
|
|
62
|
+
}
|
|
63
|
+
return frames.map(() => null);
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.log("[selectMode] symbolicate: fetch failed", {
|
|
66
|
+
isServer,
|
|
67
|
+
error
|
|
68
|
+
});
|
|
69
|
+
return frames.map(() => null);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async function symbolicateFrames(frames) {
|
|
73
|
+
const serverIndices = [];
|
|
74
|
+
const clientIndices = [];
|
|
75
|
+
for (const [index, frame] of frames.entries()) {
|
|
76
|
+
if (frame.file && isServerChunk(frame.file)) {
|
|
77
|
+
serverIndices.push(index);
|
|
78
|
+
} else {
|
|
79
|
+
clientIndices.push(index);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const [serverResults, clientResults] = await Promise.all([
|
|
83
|
+
postFrames({
|
|
84
|
+
frames: serverIndices.map((index) => frames[index]),
|
|
85
|
+
isServer: true
|
|
86
|
+
}),
|
|
87
|
+
postFrames({
|
|
88
|
+
frames: clientIndices.map((index) => frames[index]),
|
|
89
|
+
isServer: false
|
|
90
|
+
})
|
|
91
|
+
]);
|
|
92
|
+
const merged = frames.map(() => null);
|
|
93
|
+
for (const [position, index] of serverIndices.entries()) {
|
|
94
|
+
merged[index] = serverResults[position] ?? null;
|
|
95
|
+
}
|
|
96
|
+
for (const [position, index] of clientIndices.entries()) {
|
|
97
|
+
merged[index] = clientResults[position] ?? null;
|
|
98
|
+
}
|
|
99
|
+
return merged;
|
|
100
|
+
}
|
|
101
|
+
function applyResolved({
|
|
102
|
+
original,
|
|
103
|
+
frame
|
|
104
|
+
}) {
|
|
105
|
+
if (!frame || !frame.file || frame.line1 == null) {
|
|
106
|
+
return original;
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
filePath: frame.file,
|
|
110
|
+
lineNumber: frame.line1,
|
|
111
|
+
columnNumber: frame.column1 ?? void 0,
|
|
112
|
+
componentName: original.componentName
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
async function symbolicateSelectedElement(selectedElement) {
|
|
116
|
+
const sourceLocation = selectedElement.sourceLocation;
|
|
117
|
+
if (!sourceLocation || !isLikelyCompiledLocation(sourceLocation)) {
|
|
118
|
+
return selectedElement;
|
|
119
|
+
}
|
|
120
|
+
const resolved = await symbolicateFrames([toNextStackFrame(sourceLocation)]);
|
|
121
|
+
const frame = extractResolvedFrame(resolved[0] ?? null);
|
|
122
|
+
const nextLocation = applyResolved({ original: sourceLocation, frame });
|
|
123
|
+
console.log("[selectMode] symbolicate: resolved", {
|
|
124
|
+
before: sourceLocation.filePath,
|
|
125
|
+
after: nextLocation.filePath
|
|
126
|
+
});
|
|
127
|
+
return {
|
|
128
|
+
...selectedElement,
|
|
129
|
+
sourceLocation: nextLocation
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
async function symbolicateSelectedElements(elements) {
|
|
133
|
+
return Promise.all(elements.map(symbolicateSelectedElement));
|
|
134
|
+
}
|
|
135
|
+
export {
|
|
136
|
+
symbolicateSelectedElement,
|
|
137
|
+
symbolicateSelectedElements
|
|
138
|
+
};
|
|
139
|
+
//# sourceMappingURL=symbolicate.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../editor/select-mode/symbolicate.ts"],
|
|
4
|
+
"sourcesContent": ["import type {\n SelectedElement,\n SelectModeSourceLocation,\n} from \"schemas/generated/selectMode\";\n\n/**\n * Runtime source-attribution for React 19 + Next.js Turbopack.\n *\n * React 19 removed `fiber._debugSource`; the only per-element source pointer\n * left is `fiber._debugStack`, whose `.stack` references compiled SSR/client\n * chunks. We POST those compiled frames to Next.js's dev-only\n * `/__nextjs_original-stack-frames` endpoint, which symbolicates them through\n * Turbopack's in-memory source maps \u2014 the same mechanism the Next error\n * overlay uses (see `next/dist/server/dev/middleware-turbopack.js`).\n */\n\ntype NextStackFrame = {\n file: string | null;\n methodName: string | null;\n arguments: string[];\n // Next.js's `/__nextjs_original-stack-frames` reads these as `line1`/`column1`\n // (1-based) in the request body \u2014 same field names it uses in the response.\n // Sending `lineNumber`/`column` is silently dropped on the server side.\n line1: number | null;\n column1: number | null;\n};\n\ntype ResolvedFrame = {\n file: string | null;\n line1?: number | null;\n column1?: number | null;\n methodName?: string | null;\n ignored?: boolean;\n arguments?: string[];\n};\n\ntype OriginalStackFrameResponse = {\n originalStackFrame: ResolvedFrame | null;\n originalCodeFrame: string | null;\n};\n\ntype SettledResponseEntry =\n | { status: \"fulfilled\"; value: OriginalStackFrameResponse }\n | { status: \"rejected\"; reason: string };\n\nconst SYMBOLICATE_ENDPOINT = \"/__nextjs_original-stack-frames\";\n\nfunction isLikelyCompiledLocation(\n location: SelectModeSourceLocation | undefined,\n): boolean {\n if (!location) {\n return false;\n }\n const filePath = location.filePath;\n return (\n filePath.includes(\".next\") ||\n filePath.includes(\"/chunks/\") ||\n filePath.includes(\"webpack-internal:\") ||\n filePath.includes(\"turbopack:\") ||\n filePath.endsWith(\".js\") ||\n filePath.startsWith(\"about:\")\n );\n}\n\n// React 19 fibers for server-rendered (RSC) elements carry a `_debugStack`\n// whose top frame points at an SSR chunk. The endpoint resolves those\n// against the server bundler context; client chunks go through the client\n// bundler context. Mis-routing returns the compiled chunk unchanged.\nfunction isServerChunk(filePath: string): boolean {\n return (\n filePath.startsWith(\"about://React/Server\") ||\n filePath.includes(\"/server/chunks/\") ||\n filePath.includes(\".next-dev/dev/server/\") ||\n filePath.includes(\".next/server/\")\n );\n}\n\n// React 19's `_debugStack.stack` for RSC components wraps the SSR chunk URL\n// in an `about://React/Server/` prefix and appends a `?<digits>` cache-buster.\n// Turbopack's source-map lookup matches against the bare chunk URL; with\n// either decoration in place it returns the compiled chunk unchanged.\nfunction normalizeFilePathForSymbolicator(filePath: string): string {\n let normalized = filePath;\n if (normalized.startsWith(\"about://React/Server/\")) {\n normalized = normalized.slice(\"about://React/Server/\".length);\n }\n return normalized.replace(/\\?\\d+$/, \"\");\n}\n\nfunction toNextStackFrame(location: SelectModeSourceLocation): NextStackFrame {\n return {\n file: normalizeFilePathForSymbolicator(location.filePath),\n methodName: location.componentName ?? null,\n arguments: [],\n line1: location.lineNumber,\n column1: location.columnNumber ?? null,\n };\n}\n\nfunction extractResolvedFrame(\n entry: SettledResponseEntry | null,\n): ResolvedFrame | null {\n if (!entry || entry.status !== \"fulfilled\") {\n return null;\n }\n return entry.value?.originalStackFrame ?? null;\n}\n\nasync function postFrames({\n frames,\n isServer,\n}: {\n frames: NextStackFrame[];\n isServer: boolean;\n}): Promise<(SettledResponseEntry | null)[]> {\n if (frames.length === 0) {\n return [];\n }\n try {\n const response = await fetch(SYMBOLICATE_ENDPOINT, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n frames,\n isServer,\n isEdgeServer: false,\n isAppDirectory: true,\n }),\n });\n if (!response.ok) {\n console.log(\"[selectMode] symbolicate: endpoint returned non-OK status\", {\n status: response.status,\n isServer,\n });\n return frames.map(() => null);\n }\n const parsed: unknown = await response.json();\n if (Array.isArray(parsed)) {\n // Promise.allSettled-shaped entries; see\n // node_modules/next/dist/server/dev/middleware-turbopack.js.\n // Legacy cast - the runtime shape isn't exported as a type.\n // eslint-disable-next-line replo/no-as-cast\n return parsed as (SettledResponseEntry | null)[];\n }\n return frames.map(() => null);\n } catch (error) {\n console.log(\"[selectMode] symbolicate: fetch failed\", {\n isServer,\n error,\n });\n return frames.map(() => null);\n }\n}\n\nasync function symbolicateFrames(\n frames: NextStackFrame[],\n): Promise<(SettledResponseEntry | null)[]> {\n const serverIndices: number[] = [];\n const clientIndices: number[] = [];\n for (const [index, frame] of frames.entries()) {\n if (frame.file && isServerChunk(frame.file)) {\n serverIndices.push(index);\n } else {\n clientIndices.push(index);\n }\n }\n\n const [serverResults, clientResults] = await Promise.all([\n postFrames({\n frames: serverIndices.map((index) => frames[index]!),\n isServer: true,\n }),\n postFrames({\n frames: clientIndices.map((index) => frames[index]!),\n isServer: false,\n }),\n ]);\n\n const merged: (SettledResponseEntry | null)[] = frames.map(() => null);\n for (const [position, index] of serverIndices.entries()) {\n merged[index] = serverResults[position] ?? null;\n }\n for (const [position, index] of clientIndices.entries()) {\n merged[index] = clientResults[position] ?? null;\n }\n return merged;\n}\n\nfunction applyResolved({\n original,\n frame,\n}: {\n original: SelectModeSourceLocation;\n frame: ResolvedFrame | null;\n}): SelectModeSourceLocation {\n if (!frame || !frame.file || frame.line1 == null) {\n return original;\n }\n return {\n filePath: frame.file,\n lineNumber: frame.line1,\n columnNumber: frame.column1 ?? undefined,\n componentName: original.componentName,\n };\n}\n\nexport async function symbolicateSelectedElement(\n selectedElement: SelectedElement,\n): Promise<SelectedElement> {\n const sourceLocation = selectedElement.sourceLocation;\n if (!sourceLocation || !isLikelyCompiledLocation(sourceLocation)) {\n return selectedElement;\n }\n\n const resolved = await symbolicateFrames([toNextStackFrame(sourceLocation)]);\n const frame = extractResolvedFrame(resolved[0] ?? null);\n const nextLocation = applyResolved({ original: sourceLocation, frame });\n\n console.log(\"[selectMode] symbolicate: resolved\", {\n before: sourceLocation.filePath,\n after: nextLocation.filePath,\n });\n\n return {\n ...selectedElement,\n sourceLocation: nextLocation,\n };\n}\n\nexport async function symbolicateSelectedElements(\n elements: SelectedElement[],\n): Promise<SelectedElement[]> {\n return Promise.all(elements.map(symbolicateSelectedElement));\n}\n"],
|
|
5
|
+
"mappings": "AA6CA,MAAM,uBAAuB;AAE7B,SAAS,yBACP,UACS;AACT,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AACA,QAAM,WAAW,SAAS;AAC1B,SACE,SAAS,SAAS,OAAO,KACzB,SAAS,SAAS,UAAU,KAC5B,SAAS,SAAS,mBAAmB,KACrC,SAAS,SAAS,YAAY,KAC9B,SAAS,SAAS,KAAK,KACvB,SAAS,WAAW,QAAQ;AAEhC;AAMA,SAAS,cAAc,UAA2B;AAChD,SACE,SAAS,WAAW,sBAAsB,KAC1C,SAAS,SAAS,iBAAiB,KACnC,SAAS,SAAS,uBAAuB,KACzC,SAAS,SAAS,eAAe;AAErC;AAMA,SAAS,iCAAiC,UAA0B;AAClE,MAAI,aAAa;AACjB,MAAI,WAAW,WAAW,uBAAuB,GAAG;AAClD,iBAAa,WAAW,MAAM,wBAAwB,MAAM;AAAA,EAC9D;AACA,SAAO,WAAW,QAAQ,UAAU,EAAE;AACxC;AAEA,SAAS,iBAAiB,UAAoD;AAC5E,SAAO;AAAA,IACL,MAAM,iCAAiC,SAAS,QAAQ;AAAA,IACxD,YAAY,SAAS,iBAAiB;AAAA,IACtC,WAAW,CAAC;AAAA,IACZ,OAAO,SAAS;AAAA,IAChB,SAAS,SAAS,gBAAgB;AAAA,EACpC;AACF;AAEA,SAAS,qBACP,OACsB;AACtB,MAAI,CAAC,SAAS,MAAM,WAAW,aAAa;AAC1C,WAAO;AAAA,EACT;AACA,SAAO,MAAM,OAAO,sBAAsB;AAC5C;AAEA,eAAe,WAAW;AAAA,EACxB;AAAA,EACA;AACF,GAG6C;AAC3C,MAAI,OAAO,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,13 @@
|
|
|
1
|
+
type Env = {
|
|
2
|
+
CANOPY_API_HOST: string;
|
|
3
|
+
PROJECT_ID: string;
|
|
4
|
+
SHOPIFY_URL?: string;
|
|
5
|
+
SHOPIFY_STOREFRONT_ACCESS_TOKEN?: string | null;
|
|
6
|
+
STRIPE_CONNECT_ACCOUNT_ID?: string | null;
|
|
7
|
+
CHECKOUT_PROVIDER?: "shopify" | "stripe" | "none";
|
|
8
|
+
REPLO_INTERNAL_REVALIDATE_SECRET?: string;
|
|
9
|
+
/** Shared secret sent in X-Replo-Resolver-Auth for server-to-server cart calls. */
|
|
10
|
+
CART_AUTH_SECRET?: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const getEnv: () => Promise<Env>;
|
|
13
|
+
export {};
|
package/env.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { getCloudflareContext } from "@opennextjs/cloudflare";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
const envSchema = z.object({
|
|
4
|
+
CANOPY_API_HOST: z.string().min(1),
|
|
5
|
+
PROJECT_ID: z.string().uuid(),
|
|
6
|
+
SHOPIFY_URL: z.string().optional(),
|
|
7
|
+
SHOPIFY_STOREFRONT_ACCESS_TOKEN: z.string().nullable().optional(),
|
|
8
|
+
STRIPE_CONNECT_ACCOUNT_ID: z.string().nullable().optional(),
|
|
9
|
+
CHECKOUT_PROVIDER: z.enum(["shopify", "stripe", "none"]).optional(),
|
|
10
|
+
REPLO_INTERNAL_REVALIDATE_SECRET: z.string().optional(),
|
|
11
|
+
CART_AUTH_SECRET: z.string().optional()
|
|
12
|
+
});
|
|
13
|
+
const getEnv = async () => {
|
|
14
|
+
const { env } = await getCloudflareContext({ async: true });
|
|
15
|
+
return envSchema.parse(env);
|
|
16
|
+
};
|
|
17
|
+
export {
|
|
18
|
+
getEnv
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=env.js.map
|