@buoy-gg/debug-borders 2.0.2
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/README.md +334 -0
- package/lib/commonjs/debug-borders/components/DebugBordersModal.js +234 -0
- package/lib/commonjs/debug-borders/components/DebugBordersStandaloneOverlay.js +436 -0
- package/lib/commonjs/debug-borders/index.js +51 -0
- package/lib/commonjs/debug-borders/types.js +1 -0
- package/lib/commonjs/debug-borders/utils/DebugBordersManager.js +119 -0
- package/lib/commonjs/debug-borders/utils/ViewTypeMapper.js +264 -0
- package/lib/commonjs/debug-borders/utils/colorGeneration.js +76 -0
- package/lib/commonjs/debug-borders/utils/componentInfo.js +183 -0
- package/lib/commonjs/debug-borders/utils/componentMeasurement.js +111 -0
- package/lib/commonjs/debug-borders/utils/fiberTreeTraversal.js +309 -0
- package/lib/commonjs/debug-borders/utils/labelPositioning.js +202 -0
- package/lib/commonjs/index.js +34 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/preset.js +178 -0
- package/lib/module/debug-borders/components/DebugBordersModal.js +229 -0
- package/lib/module/debug-borders/components/DebugBordersStandaloneOverlay.js +432 -0
- package/lib/module/debug-borders/index.js +15 -0
- package/lib/module/debug-borders/types.js +1 -0
- package/lib/module/debug-borders/utils/DebugBordersManager.js +119 -0
- package/lib/module/debug-borders/utils/ViewTypeMapper.js +255 -0
- package/lib/module/debug-borders/utils/colorGeneration.js +76 -0
- package/lib/module/debug-borders/utils/componentInfo.js +183 -0
- package/lib/module/debug-borders/utils/componentMeasurement.js +111 -0
- package/lib/module/debug-borders/utils/fiberTreeTraversal.js +309 -0
- package/lib/module/debug-borders/utils/labelPositioning.js +202 -0
- package/lib/module/index.js +7 -0
- package/lib/module/preset.js +166 -0
- package/lib/typescript/debug-borders/components/DebugBordersModal.d.ts +11 -0
- package/lib/typescript/debug-borders/components/DebugBordersModal.d.ts.map +1 -0
- package/lib/typescript/debug-borders/components/DebugBordersStandaloneOverlay.d.ts +15 -0
- package/lib/typescript/debug-borders/components/DebugBordersStandaloneOverlay.d.ts.map +1 -0
- package/lib/typescript/debug-borders/index.d.ts +8 -0
- package/lib/typescript/debug-borders/index.d.ts.map +1 -0
- package/lib/typescript/debug-borders/types.d.ts +45 -0
- package/lib/typescript/debug-borders/types.d.ts.map +1 -0
- package/lib/typescript/debug-borders/utils/ViewTypeMapper.d.ts +66 -0
- package/lib/typescript/debug-borders/utils/ViewTypeMapper.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +3 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/preset.d.ts +108 -0
- package/lib/typescript/preset.d.ts.map +1 -0
- package/package.json +72 -0
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Standalone Debug Borders Overlay
|
|
5
|
+
*
|
|
6
|
+
* This component renders debug borders independently of the Provider.
|
|
7
|
+
* It should be rendered at the root level of the app to ensure it appears on top.
|
|
8
|
+
*
|
|
9
|
+
* Supports two display modes:
|
|
10
|
+
* - "borders" - Shows colored borders only
|
|
11
|
+
* - "labels" - Shows colored borders with component labels
|
|
12
|
+
*
|
|
13
|
+
* Automatically hides borders when DevTools modals are open to avoid visual clutter.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import React, { useEffect, useState, useCallback } from "react";
|
|
17
|
+
import { View, Text, StyleSheet, TouchableOpacity } from "react-native";
|
|
18
|
+
|
|
19
|
+
// Import JsModal from shared
|
|
20
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
21
|
+
let JsModal = null;
|
|
22
|
+
let DataViewer = null;
|
|
23
|
+
try {
|
|
24
|
+
const sharedModule = require("@buoy-gg/shared-ui");
|
|
25
|
+
JsModal = sharedModule.JsModal;
|
|
26
|
+
} catch (e) {
|
|
27
|
+
// JsModal not available
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
const dataViewerModule = require("@buoy-gg/shared-ui/dataViewer");
|
|
31
|
+
DataViewer = dataViewerModule.DataViewer;
|
|
32
|
+
} catch (e) {
|
|
33
|
+
// DataViewer not available
|
|
34
|
+
}
|
|
35
|
+
const DebugBordersManager = require("../utils/DebugBordersManager");
|
|
36
|
+
const {
|
|
37
|
+
getAllHostComponentInstances
|
|
38
|
+
} = require("../utils/fiberTreeTraversal");
|
|
39
|
+
const {
|
|
40
|
+
measureInstances
|
|
41
|
+
} = require("../utils/componentMeasurement");
|
|
42
|
+
const {
|
|
43
|
+
getColorForDepth
|
|
44
|
+
} = require("../utils/colorGeneration");
|
|
45
|
+
const {
|
|
46
|
+
getShortLabel
|
|
47
|
+
} = require("../utils/componentInfo");
|
|
48
|
+
const {
|
|
49
|
+
resolveOverlappingLabels
|
|
50
|
+
} = require("../utils/labelPositioning");
|
|
51
|
+
|
|
52
|
+
// Import DevToolsVisibility context to detect when DevTools are open
|
|
53
|
+
let useDevToolsVisibility = null;
|
|
54
|
+
try {
|
|
55
|
+
// Optional import - will gracefully fail if not available
|
|
56
|
+
const coreModule = require("@buoy-gg/core");
|
|
57
|
+
useDevToolsVisibility = coreModule.useDevToolsVisibility;
|
|
58
|
+
} catch (e) {
|
|
59
|
+
// DevToolsVisibility not available, that's ok - borders will always work
|
|
60
|
+
}
|
|
61
|
+
// Row component for displaying info
|
|
62
|
+
function InfoRow({
|
|
63
|
+
label,
|
|
64
|
+
value,
|
|
65
|
+
color
|
|
66
|
+
}) {
|
|
67
|
+
if (value === null || value === undefined) return null;
|
|
68
|
+
let displayValue;
|
|
69
|
+
if (typeof value === "object") {
|
|
70
|
+
try {
|
|
71
|
+
displayValue = JSON.stringify(value, null, 2);
|
|
72
|
+
} catch {
|
|
73
|
+
displayValue = String(value);
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
displayValue = String(value);
|
|
77
|
+
}
|
|
78
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
79
|
+
style: modalStyles.row,
|
|
80
|
+
children: [/*#__PURE__*/_jsx(Text, {
|
|
81
|
+
style: modalStyles.label,
|
|
82
|
+
children: label
|
|
83
|
+
}), /*#__PURE__*/_jsx(Text, {
|
|
84
|
+
style: [modalStyles.value, color ? {
|
|
85
|
+
color
|
|
86
|
+
} : null],
|
|
87
|
+
children: displayValue
|
|
88
|
+
})]
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Simple header with just title (no hints)
|
|
93
|
+
function SimpleHeader({
|
|
94
|
+
title
|
|
95
|
+
}) {
|
|
96
|
+
return /*#__PURE__*/_jsx(View, {
|
|
97
|
+
style: headerStyles.container,
|
|
98
|
+
children: /*#__PURE__*/_jsx(Text, {
|
|
99
|
+
style: headerStyles.title,
|
|
100
|
+
numberOfLines: 1,
|
|
101
|
+
children: title
|
|
102
|
+
})
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Component Info Modal Content
|
|
107
|
+
function ComponentInfoContent({
|
|
108
|
+
info,
|
|
109
|
+
rect
|
|
110
|
+
}) {
|
|
111
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
112
|
+
style: modalStyles.content,
|
|
113
|
+
children: [/*#__PURE__*/_jsx(Text, {
|
|
114
|
+
style: modalStyles.sectionTitle,
|
|
115
|
+
children: "Identifiers"
|
|
116
|
+
}), /*#__PURE__*/_jsx(InfoRow, {
|
|
117
|
+
label: "testID",
|
|
118
|
+
value: info.testID,
|
|
119
|
+
color: "#10b981"
|
|
120
|
+
}), /*#__PURE__*/_jsx(InfoRow, {
|
|
121
|
+
label: "accessibilityLabel",
|
|
122
|
+
value: info.accessibilityLabel,
|
|
123
|
+
color: "#ec4899"
|
|
124
|
+
}), /*#__PURE__*/_jsx(InfoRow, {
|
|
125
|
+
label: "nativeID",
|
|
126
|
+
value: info.nativeID,
|
|
127
|
+
color: "#f59e0b"
|
|
128
|
+
}), /*#__PURE__*/_jsx(InfoRow, {
|
|
129
|
+
label: "key",
|
|
130
|
+
value: info.fiberKey
|
|
131
|
+
}), /*#__PURE__*/_jsx(Text, {
|
|
132
|
+
style: modalStyles.sectionTitle,
|
|
133
|
+
children: "Component"
|
|
134
|
+
}), /*#__PURE__*/_jsx(InfoRow, {
|
|
135
|
+
label: "Component Name",
|
|
136
|
+
value: info.componentName,
|
|
137
|
+
color: "#a855f7"
|
|
138
|
+
}), /*#__PURE__*/_jsx(InfoRow, {
|
|
139
|
+
label: "Parent Component",
|
|
140
|
+
value: info.parentComponentName
|
|
141
|
+
}), /*#__PURE__*/_jsx(InfoRow, {
|
|
142
|
+
label: "Display Name",
|
|
143
|
+
value: info.displayName
|
|
144
|
+
}), /*#__PURE__*/_jsx(InfoRow, {
|
|
145
|
+
label: "Native View Type",
|
|
146
|
+
value: info.viewType
|
|
147
|
+
}), /*#__PURE__*/_jsx(InfoRow, {
|
|
148
|
+
label: "Fiber Tag",
|
|
149
|
+
value: info.fiberTag
|
|
150
|
+
}), /*#__PURE__*/_jsx(Text, {
|
|
151
|
+
style: modalStyles.sectionTitle,
|
|
152
|
+
children: "Position & Size"
|
|
153
|
+
}), /*#__PURE__*/_jsx(InfoRow, {
|
|
154
|
+
label: "X",
|
|
155
|
+
value: Math.round(rect.x)
|
|
156
|
+
}), /*#__PURE__*/_jsx(InfoRow, {
|
|
157
|
+
label: "Y",
|
|
158
|
+
value: Math.round(rect.y)
|
|
159
|
+
}), /*#__PURE__*/_jsx(InfoRow, {
|
|
160
|
+
label: "Width",
|
|
161
|
+
value: Math.round(rect.width)
|
|
162
|
+
}), /*#__PURE__*/_jsx(InfoRow, {
|
|
163
|
+
label: "Height",
|
|
164
|
+
value: Math.round(rect.height)
|
|
165
|
+
}), /*#__PURE__*/_jsx(InfoRow, {
|
|
166
|
+
label: "Depth",
|
|
167
|
+
value: rect.depth
|
|
168
|
+
}), (info.accessibilityRole || info.accessibilityHint || info.accessibilityState) && /*#__PURE__*/_jsxs(_Fragment, {
|
|
169
|
+
children: [/*#__PURE__*/_jsx(Text, {
|
|
170
|
+
style: modalStyles.sectionTitle,
|
|
171
|
+
children: "Accessibility"
|
|
172
|
+
}), /*#__PURE__*/_jsx(InfoRow, {
|
|
173
|
+
label: "Role",
|
|
174
|
+
value: info.accessibilityRole
|
|
175
|
+
}), /*#__PURE__*/_jsx(InfoRow, {
|
|
176
|
+
label: "Hint",
|
|
177
|
+
value: info.accessibilityHint
|
|
178
|
+
}), info.accessibilityState && DataViewer ? /*#__PURE__*/_jsx(DataViewer, {
|
|
179
|
+
title: "State",
|
|
180
|
+
data: info.accessibilityState,
|
|
181
|
+
showTypeFilter: false,
|
|
182
|
+
initialExpanded: true
|
|
183
|
+
}) : /*#__PURE__*/_jsx(InfoRow, {
|
|
184
|
+
label: "State",
|
|
185
|
+
value: info.accessibilityState
|
|
186
|
+
})]
|
|
187
|
+
}), info.styleInfo && /*#__PURE__*/_jsxs(_Fragment, {
|
|
188
|
+
children: [/*#__PURE__*/_jsx(Text, {
|
|
189
|
+
style: modalStyles.sectionTitle,
|
|
190
|
+
children: "Styles"
|
|
191
|
+
}), DataViewer ? /*#__PURE__*/_jsx(DataViewer, {
|
|
192
|
+
title: "Styles",
|
|
193
|
+
data: info.styleInfo,
|
|
194
|
+
showTypeFilter: false,
|
|
195
|
+
initialExpanded: true
|
|
196
|
+
}) : /*#__PURE__*/_jsx(View, {
|
|
197
|
+
style: modalStyles.codeBlock,
|
|
198
|
+
children: /*#__PURE__*/_jsx(Text, {
|
|
199
|
+
style: modalStyles.codeText,
|
|
200
|
+
children: JSON.stringify(info.styleInfo, null, 2)
|
|
201
|
+
})
|
|
202
|
+
})]
|
|
203
|
+
})]
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
export function DebugBordersStandaloneOverlay() {
|
|
207
|
+
const [mode, setMode] = useState("off");
|
|
208
|
+
const [rectangles, setRectangles] = useState([]);
|
|
209
|
+
const [selectedRect, setSelectedRect] = useState(null);
|
|
210
|
+
const [modalVisible, setModalVisible] = useState(false);
|
|
211
|
+
const measuringRef = React.useRef(false); // Prevent overlapping measurements
|
|
212
|
+
|
|
213
|
+
// Check if any DevTools are open (if context is available)
|
|
214
|
+
const isDevToolsActive = useDevToolsVisibility?.()?.isDevToolsActive ?? false;
|
|
215
|
+
const handleLabelPress = useCallback(rect => {
|
|
216
|
+
setSelectedRect(rect);
|
|
217
|
+
setModalVisible(true);
|
|
218
|
+
}, []);
|
|
219
|
+
const handleCloseModal = useCallback(() => {
|
|
220
|
+
setModalVisible(false);
|
|
221
|
+
setSelectedRect(null);
|
|
222
|
+
}, []);
|
|
223
|
+
|
|
224
|
+
// Effective enabled state: user enabled AND no DevTools active
|
|
225
|
+
const isEnabled = mode !== "off" && !isDevToolsActive;
|
|
226
|
+
const showLabels = mode === "labels" && !isDevToolsActive;
|
|
227
|
+
|
|
228
|
+
// Subscribe to manager
|
|
229
|
+
useEffect(() => {
|
|
230
|
+
const unsubscribe = DebugBordersManager.subscribe(newMode => {
|
|
231
|
+
setMode(newMode);
|
|
232
|
+
});
|
|
233
|
+
return unsubscribe;
|
|
234
|
+
}, []);
|
|
235
|
+
|
|
236
|
+
// Update measurements when enabled
|
|
237
|
+
useEffect(() => {
|
|
238
|
+
if (!isEnabled) {
|
|
239
|
+
setRectangles([]);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
let mounted = true;
|
|
243
|
+
let timer;
|
|
244
|
+
const updateMeasurements = async () => {
|
|
245
|
+
if (!mounted || measuringRef.current) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
measuringRef.current = true;
|
|
249
|
+
try {
|
|
250
|
+
const instances = getAllHostComponentInstances();
|
|
251
|
+
if (instances.length === 0) {
|
|
252
|
+
measuringRef.current = false;
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
const measurements = await measureInstances(instances);
|
|
256
|
+
if (mounted) {
|
|
257
|
+
// Resolve overlapping labels when in labels mode
|
|
258
|
+
const processedMeasurements = showLabels ? resolveOverlappingLabels(measurements) : measurements;
|
|
259
|
+
setRectangles(processedMeasurements);
|
|
260
|
+
}
|
|
261
|
+
} catch (error) {
|
|
262
|
+
console.error("[DebugBorders] Error updating measurements:", error);
|
|
263
|
+
} finally {
|
|
264
|
+
measuringRef.current = false;
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
// Initial measurement with delay to let UI settle
|
|
269
|
+
const initialTimer = setTimeout(() => {
|
|
270
|
+
updateMeasurements();
|
|
271
|
+
}, 500);
|
|
272
|
+
|
|
273
|
+
// Periodic updates (less frequent to avoid performance issues)
|
|
274
|
+
timer = setInterval(updateMeasurements, 2000);
|
|
275
|
+
return () => {
|
|
276
|
+
mounted = false;
|
|
277
|
+
clearTimeout(initialTimer);
|
|
278
|
+
clearInterval(timer);
|
|
279
|
+
measuringRef.current = false;
|
|
280
|
+
};
|
|
281
|
+
}, [isEnabled, showLabels, rectangles.length]);
|
|
282
|
+
if (!isEnabled) {
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
286
|
+
style: styles.overlay,
|
|
287
|
+
pointerEvents: "box-none"
|
|
288
|
+
// @ts-ignore - custom prop to identify this as debug overlay
|
|
289
|
+
,
|
|
290
|
+
dataSet: {
|
|
291
|
+
debugOverlay: "true"
|
|
292
|
+
},
|
|
293
|
+
nativeID: "debug-borders-overlay",
|
|
294
|
+
children: [rectangles.map((rect, index) => {
|
|
295
|
+
const info = rect.componentInfo;
|
|
296
|
+
const hasValidLabel = info && (info.testID || info.accessibilityLabel);
|
|
297
|
+
|
|
298
|
+
// In labels mode, only show components with testID or accessibilityLabel
|
|
299
|
+
if (showLabels && !hasValidLabel) {
|
|
300
|
+
return null;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// Use label color for border when in labels mode, otherwise use depth-based color
|
|
304
|
+
const borderColor = showLabels && info ? info.primaryColor : getColorForDepth(rect.depth);
|
|
305
|
+
return /*#__PURE__*/_jsxs(React.Fragment, {
|
|
306
|
+
children: [/*#__PURE__*/_jsx(View, {
|
|
307
|
+
pointerEvents: "none",
|
|
308
|
+
style: [styles.border, {
|
|
309
|
+
left: rect.x,
|
|
310
|
+
top: rect.y,
|
|
311
|
+
width: rect.width,
|
|
312
|
+
height: rect.height,
|
|
313
|
+
borderColor: borderColor
|
|
314
|
+
}]
|
|
315
|
+
}), showLabels && hasValidLabel && /*#__PURE__*/_jsx(TouchableOpacity, {
|
|
316
|
+
activeOpacity: 0.7,
|
|
317
|
+
onPress: () => handleLabelPress(rect),
|
|
318
|
+
style: [styles.labelContainer, {
|
|
319
|
+
left: rect.x,
|
|
320
|
+
top: rect.y - 10 - (rect.labelOffsetY || 0),
|
|
321
|
+
backgroundColor: info.primaryColor
|
|
322
|
+
}],
|
|
323
|
+
children: /*#__PURE__*/_jsx(Text, {
|
|
324
|
+
style: styles.labelText,
|
|
325
|
+
numberOfLines: 1,
|
|
326
|
+
children: info.primaryLabel
|
|
327
|
+
})
|
|
328
|
+
})]
|
|
329
|
+
}, `border-${index}`);
|
|
330
|
+
}), JsModal && selectedRect?.componentInfo && /*#__PURE__*/_jsx(JsModal, {
|
|
331
|
+
visible: modalVisible,
|
|
332
|
+
onClose: handleCloseModal,
|
|
333
|
+
initialMode: "bottomSheet",
|
|
334
|
+
header: {
|
|
335
|
+
customContent: /*#__PURE__*/_jsx(SimpleHeader, {
|
|
336
|
+
title: selectedRect.componentInfo.primaryLabel
|
|
337
|
+
})
|
|
338
|
+
},
|
|
339
|
+
persistenceKey: "debug-borders-info-modal",
|
|
340
|
+
enablePersistence: false,
|
|
341
|
+
children: /*#__PURE__*/_jsx(ComponentInfoContent, {
|
|
342
|
+
info: selectedRect.componentInfo,
|
|
343
|
+
rect: selectedRect
|
|
344
|
+
})
|
|
345
|
+
})]
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
const styles = StyleSheet.create({
|
|
349
|
+
overlay: {
|
|
350
|
+
position: "absolute",
|
|
351
|
+
top: 0,
|
|
352
|
+
left: 0,
|
|
353
|
+
right: 0,
|
|
354
|
+
bottom: 0,
|
|
355
|
+
// Use z-index below floating dev tools (9999-10001) but above normal app content
|
|
356
|
+
zIndex: 9000,
|
|
357
|
+
elevation: 9000
|
|
358
|
+
},
|
|
359
|
+
border: {
|
|
360
|
+
position: "absolute",
|
|
361
|
+
borderWidth: 1,
|
|
362
|
+
borderStyle: "solid"
|
|
363
|
+
},
|
|
364
|
+
labelContainer: {
|
|
365
|
+
position: "absolute",
|
|
366
|
+
paddingHorizontal: 4,
|
|
367
|
+
paddingVertical: 1,
|
|
368
|
+
borderRadius: 2
|
|
369
|
+
},
|
|
370
|
+
labelText: {
|
|
371
|
+
fontSize: 8,
|
|
372
|
+
fontWeight: "700",
|
|
373
|
+
fontFamily: "monospace",
|
|
374
|
+
color: "#ffffff"
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
const headerStyles = StyleSheet.create({
|
|
378
|
+
container: {
|
|
379
|
+
paddingHorizontal: 16,
|
|
380
|
+
paddingVertical: 8,
|
|
381
|
+
alignItems: "center"
|
|
382
|
+
},
|
|
383
|
+
title: {
|
|
384
|
+
fontSize: 16,
|
|
385
|
+
fontWeight: "600",
|
|
386
|
+
color: "#ffffff",
|
|
387
|
+
fontFamily: "monospace"
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
const modalStyles = StyleSheet.create({
|
|
391
|
+
content: {
|
|
392
|
+
padding: 16
|
|
393
|
+
},
|
|
394
|
+
sectionTitle: {
|
|
395
|
+
fontSize: 12,
|
|
396
|
+
fontWeight: "700",
|
|
397
|
+
color: "#6b7280",
|
|
398
|
+
marginTop: 16,
|
|
399
|
+
marginBottom: 8,
|
|
400
|
+
textTransform: "uppercase",
|
|
401
|
+
letterSpacing: 1
|
|
402
|
+
},
|
|
403
|
+
row: {
|
|
404
|
+
flexDirection: "row",
|
|
405
|
+
paddingVertical: 8,
|
|
406
|
+
borderBottomWidth: 1,
|
|
407
|
+
borderBottomColor: "rgba(255, 255, 255, 0.1)"
|
|
408
|
+
},
|
|
409
|
+
label: {
|
|
410
|
+
fontSize: 13,
|
|
411
|
+
color: "#9ca3af",
|
|
412
|
+
width: 140,
|
|
413
|
+
fontFamily: "monospace"
|
|
414
|
+
},
|
|
415
|
+
value: {
|
|
416
|
+
fontSize: 13,
|
|
417
|
+
color: "#ffffff",
|
|
418
|
+
flex: 1,
|
|
419
|
+
fontFamily: "monospace"
|
|
420
|
+
},
|
|
421
|
+
codeBlock: {
|
|
422
|
+
backgroundColor: "rgba(0, 0, 0, 0.3)",
|
|
423
|
+
padding: 12,
|
|
424
|
+
borderRadius: 8,
|
|
425
|
+
marginTop: 4
|
|
426
|
+
},
|
|
427
|
+
codeText: {
|
|
428
|
+
fontSize: 11,
|
|
429
|
+
color: "#e5e7eb",
|
|
430
|
+
fontFamily: "monospace"
|
|
431
|
+
}
|
|
432
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Export types
|
|
4
|
+
export * from "./types";
|
|
5
|
+
|
|
6
|
+
// Export components
|
|
7
|
+
export { DebugBordersModal } from "./components/DebugBordersModal";
|
|
8
|
+
export { DebugBordersStandaloneOverlay } from "./components/DebugBordersStandaloneOverlay";
|
|
9
|
+
|
|
10
|
+
// Export utilities (JS modules - will be typed when converted to TS)
|
|
11
|
+
// Note: These are CommonJS modules, so we use require for now
|
|
12
|
+
export const DebugBordersManager = require("./utils/DebugBordersManager");
|
|
13
|
+
export const fiberTreeTraversal = require("./utils/fiberTreeTraversal");
|
|
14
|
+
export const componentMeasurement = require("./utils/componentMeasurement");
|
|
15
|
+
export const colorGeneration = require("./utils/colorGeneration");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
let globalMode = "off";
|
|
4
|
+
const listeners = new Set();
|
|
5
|
+
const MODE_CYCLE_FULL = ["off", "borders", "labels"];
|
|
6
|
+
const MODE_CYCLE_FREE = ["off", "borders"];
|
|
7
|
+
let _isPro = null;
|
|
8
|
+
let _licenseLoadAttempted = false;
|
|
9
|
+
function loadLicenseModule() {
|
|
10
|
+
if (_licenseLoadAttempted) return;
|
|
11
|
+
_licenseLoadAttempted = true;
|
|
12
|
+
try {
|
|
13
|
+
const mod = require("@buoy/license");
|
|
14
|
+
if (mod && typeof mod.isPro === "function") {
|
|
15
|
+
_isPro = mod.isPro;
|
|
16
|
+
}
|
|
17
|
+
} catch {
|
|
18
|
+
_isPro = null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function checkIsPro() {
|
|
22
|
+
loadLicenseModule();
|
|
23
|
+
if (_isPro) {
|
|
24
|
+
try {
|
|
25
|
+
return _isPro();
|
|
26
|
+
} catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
function getModeCycle() {
|
|
33
|
+
return checkIsPro() ? MODE_CYCLE_FULL : MODE_CYCLE_FREE;
|
|
34
|
+
}
|
|
35
|
+
const MODE_CYCLE = MODE_CYCLE_FULL;
|
|
36
|
+
function subscribe(listener) {
|
|
37
|
+
listeners.add(listener);
|
|
38
|
+
listener(globalMode);
|
|
39
|
+
return () => {
|
|
40
|
+
listeners.delete(listener);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function notifyListeners() {
|
|
44
|
+
listeners.forEach(listener => {
|
|
45
|
+
try {
|
|
46
|
+
listener(globalMode);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.error("[DebugBorders] Error in listener:", error);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function setMode(mode) {
|
|
53
|
+
if (globalMode === mode) {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
if (mode === "labels" && !checkIsPro()) {
|
|
57
|
+
console.warn("[DebugBorders] Labels mode requires React Buoy Pro. Upgrade at https://buoy.gg/pro");
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
globalMode = mode;
|
|
61
|
+
notifyListeners();
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
function getMode() {
|
|
65
|
+
return globalMode;
|
|
66
|
+
}
|
|
67
|
+
function cycle() {
|
|
68
|
+
const availableModes = getModeCycle();
|
|
69
|
+
const currentIndex = availableModes.indexOf(globalMode);
|
|
70
|
+
if (currentIndex === -1) {
|
|
71
|
+
setMode("off");
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const nextIndex = (currentIndex + 1) % availableModes.length;
|
|
75
|
+
setMode(availableModes[nextIndex]);
|
|
76
|
+
}
|
|
77
|
+
function enable() {
|
|
78
|
+
setMode("borders");
|
|
79
|
+
}
|
|
80
|
+
function disable() {
|
|
81
|
+
setMode("off");
|
|
82
|
+
}
|
|
83
|
+
function toggle() {
|
|
84
|
+
cycle();
|
|
85
|
+
}
|
|
86
|
+
function isEnabled() {
|
|
87
|
+
return globalMode !== "off";
|
|
88
|
+
}
|
|
89
|
+
function showLabels() {
|
|
90
|
+
return globalMode === "labels" && checkIsPro();
|
|
91
|
+
}
|
|
92
|
+
function isProEnabled() {
|
|
93
|
+
return checkIsPro();
|
|
94
|
+
}
|
|
95
|
+
function getAvailableModes() {
|
|
96
|
+
return getModeCycle();
|
|
97
|
+
}
|
|
98
|
+
function setEnabled(enabled) {
|
|
99
|
+
if (enabled) {
|
|
100
|
+
enable();
|
|
101
|
+
} else {
|
|
102
|
+
disable();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
module.exports = {
|
|
106
|
+
subscribe,
|
|
107
|
+
enable,
|
|
108
|
+
disable,
|
|
109
|
+
toggle,
|
|
110
|
+
cycle,
|
|
111
|
+
isEnabled,
|
|
112
|
+
showLabels,
|
|
113
|
+
setEnabled,
|
|
114
|
+
getMode,
|
|
115
|
+
setMode,
|
|
116
|
+
isProEnabled,
|
|
117
|
+
getAvailableModes,
|
|
118
|
+
MODE_CYCLE
|
|
119
|
+
};
|