@replohq/sandbox-runtime 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.
Files changed (139) hide show
  1. package/ClientErrorBoundary.d.ts +10 -0
  2. package/ClientErrorBoundary.js +61 -0
  3. package/ClientErrorBoundary.js.map +7 -0
  4. package/DocumentReadyBeacon.d.ts +1 -0
  5. package/DocumentReadyBeacon.js +9 -0
  6. package/DocumentReadyBeacon.js.map +7 -0
  7. package/LICENSE +11 -0
  8. package/LinkInterceptor.d.ts +1 -0
  9. package/LinkInterceptor.js +128 -0
  10. package/LinkInterceptor.js.map +7 -0
  11. package/NextErrorReporter.d.ts +1 -0
  12. package/NextErrorReporter.js +92 -0
  13. package/NextErrorReporter.js.map +7 -0
  14. package/_vendor/replo-utils/lib/crypto.d.ts +30 -0
  15. package/_vendor/replo-utils/lib/errors.d.ts +83 -0
  16. package/_vendor/replo-utils/lib/fonts.d.ts +49 -0
  17. package/_vendor/replo-utils/lib/fonts.mjs +221 -0
  18. package/_vendor/replo-utils/lib/geometry.d.ts +18 -0
  19. package/_vendor/replo-utils/lib/geometry.mjs +9 -0
  20. package/_vendor/replo-utils/lib/json.d.ts +6 -0
  21. package/_vendor/replo-utils/lib/log.d.ts +11 -0
  22. package/_vendor/replo-utils/lib/misc.d.ts +145 -0
  23. package/_vendor/replo-utils/lib/misc.mjs +2 -0
  24. package/_vendor/replo-utils/lib/object.d.ts +31 -0
  25. package/_vendor/replo-utils/lib/parse.d.ts +15 -0
  26. package/_vendor/replo-utils/lib/posthogReplay.d.ts +43 -0
  27. package/_vendor/replo-utils/lib/posthogReplay.mjs +121 -0
  28. package/_vendor/replo-utils/react/use-iframe-rpc-channel.d.ts +14 -0
  29. package/_vendor/replo-utils/react/use-iframe-rpc-channel.mjs +14 -0
  30. package/_vendor/schemas/designLibrary.d.ts +361 -0
  31. package/_vendor/schemas/designLibrary.mjs +126 -0
  32. package/_vendor/schemas/errors.d.ts +459 -0
  33. package/_vendor/schemas/generated/errors.d.ts +61 -0
  34. package/_vendor/schemas/generated/pageAnnotations.d.ts +48 -0
  35. package/_vendor/schemas/generated/pageAnnotations.mjs +1 -0
  36. package/_vendor/schemas/generated/selectMode.d.ts +119 -0
  37. package/_vendor/schemas/generated/selectMode.mjs +1 -0
  38. package/_vendor/schemas/generated/selectModeIframeRpc.d.ts +100 -0
  39. package/_vendor/schemas/generated/selectModeIframeRpc.mjs +1 -0
  40. package/_vendor/schemas/iframeRpcChannel.d.ts +82 -0
  41. package/_vendor/schemas/iframeRpcChannel.mjs +520 -0
  42. package/_vendor/schemas/pageAnnotations.d.ts +134 -0
  43. package/_vendor/schemas/pageAnnotations.mjs +61 -0
  44. package/_vendor/schemas/savedStyles.d.ts +140 -0
  45. package/_vendor/schemas/selectMode.d.ts +522 -0
  46. package/_vendor/schemas/selectMode.mjs +3 -0
  47. package/_vendor/schemas/selectModeIframeRpc.d.ts +900 -0
  48. package/_vendor/schemas/selectModeIframeRpc.mjs +223 -0
  49. package/annotations/AnnotationLayerMount.d.ts +1 -0
  50. package/annotations/AnnotationLayerMount.js +13 -0
  51. package/annotations/AnnotationLayerMount.js.map +7 -0
  52. package/annotations/annotationController.d.ts +1 -0
  53. package/annotations/annotationController.js +384 -0
  54. package/annotations/annotationController.js.map +7 -0
  55. package/annotations/bridgeGate.d.ts +7 -0
  56. package/annotations/bridgeGate.js +22 -0
  57. package/annotations/bridgeGate.js.map +7 -0
  58. package/chunk-3UFG7XTQ.mjs +205 -0
  59. package/chunk-FNTGY7I5.mjs +68 -0
  60. package/chunk-N5EI2MOZ.mjs +1535 -0
  61. package/design-library-preview/DesignLibraryPreview.d.ts +1 -0
  62. package/design-library-preview/DesignLibraryPreview.js +93 -0
  63. package/design-library-preview/DesignLibraryPreview.js.map +7 -0
  64. package/package.json +41 -0
  65. package/posthog-relay.d.ts +11 -0
  66. package/posthog-relay.js +72 -0
  67. package/posthog-relay.js.map +7 -0
  68. package/sandbox-runtime.d.ts +1 -0
  69. package/sandbox-runtime.js +29 -0
  70. package/sandbox-runtime.js.map +7 -0
  71. package/select-mode/EditorSelection.d.ts +24 -0
  72. package/select-mode/EditorSelection.js +95 -0
  73. package/select-mode/EditorSelection.js.map +7 -0
  74. package/select-mode/annotationFrames.d.ts +33 -0
  75. package/select-mode/annotationFrames.js +119 -0
  76. package/select-mode/annotationFrames.js.map +7 -0
  77. package/select-mode/descriptor/elementDescriptor.d.ts +26 -0
  78. package/select-mode/descriptor/elementDescriptor.js +201 -0
  79. package/select-mode/descriptor/elementDescriptor.js.map +7 -0
  80. package/select-mode/descriptor/styleExtraction.d.ts +3 -0
  81. package/select-mode/descriptor/styleExtraction.js +271 -0
  82. package/select-mode/descriptor/styleExtraction.js.map +7 -0
  83. package/select-mode/displayModeStore.d.ts +10 -0
  84. package/select-mode/displayModeStore.js +47 -0
  85. package/select-mode/displayModeStore.js.map +7 -0
  86. package/select-mode/fast-refresh-relay.d.ts +3 -0
  87. package/select-mode/fast-refresh-relay.js +33 -0
  88. package/select-mode/fast-refresh-relay.js.map +7 -0
  89. package/select-mode/fiber.d.ts +49 -0
  90. package/select-mode/fiber.js +306 -0
  91. package/select-mode/fiber.js.map +7 -0
  92. package/select-mode/hooks/useCrosshairCursor.d.ts +12 -0
  93. package/select-mode/hooks/useCrosshairCursor.js +20 -0
  94. package/select-mode/hooks/useCrosshairCursor.js.map +7 -0
  95. package/select-mode/hooks/useEditModeStateMachine.d.ts +16 -0
  96. package/select-mode/hooks/useEditModeStateMachine.js +235 -0
  97. package/select-mode/hooks/useEditModeStateMachine.js.map +7 -0
  98. package/select-mode/hooks/useOptimisticOverrides.d.ts +17 -0
  99. package/select-mode/hooks/useOptimisticOverrides.js +283 -0
  100. package/select-mode/hooks/useOptimisticOverrides.js.map +7 -0
  101. package/select-mode/hooks/useParentMessaging.d.ts +36 -0
  102. package/select-mode/hooks/useParentMessaging.js +74 -0
  103. package/select-mode/hooks/useParentMessaging.js.map +7 -0
  104. package/select-mode/hooks/useSelectModeController.d.ts +8 -0
  105. package/select-mode/hooks/useSelectModeController.js +46 -0
  106. package/select-mode/hooks/useSelectModeController.js.map +7 -0
  107. package/select-mode/hooks/useSelectionHover.d.ts +22 -0
  108. package/select-mode/hooks/useSelectionHover.js +110 -0
  109. package/select-mode/hooks/useSelectionHover.js.map +7 -0
  110. package/select-mode/hooks/useSelectionInteractions.d.ts +37 -0
  111. package/select-mode/hooks/useSelectionInteractions.js +353 -0
  112. package/select-mode/hooks/useSelectionInteractions.js.map +7 -0
  113. package/select-mode/hooks/useSelectionScrollSync.d.ts +28 -0
  114. package/select-mode/hooks/useSelectionScrollSync.js +70 -0
  115. package/select-mode/hooks/useSelectionScrollSync.js.map +7 -0
  116. package/select-mode/hooks/useSiblingResolution.d.ts +6 -0
  117. package/select-mode/hooks/useSiblingResolution.js +59 -0
  118. package/select-mode/hooks/useSiblingResolution.js.map +7 -0
  119. package/select-mode/iframeRpcChannel.d.ts +356 -0
  120. package/select-mode/iframeRpcChannel.js +92 -0
  121. package/select-mode/iframeRpcChannel.js.map +7 -0
  122. package/select-mode/inlineTextMarks.d.ts +6 -0
  123. package/select-mode/inlineTextMarks.js +25 -0
  124. package/select-mode/inlineTextMarks.js.map +7 -0
  125. package/select-mode/interactions/selectionGeometry.d.ts +105 -0
  126. package/select-mode/interactions/selectionGeometry.js +192 -0
  127. package/select-mode/interactions/selectionGeometry.js.map +7 -0
  128. package/select-mode/selectModeSession.d.ts +21 -0
  129. package/select-mode/selectModeSession.js +7 -0
  130. package/select-mode/selectModeSession.js.map +7 -0
  131. package/select-mode/selectionFrame.d.ts +81 -0
  132. package/select-mode/selectionFrame.js +132 -0
  133. package/select-mode/selectionFrame.js.map +7 -0
  134. package/select-mode/symbolicate.d.ts +2 -0
  135. package/select-mode/symbolicate.js +200 -0
  136. package/select-mode/symbolicate.js.map +7 -0
  137. package/select-mode/tiptapInlineEditor.d.ts +23 -0
  138. package/select-mode/tiptapInlineEditor.js +120 -0
  139. package/select-mode/tiptapInlineEditor.js.map +7 -0
@@ -0,0 +1,221 @@
1
+ import { Symbol_default, isArray_default, isObjectLike_default, baseGetTag_default } from '../../../chunk-FNTGY7I5.mjs';
2
+
3
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_arrayMap.js
4
+ function arrayMap(array, iteratee) {
5
+ var index = -1, length = array == null ? 0 : array.length, result = Array(length);
6
+ while (++index < length) {
7
+ result[index] = iteratee(array[index], index, array);
8
+ }
9
+ return result;
10
+ }
11
+ var arrayMap_default = arrayMap;
12
+
13
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isSymbol.js
14
+ var symbolTag = "[object Symbol]";
15
+ function isSymbol(value) {
16
+ return typeof value == "symbol" || isObjectLike_default(value) && baseGetTag_default(value) == symbolTag;
17
+ }
18
+ var isSymbol_default = isSymbol;
19
+ var symbolProto = Symbol_default ? Symbol_default.prototype : void 0;
20
+ var symbolToString = symbolProto ? symbolProto.toString : void 0;
21
+ function baseToString(value) {
22
+ if (typeof value == "string") {
23
+ return value;
24
+ }
25
+ if (isArray_default(value)) {
26
+ return arrayMap_default(value, baseToString) + "";
27
+ }
28
+ if (isSymbol_default(value)) {
29
+ return symbolToString ? symbolToString.call(value) : "";
30
+ }
31
+ var result = value + "";
32
+ return result == "0" && 1 / value == -Infinity ? "-0" : result;
33
+ }
34
+ var baseToString_default = baseToString;
35
+
36
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/toString.js
37
+ function toString(value) {
38
+ return value == null ? "" : baseToString_default(value);
39
+ }
40
+ var toString_default = toString;
41
+
42
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseSlice.js
43
+ function baseSlice(array, start, end) {
44
+ var index = -1, length = array.length;
45
+ if (start < 0) {
46
+ start = -start > length ? 0 : length + start;
47
+ }
48
+ end = end > length ? length : end;
49
+ if (end < 0) {
50
+ end += length;
51
+ }
52
+ length = start > end ? 0 : end - start >>> 0;
53
+ start >>>= 0;
54
+ var result = Array(length);
55
+ while (++index < length) {
56
+ result[index] = array[index + start];
57
+ }
58
+ return result;
59
+ }
60
+ var baseSlice_default = baseSlice;
61
+
62
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_castSlice.js
63
+ function castSlice(array, start, end) {
64
+ var length = array.length;
65
+ end = end === void 0 ? length : end;
66
+ return !start && end >= length ? array : baseSlice_default(array, start, end);
67
+ }
68
+ var castSlice_default = castSlice;
69
+
70
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_hasUnicode.js
71
+ var rsAstralRange = "\\ud800-\\udfff";
72
+ var rsComboMarksRange = "\\u0300-\\u036f";
73
+ var reComboHalfMarksRange = "\\ufe20-\\ufe2f";
74
+ var rsComboSymbolsRange = "\\u20d0-\\u20ff";
75
+ var rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange;
76
+ var rsVarRange = "\\ufe0e\\ufe0f";
77
+ var rsZWJ = "\\u200d";
78
+ var reHasUnicode = RegExp("[" + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + "]");
79
+ function hasUnicode(string) {
80
+ return reHasUnicode.test(string);
81
+ }
82
+ var hasUnicode_default = hasUnicode;
83
+
84
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_asciiToArray.js
85
+ function asciiToArray(string) {
86
+ return string.split("");
87
+ }
88
+ var asciiToArray_default = asciiToArray;
89
+
90
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_unicodeToArray.js
91
+ var rsAstralRange2 = "\\ud800-\\udfff";
92
+ var rsComboMarksRange2 = "\\u0300-\\u036f";
93
+ var reComboHalfMarksRange2 = "\\ufe20-\\ufe2f";
94
+ var rsComboSymbolsRange2 = "\\u20d0-\\u20ff";
95
+ var rsComboRange2 = rsComboMarksRange2 + reComboHalfMarksRange2 + rsComboSymbolsRange2;
96
+ var rsVarRange2 = "\\ufe0e\\ufe0f";
97
+ var rsAstral = "[" + rsAstralRange2 + "]";
98
+ var rsCombo = "[" + rsComboRange2 + "]";
99
+ var rsFitz = "\\ud83c[\\udffb-\\udfff]";
100
+ var rsModifier = "(?:" + rsCombo + "|" + rsFitz + ")";
101
+ var rsNonAstral = "[^" + rsAstralRange2 + "]";
102
+ var rsRegional = "(?:\\ud83c[\\udde6-\\uddff]){2}";
103
+ var rsSurrPair = "[\\ud800-\\udbff][\\udc00-\\udfff]";
104
+ var rsZWJ2 = "\\u200d";
105
+ var reOptMod = rsModifier + "?";
106
+ var rsOptVar = "[" + rsVarRange2 + "]?";
107
+ var rsOptJoin = "(?:" + rsZWJ2 + "(?:" + [rsNonAstral, rsRegional, rsSurrPair].join("|") + ")" + rsOptVar + reOptMod + ")*";
108
+ var rsSeq = rsOptVar + reOptMod + rsOptJoin;
109
+ var rsSymbol = "(?:" + [rsNonAstral + rsCombo + "?", rsCombo, rsRegional, rsSurrPair, rsAstral].join("|") + ")";
110
+ var reUnicode = RegExp(rsFitz + "(?=" + rsFitz + ")|" + rsSymbol + rsSeq, "g");
111
+ function unicodeToArray(string) {
112
+ return string.match(reUnicode) || [];
113
+ }
114
+ var unicodeToArray_default = unicodeToArray;
115
+
116
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_stringToArray.js
117
+ function stringToArray(string) {
118
+ return hasUnicode_default(string) ? unicodeToArray_default(string) : asciiToArray_default(string);
119
+ }
120
+ var stringToArray_default = stringToArray;
121
+
122
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_createCaseFirst.js
123
+ function createCaseFirst(methodName) {
124
+ return function(string) {
125
+ string = toString_default(string);
126
+ var strSymbols = hasUnicode_default(string) ? stringToArray_default(string) : void 0;
127
+ var chr = strSymbols ? strSymbols[0] : string.charAt(0);
128
+ var trailing = strSymbols ? castSlice_default(strSymbols, 1).join("") : string.slice(1);
129
+ return chr[methodName]() + trailing;
130
+ };
131
+ }
132
+ var createCaseFirst_default = createCaseFirst;
133
+
134
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/upperFirst.js
135
+ var upperFirst = createCaseFirst_default("toUpperCase");
136
+ var upperFirst_default = upperFirst;
137
+
138
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/capitalize.js
139
+ function capitalize(string) {
140
+ return upperFirst_default(toString_default(string).toLowerCase());
141
+ }
142
+ var capitalize_default = capitalize;
143
+
144
+ // ../replo-utils/lib/fonts.ts
145
+ function slugifyFontFamily(family) {
146
+ return family.replace(/([a-z])([A-Z])/g, "$1-$2").split(/[\s_-]+/u).map((word) => word.toLowerCase()).join("-");
147
+ }
148
+ function fontNameToCssVariable(fontName) {
149
+ return `--font-${slugifyFontFamily(fontName)}`;
150
+ }
151
+ function quoteFontFamily(family) {
152
+ return /\s/u.test(family) ? `'${family}'` : family;
153
+ }
154
+ function fontNameToVariableName(fontName) {
155
+ const words = fontName.replace(/([a-z])([A-Z])/g, "$1 $2").split(/[\s_-]+/u);
156
+ return words.map((word, index) => {
157
+ return index === 0 ? word.toLowerCase() : capitalize_default(word);
158
+ }).join("");
159
+ }
160
+ function buildGoogleFontsCssUrl(family, weights) {
161
+ const requested = weights && weights.length > 0 ? Array.from(new Set(weights)) : [400];
162
+ const sortedWeights = requested.sort(
163
+ (leftWeight, rightWeight) => leftWeight - rightWeight
164
+ );
165
+ const familyParam = family.trim().replace(/\s+/gu, "+");
166
+ return `https://fonts.googleapis.com/css2?family=${familyParam}:wght@${sortedWeights.join(
167
+ ";"
168
+ )}&display=swap`;
169
+ }
170
+ var FONT_MIME_BY_EXTENSION = {
171
+ woff2: "font/woff2",
172
+ woff: "font/woff",
173
+ ttf: "font/ttf",
174
+ otf: "font/otf"
175
+ };
176
+ function describeFontFile(fileName) {
177
+ const lastDot = fileName.lastIndexOf(".");
178
+ const base = lastDot > 0 ? fileName.slice(0, lastDot) : fileName;
179
+ const extension = lastDot > 0 ? fileName.slice(lastDot + 1).toLowerCase() : "";
180
+ const family = base.replace(/[_-]+/gu, " ").replace(/\s+/gu, " ").trim() || "Custom font";
181
+ return {
182
+ family,
183
+ mimeType: FONT_MIME_BY_EXTENSION[extension] ?? "font/woff2"
184
+ };
185
+ }
186
+ function fontFormatFromExtension(extension) {
187
+ const normalized = extension.toLowerCase().replace(/^\./u, "");
188
+ if (normalized === "woff2") return "woff2";
189
+ if (normalized === "woff") return "woff";
190
+ if (normalized === "otf") return "opentype";
191
+ if (normalized === "ttf") return "truetype";
192
+ return "woff2";
193
+ }
194
+ function fontFormatFromMimeType(mimeType) {
195
+ const normalized = mimeType.toLowerCase();
196
+ if (normalized.includes("woff2")) return "woff2";
197
+ if (normalized.includes("woff")) return "woff";
198
+ if (normalized.includes("otf") || normalized.includes("opentype")) {
199
+ return "opentype";
200
+ }
201
+ if (normalized.includes("ttf") || normalized.includes("truetype")) {
202
+ return "truetype";
203
+ }
204
+ return "woff2";
205
+ }
206
+ function escapeCssString(value) {
207
+ return value.replace(/\\/gu, "\\\\").replace(/"/gu, '\\"');
208
+ }
209
+ function buildFontFaceCss({
210
+ family,
211
+ faceUrl,
212
+ format,
213
+ weight = 400
214
+ }) {
215
+ return `@font-face{font-family:"${escapeCssString(family)}";font-weight:${weight};font-style:normal;src:url("${escapeCssString(faceUrl)}") format("${escapeCssString(format)}");font-display:swap;}`;
216
+ }
217
+ var escapeFontFamilyName = (fontFamily) => {
218
+ return fontFamily.replace(/"/g, '\\"').replace(/'/g, "\\'");
219
+ };
220
+
221
+ export { buildFontFaceCss, buildGoogleFontsCssUrl, describeFontFile, escapeFontFamilyName, fontFormatFromExtension, fontFormatFromMimeType, fontNameToCssVariable, fontNameToVariableName, quoteFontFamily, slugifyFontFamily };
@@ -0,0 +1,18 @@
1
+ export type GeometryRect = {
2
+ left: number;
3
+ right: number;
4
+ top: number;
5
+ bottom: number;
6
+ };
7
+ /**
8
+ * Whether two axis-aligned rects overlap. `tolerance` expands the test
9
+ * rect on every side, so rects that fall a few pixels short of touching
10
+ * (sub-pixel rendering, borders) still count as intersecting.
11
+ */
12
+ export declare function isIntersecting(targetRect: GeometryRect, destinationRect: GeometryRect, { tolerance }?: {
13
+ tolerance?: number;
14
+ }): boolean;
15
+ /**
16
+ * Whether `targetRect` wholly contains `testRect`.
17
+ */
18
+ export declare function isRectEnclosing(targetRect: GeometryRect, testRect: GeometryRect): boolean;
@@ -0,0 +1,9 @@
1
+ // ../replo-utils/lib/geometry.ts
2
+ function isIntersecting(targetRect, destinationRect, { tolerance = 0 } = {}) {
3
+ return targetRect.left <= destinationRect.right + tolerance && targetRect.right >= destinationRect.left - tolerance && targetRect.top <= destinationRect.bottom + tolerance && targetRect.bottom >= destinationRect.top - tolerance;
4
+ }
5
+ function isRectEnclosing(targetRect, testRect) {
6
+ return targetRect.left <= testRect.left && targetRect.right >= testRect.right && targetRect.top <= testRect.top && targetRect.bottom >= testRect.bottom;
7
+ }
8
+
9
+ export { isIntersecting, isRectEnclosing };
@@ -0,0 +1,6 @@
1
+ export declare function parseJsonOrNull(json: string): unknown | null;
2
+ export declare function omitJsonObjectFieldsOrNull({ json, fields, }: {
3
+ json: string;
4
+ fields: string[];
5
+ }): string | null;
6
+ export declare function jsonStringifyOrNull(value: unknown): string | null;
@@ -0,0 +1,11 @@
1
+ export type Logger = {
2
+ info: Console["log"];
3
+ debug: Console["debug"];
4
+ error: Console["error"];
5
+ };
6
+ export declare const defaultLogger: Logger;
7
+ /**
8
+ * Silent logger, mostly useful for testing cases where you may not want
9
+ * a service logging out errors that you're expecting.
10
+ */
11
+ export declare const noOpLogger: Logger;
@@ -0,0 +1,145 @@
1
+ import isFunction from "lodash-es/isFunction";
2
+ import isNumber from "lodash-es/isNumber";
3
+ import isString from "lodash-es/isString";
4
+ export { isFunction, isNumber, isString };
5
+ /**
6
+ * Checks if a value is neither `null` nor `undefined`.
7
+ */
8
+ export declare function isNotNullish<ValueType>(value: ValueType): value is Exclude<ValueType, null | undefined>;
9
+ /**
10
+ * Checks if a value is either `null` or `undefined`.
11
+ */
12
+ export declare function isNullish(value: unknown): value is null | undefined;
13
+ export declare function getFromRecordOrNull<RecordKey extends PropertyKey, RecordValue>(record: Record<RecordKey, RecordValue> | null | undefined, key: RecordKey | undefined | null): NonNullable<Record<RecordKey, RecordValue>[RecordKey]> | null;
14
+ export declare function isPrimitive(value: unknown): value is string | number | boolean;
15
+ type StructureRecord<UnionType extends {
16
+ type: string;
17
+ }, ResultType> = {
18
+ [MemberType in UnionType as MemberType["type"]]: ResultType | ((value: MemberType) => ResultType);
19
+ };
20
+ type StructureRecordBareString<UnionType extends string, ResultType> = {
21
+ [MemberType in UnionType]: ResultType | ((value: MemberType) => ResultType);
22
+ };
23
+ type StructureRecordGeneric<UnionType extends Record<KeyType, string>, ResultType, KeyType extends keyof UnionType> = {
24
+ [MemberType in UnionType as MemberType[KeyType]]: ResultType | ((value: MemberType) => ResultType);
25
+ };
26
+ /**
27
+ * @returns A function which can be used to create an exhaustive switch over all
28
+ * types of a discriminated union, based on a given key, or over all members of
29
+ * a bare string union.
30
+ *
31
+ * When no key is provided, it defaults to using "type" as the discriminant.
32
+ * When the value is a bare string union, the value is its own discriminant.
33
+ *
34
+ * Examples:
35
+ *
36
+ * With default "type" discriminant:
37
+ * ```
38
+ * type OneOrTwo = { type: "one", numberValue: number } |
39
+ * { type: "two", stringValue: string }
40
+ *
41
+ * let oneOrTwo = ...
42
+ * let result = exhaustiveSwitch(oneOrTwo)({
43
+ * one: (op) => `${op.numberValue + 1}`, // Typescript knows numberValue is a number
44
+ * two: (op) => op.stringValue + "hello", // Typescript knows stringValue is a string
45
+ * }) // type of result is inferred to be string
46
+ * ```
47
+ *
48
+ * With custom discriminant key:
49
+ * ```
50
+ * type OneOrTwo = { variant: "one", numberValue: number } |
51
+ * { variant: "two", stringValue: string }
52
+ *
53
+ * let oneOrTwo = ...
54
+ * let result = exhaustiveSwitch(oneOrTwo, "variant")({
55
+ * one: (op) => `${op.numberValue + 1}`, // Typescript knows numberValue is a number
56
+ * two: (op) => op.stringValue + "hello", // Typescript knows stringValue is a string
57
+ * }) // type of result is inferred to be string
58
+ * ```
59
+ *
60
+ * With a bare string union:
61
+ * ```
62
+ * type OneOrTwo = "one" | "two"
63
+ *
64
+ * let oneOrTwo = ...
65
+ * let result = exhaustiveSwitch(oneOrTwo)({
66
+ * one: 1, // cases can be plain values...
67
+ * two: () => 1 + 1, // ...or functions, evaluated lazily
68
+ * }) // type of result is inferred to be number
69
+ * ```
70
+ *
71
+ * Typescript will error if you forget a case, or if you assume the wrong type
72
+ * for a case value. The switch also returns the value you return from the
73
+ * function mapping, so it works well for "extension" methods where you want to
74
+ * map over all discriminated union cases and do a different thing for each.
75
+ *
76
+ * Works well for many of our types, like ComponentActionType, Action, etc
77
+ */
78
+ export declare function exhaustiveSwitch<UnionType extends string>(value: UnionType): <ResultType>(cases: StructureRecordBareString<UnionType, ResultType>) => ResultType;
79
+ export declare function exhaustiveSwitch<UnionType extends {
80
+ type: string;
81
+ }>(value: UnionType): <ResultType>(cases: StructureRecord<UnionType, ResultType>) => ResultType;
82
+ export declare function exhaustiveSwitch<UnionType extends Record<KeyType, string>, KeyType extends keyof UnionType>(value: UnionType, key: KeyType): <ResultType>(cases: StructureRecordGeneric<UnionType, ResultType, KeyType>) => ResultType;
83
+ type EmptyObject<ValueType> = {
84
+ [KeyType in keyof ValueType]?: never;
85
+ };
86
+ type EmptyObjectOf<ValueType> = EmptyObject<ValueType> extends ValueType ? EmptyObject<ValueType> : never;
87
+ /**
88
+ * The same as `isEmpty` from lodash, but with a few additional overloads for
89
+ * stronger type-checking on empty arrays.
90
+ */
91
+ export declare function isEmpty(value: string): value is "";
92
+ export declare function isEmpty<ValueType extends any[]>(value: ValueType | null | undefined): value is (ValueType & []) | null | undefined;
93
+ export declare function isEmpty<ValueType extends ArrayLike<any>>(value: ValueType | null | undefined): value is (ValueType & {
94
+ length: 0;
95
+ }) | null | undefined;
96
+ export declare function isEmpty(value: Map<any, any> | Set<any> | ArrayLike<any> | null | undefined): boolean;
97
+ export declare function isEmpty(value: object): boolean;
98
+ export declare function isEmpty<ValueType extends object>(value: ValueType | null | undefined): value is EmptyObjectOf<ValueType> | null | undefined;
99
+ export declare function isEmpty(value?: any): boolean;
100
+ export declare function noop(): void;
101
+ export declare function preventDefault(event: {
102
+ preventDefault(): void;
103
+ }): void;
104
+ /**
105
+ * Copyright (c) 2019 Alexander Reardon
106
+ * https://github.com/alexreardon/tiny-warning/blob/master/src/index.js
107
+ */
108
+ export declare function warning(condition: unknown, message: string | (() => string), options?: {
109
+ severity: "log" | "warn" | "error";
110
+ }): void;
111
+ /**
112
+ *
113
+ * Copyright (c) 2019 Alexander Reardon
114
+ * https://github.com/alexreardon/tiny-warning/blob/master/src/index.js
115
+ */
116
+ export declare function invariant(condition: unknown, message: string | (() => string), opts?: {
117
+ stripErrorMessage: unknown;
118
+ }): asserts condition;
119
+ export declare const mergeReplacingObjects: (first: Object, second: Object) => void;
120
+ export declare const mergeReplacingArrays: (first: Object, second: Object) => void;
121
+ export declare const deepCloneAndMergeReplacingArrays: <ValueType>(source: ValueType, ...toMerge: Object[]) => ValueType;
122
+ /**
123
+ * hasOwnProperty with a type assertion. If this returns true, typescript knows that `obj`
124
+ * has a property called `prop` from that point forward
125
+ * https://fettblog.eu/typescript-hasownproperty/
126
+ */
127
+ export declare function hasOwnProperty<ObjectType extends {} | null | undefined, KeyType extends PropertyKey>(obj: ObjectType, prop: KeyType): obj is ObjectType & Record<KeyType, unknown>;
128
+ /**
129
+ * Given a string | number param, converts it to a string, unless it's nullish
130
+ * in which case it just returns it. Useful for times when you have string | number
131
+ * | nullish types, like when selecting the current value of a CSS property in a right
132
+ * bar modifier
133
+ */
134
+ export declare function coerceNumberToString(value: string | number): string;
135
+ export declare function coerceNumberToString(value: string | number | null | undefined): string | null | undefined;
136
+ export declare function coerceNumberToString(value: string | number | undefined): string | undefined;
137
+ export declare function coerceNumberToString(value: string | number | null): string | null;
138
+ /**
139
+ * Formats a file size in bytes to a human readable string with appropriate
140
+ * units. Rounds to 0 decimal places unless otherwise specified and uses
141
+ * standard binary units (KB, MB, etc).
142
+ */
143
+ export declare function formatFileSize(byteCount: number, decimalPlaces?: number): string;
144
+ export declare const sleep: (ms: number) => Promise<unknown>;
145
+ export declare function errorMessage(error: unknown): string;
@@ -0,0 +1,2 @@
1
+ export { coerceNumberToString, deepCloneAndMergeReplacingArrays, errorMessage, exhaustiveSwitch, formatFileSize, getFromRecordOrNull, hasOwnProperty, invariant, isEmpty, isFunction_default as isFunction, isNotNullish, isNullish, isNumber_default as isNumber, isPrimitive, isString_default as isString, mergeReplacingArrays, mergeReplacingObjects, noop, preventDefault, sleep, warning } from '../../../chunk-N5EI2MOZ.mjs';
2
+ import '../../../chunk-FNTGY7I5.mjs';
@@ -0,0 +1,31 @@
1
+ import { dequal as dequalLite } from "dequal/lite";
2
+ interface ForEachPrimitiveValueArgs {
3
+ target: Record<string, any> | unknown[] | null;
4
+ fn: (value: unknown, key: string, newTarget: Record<string, any>) => void;
5
+ valueConversionFunction?: (transformValue: Record<string, any> | unknown[]) => Record<string, any> | unknown[];
6
+ }
7
+ /** There's probably a bug somewhere here since it assumes target is initially an object */
8
+ export declare function forEachPrimitiveValue({ target, fn, valueConversionFunction, }: ForEachPrimitiveValueArgs): void;
9
+ export declare function shallowEqual(objA: unknown, objB: unknown): boolean;
10
+ /**
11
+ * Internally we use `dequal` for deep equality checks. It benchmarks faster
12
+ * than lodash and most other libraries.
13
+ *
14
+ * This function is an alias for `dequal`'s "lite" module. It does not check
15
+ * equality for `Map` or `Set` values. If you need to compare those, use
16
+ * `deepEqualHeavy`.
17
+ *
18
+ * @see https://github.com/lukeed/dequal#modes
19
+ */
20
+ export declare const deepEqual: typeof dequalLite;
21
+ /**
22
+ * Creates a new object with specified keys omitted.
23
+ *
24
+ * @param obj - The source object
25
+ * @param keysToOmit - Array of keys to omit from the result
26
+ * @returns A new object without the specified keys
27
+ */
28
+ export declare function omit<ObjectType extends Record<string, any>, KeyType extends keyof ObjectType>(obj: ObjectType, keysToOmit: KeyType[]): Omit<ObjectType, KeyType>;
29
+ export declare function filterUndefined<ObjectType extends Record<string, unknown>>(data: ObjectType): Partial<ObjectType>;
30
+ export declare function toNullableIfDefined<ValueType>(value: ValueType | undefined): ValueType | null | undefined;
31
+ export {};
@@ -0,0 +1,15 @@
1
+ import type { z } from "zod";
2
+ /**
3
+ * Parse a value using the zod schema, or default. This is useful when parsing build-time
4
+ * environmental variables that need to be access via the full object path, like
5
+ * `process.env.COMMIT`.
6
+ */
7
+ export declare function parseOrDefault<SchemaType extends z.ZodType<any, any>>(value: string | undefined, schema: SchemaType, defaultValue: z.infer<SchemaType>): z.infer<SchemaType>;
8
+ /**
9
+ * Parse an arbitrary value using the zod schema, returning `null` on
10
+ * failure. Use this for the common pattern of validating untrusted
11
+ * runtime data (postMessage payloads, JSON strings parsed out of DOM
12
+ * attributes, etc.) where the caller doesn't care *why* parsing failed
13
+ * — they just want the typed value or nothing.
14
+ */
15
+ export declare function parseSchemaOrNull<SchemaType extends z.ZodType<any, any>>(value: unknown, schema: SchemaType): z.infer<SchemaType> | null;
@@ -0,0 +1,43 @@
1
+ export declare const POSTHOG_REPLAY_SNAPSHOT_REQUEST = "posthog:replay:request-full-snapshot";
2
+ interface PostHogRrweb {
3
+ record: {
4
+ takeFullSnapshot?: () => void;
5
+ };
6
+ }
7
+ type PostHogReplayMessageListener = (event: {
8
+ data: unknown;
9
+ source: unknown;
10
+ }) => void;
11
+ interface PostHogReplayWindow {
12
+ readonly parent: unknown;
13
+ readonly frames: ArrayLike<{
14
+ postMessage: (message: string, targetOrigin: string) => void;
15
+ }>;
16
+ readonly __PosthogExtensions__?: {
17
+ rrweb?: PostHogRrweb;
18
+ };
19
+ addEventListener(type: "message", listener: PostHogReplayMessageListener): void;
20
+ removeEventListener(type: "message", listener: PostHogReplayMessageListener): void;
21
+ setTimeout(listener: () => void, timeout: number): number;
22
+ clearTimeout(timeoutId: number): void;
23
+ }
24
+ declare global {
25
+ interface Window {
26
+ __PosthogExtensions__?: {
27
+ rrweb?: PostHogRrweb;
28
+ };
29
+ }
30
+ }
31
+ export declare function requestChildPostHogReplaySnapshots({ targetWindow, }: {
32
+ targetWindow: PostHogReplayWindow;
33
+ }): void;
34
+ export declare function startPostHogReplaySnapshotCascade({ isRecordingStarted, targetWindow, onReady, }: {
35
+ isRecordingStarted: () => boolean;
36
+ targetWindow: PostHogReplayWindow;
37
+ onReady?: () => void;
38
+ }): () => void;
39
+ export declare function startChildPostHogReplaySnapshotRelay({ isRecordingStarted, targetWindow, }: {
40
+ isRecordingStarted: () => boolean;
41
+ targetWindow: PostHogReplayWindow;
42
+ }): () => void;
43
+ export {};
@@ -0,0 +1,121 @@
1
+ // ../replo-utils/lib/posthogReplay.ts
2
+ var POSTHOG_REPLAY_SNAPSHOT_REQUEST = "posthog:replay:request-full-snapshot";
3
+ var POSTHOG_REPLAY_READY_POLL_INTERVAL_MS = 100;
4
+ var POSTHOG_REPLAY_READY_POLL_TIMEOUT_MS = 1e4;
5
+ function requestChildPostHogReplaySnapshots({
6
+ targetWindow
7
+ }) {
8
+ for (let frameIndex = 0; frameIndex < targetWindow.frames.length; frameIndex++) {
9
+ targetWindow.frames[frameIndex]?.postMessage(
10
+ POSTHOG_REPLAY_SNAPSHOT_REQUEST,
11
+ "*"
12
+ );
13
+ }
14
+ }
15
+ function takePostHogReplayFullSnapshot({
16
+ isRecordingStarted,
17
+ targetWindow
18
+ }) {
19
+ if (!isRecordingStarted()) {
20
+ return false;
21
+ }
22
+ const takeFullSnapshot = targetWindow.__PosthogExtensions__?.rrweb?.record.takeFullSnapshot;
23
+ if (!takeFullSnapshot) {
24
+ return false;
25
+ }
26
+ try {
27
+ takeFullSnapshot();
28
+ return true;
29
+ } catch {
30
+ return false;
31
+ }
32
+ }
33
+ function startPostHogReplaySnapshotCascade({
34
+ isRecordingStarted,
35
+ targetWindow,
36
+ onReady
37
+ }) {
38
+ const replayReadyPollDeadline = Date.now() + POSTHOG_REPLAY_READY_POLL_TIMEOUT_MS;
39
+ let timeoutId;
40
+ let stopCascading;
41
+ const startCascadingWhenReady = () => {
42
+ const record = targetWindow.__PosthogExtensions__?.rrweb?.record;
43
+ const takeFullSnapshot = record?.takeFullSnapshot;
44
+ if (!record || !takeFullSnapshot || !isRecordingStarted()) {
45
+ if (Date.now() < replayReadyPollDeadline) {
46
+ timeoutId = targetWindow.setTimeout(
47
+ startCascadingWhenReady,
48
+ POSTHOG_REPLAY_READY_POLL_INTERVAL_MS
49
+ );
50
+ }
51
+ return;
52
+ }
53
+ const takeFullSnapshotAndCascade = () => {
54
+ takeFullSnapshot();
55
+ requestChildPostHogReplaySnapshots({ targetWindow });
56
+ };
57
+ record.takeFullSnapshot = takeFullSnapshotAndCascade;
58
+ stopCascading = () => {
59
+ if (record.takeFullSnapshot === takeFullSnapshotAndCascade) {
60
+ record.takeFullSnapshot = takeFullSnapshot;
61
+ }
62
+ };
63
+ onReady?.();
64
+ };
65
+ startCascadingWhenReady();
66
+ return () => {
67
+ if (timeoutId !== void 0) {
68
+ targetWindow.clearTimeout(timeoutId);
69
+ }
70
+ stopCascading?.();
71
+ };
72
+ }
73
+ function startChildPostHogReplaySnapshotRelay({
74
+ isRecordingStarted,
75
+ targetWindow
76
+ }) {
77
+ if (targetWindow.parent === targetWindow) {
78
+ return () => {
79
+ };
80
+ }
81
+ let hasPendingSnapshotRequest = false;
82
+ let isSnapshotCascadeReady = false;
83
+ let stopCascadingSnapshots = () => {
84
+ };
85
+ const startCascadingSnapshots = () => {
86
+ stopCascadingSnapshots();
87
+ isSnapshotCascadeReady = false;
88
+ stopCascadingSnapshots = startPostHogReplaySnapshotCascade({
89
+ isRecordingStarted,
90
+ targetWindow,
91
+ onReady: () => {
92
+ isSnapshotCascadeReady = true;
93
+ if (hasPendingSnapshotRequest) {
94
+ hasPendingSnapshotRequest = false;
95
+ takePostHogReplayFullSnapshot({ isRecordingStarted, targetWindow });
96
+ }
97
+ }
98
+ });
99
+ };
100
+ startCascadingSnapshots();
101
+ const onMessage = (event) => {
102
+ if (event.source !== targetWindow.parent || event.data !== POSTHOG_REPLAY_SNAPSHOT_REQUEST) {
103
+ return;
104
+ }
105
+ if (!takePostHogReplayFullSnapshot({ isRecordingStarted, targetWindow })) {
106
+ hasPendingSnapshotRequest = true;
107
+ startCascadingSnapshots();
108
+ return;
109
+ }
110
+ if (!isSnapshotCascadeReady) {
111
+ requestChildPostHogReplaySnapshots({ targetWindow });
112
+ }
113
+ };
114
+ targetWindow.addEventListener("message", onMessage);
115
+ return () => {
116
+ stopCascadingSnapshots();
117
+ targetWindow.removeEventListener("message", onMessage);
118
+ };
119
+ }
120
+
121
+ export { POSTHOG_REPLAY_SNAPSHOT_REQUEST, requestChildPostHogReplaySnapshots, startChildPostHogReplaySnapshotRelay, startPostHogReplaySnapshotCascade };
@@ -0,0 +1,14 @@
1
+ type SubscribableChannel = {
2
+ subscribe: () => () => void;
3
+ };
4
+ /**
5
+ * Subscribes an iframe RPC channel for the lifetime of the calling component.
6
+ * Returns the same channel so callers can keep a stable handle for `call`.
7
+ *
8
+ * Typed structurally so this hook can live in `replo-utils` without importing
9
+ * the channel implementation from `schemas` (which would close a workspace
10
+ * cycle: schemas → replo-utils).
11
+ */
12
+ export declare function useIframeRpcChannel<ChannelType extends SubscribableChannel>(channel: ChannelType): ChannelType;
13
+ export declare function useIframeRpcChannel<ChannelType extends SubscribableChannel>(channel: ChannelType | null): ChannelType | null;
14
+ export {};
@@ -0,0 +1,14 @@
1
+ import * as React from 'react';
2
+
3
+ // ../replo-utils/react/use-iframe-rpc-channel.ts
4
+ function useIframeRpcChannel(channel) {
5
+ React.useEffect(() => {
6
+ if (!channel) {
7
+ return;
8
+ }
9
+ return channel.subscribe();
10
+ }, [channel]);
11
+ return channel;
12
+ }
13
+
14
+ export { useIframeRpcChannel };