bippy 0.2.0 → 0.2.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 +8 -0
- package/dist/chunk-6TJRMCM3.js +1 -0
- package/dist/{extract/index.cjs → chunk-XBNRYX4A.js} +142 -474
- package/dist/{extract/index.js → chunk-XCDPKSJZ.cjs} +205 -468
- package/dist/chunk-YZYCWAB2.cjs +2 -0
- package/dist/core-DBUthQlD.d.cts +261 -0
- package/dist/core-DBUthQlD.d.ts +261 -0
- package/dist/core.cjs +229 -740
- package/dist/core.d.cts +3 -196
- package/dist/core.d.ts +3 -196
- package/dist/core.js +1 -687
- package/dist/index.cjs +250 -745
- package/dist/index.d.cts +2 -3
- package/dist/index.d.ts +2 -3
- package/dist/index.global.js +1 -1
- package/dist/index.js +2 -687
- package/dist/inspect.cjs +1560 -0
- package/dist/inspect.d.cts +10 -0
- package/dist/inspect.d.ts +10 -0
- package/dist/inspect.js +1551 -0
- package/package.json +19 -2
- package/dist/extract/index.d.cts +0 -42
- package/dist/extract/index.d.ts +0 -42
- package/dist/extract/index.global.js +0 -9
- package/dist/scan/index.cjs +0 -1079
- package/dist/scan/index.d.cts +0 -24
- package/dist/scan/index.d.ts +0 -24
- package/dist/scan/index.global.js +0 -9
- package/dist/scan/index.js +0 -1071
- package/dist/types-BqcvCznx.d.cts +0 -69
- package/dist/types-BqcvCznx.d.ts +0 -69
package/dist/scan/index.js
DELETED
|
@@ -1,1071 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license bippy
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) Aiden Bai, Million Software, Inc.
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE file in the root directory of this source tree.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
// src/rdt-hook.ts
|
|
11
|
-
var version = "0.2.0";
|
|
12
|
-
var BIPPY_INSTRUMENTATION_STRING = `bippy-${version}`;
|
|
13
|
-
var NO_OP = () => {
|
|
14
|
-
};
|
|
15
|
-
var checkDCE = (fn) => {
|
|
16
|
-
try {
|
|
17
|
-
const code = Function.prototype.toString.call(fn);
|
|
18
|
-
if (code.indexOf("^_^") > -1) {
|
|
19
|
-
setTimeout(() => {
|
|
20
|
-
throw new Error(
|
|
21
|
-
"React is running in production mode, but dead code elimination has not been applied. Read how to correctly configure React for production: https://reactjs.org/link/perf-use-production-build"
|
|
22
|
-
);
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
} catch {
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
var installRDTHook = (onActive) => {
|
|
29
|
-
const renderers = /* @__PURE__ */ new Map();
|
|
30
|
-
let i = 0;
|
|
31
|
-
const rdtHook = {
|
|
32
|
-
checkDCE,
|
|
33
|
-
supportsFiber: true,
|
|
34
|
-
supportsFlight: true,
|
|
35
|
-
hasUnsupportedRendererAttached: false,
|
|
36
|
-
renderers,
|
|
37
|
-
onCommitFiberRoot: NO_OP,
|
|
38
|
-
onCommitFiberUnmount: NO_OP,
|
|
39
|
-
onPostCommitFiberRoot: NO_OP,
|
|
40
|
-
inject(renderer) {
|
|
41
|
-
const nextID = ++i;
|
|
42
|
-
renderers.set(nextID, renderer);
|
|
43
|
-
if (!rdtHook._instrumentationIsActive) {
|
|
44
|
-
rdtHook._instrumentationIsActive = true;
|
|
45
|
-
onActive?.();
|
|
46
|
-
}
|
|
47
|
-
return nextID;
|
|
48
|
-
},
|
|
49
|
-
_instrumentationSource: BIPPY_INSTRUMENTATION_STRING,
|
|
50
|
-
_instrumentationIsActive: false
|
|
51
|
-
};
|
|
52
|
-
try {
|
|
53
|
-
Object.defineProperty(globalThis, "__REACT_DEVTOOLS_GLOBAL_HOOK__", {
|
|
54
|
-
value: rdtHook
|
|
55
|
-
});
|
|
56
|
-
} catch {
|
|
57
|
-
}
|
|
58
|
-
return rdtHook;
|
|
59
|
-
};
|
|
60
|
-
var hasRDTHook = () => {
|
|
61
|
-
return Object.prototype.hasOwnProperty.call(
|
|
62
|
-
globalThis,
|
|
63
|
-
"__REACT_DEVTOOLS_GLOBAL_HOOK__"
|
|
64
|
-
);
|
|
65
|
-
};
|
|
66
|
-
var getRDTHook = (onActive) => {
|
|
67
|
-
let rdtHook = globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__;
|
|
68
|
-
if (rdtHook) onActive?.();
|
|
69
|
-
if (!hasRDTHook()) {
|
|
70
|
-
rdtHook = installRDTHook(onActive);
|
|
71
|
-
}
|
|
72
|
-
return rdtHook;
|
|
73
|
-
};
|
|
74
|
-
try {
|
|
75
|
-
if (typeof window !== "undefined" && // @ts-expect-error `document` may not be defined in some enviroments
|
|
76
|
-
(window.document?.createElement || window.navigator?.product === "ReactNative") && typeof process !== "undefined" && process.versions != null && process.versions.node != null) {
|
|
77
|
-
installRDTHook();
|
|
78
|
-
}
|
|
79
|
-
} catch {
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// src/core.ts
|
|
83
|
-
var FunctionComponentTag = 0;
|
|
84
|
-
var ClassComponentTag = 1;
|
|
85
|
-
var HostRootTag = 3;
|
|
86
|
-
var HostComponentTag = 5;
|
|
87
|
-
var HostTextTag = 6;
|
|
88
|
-
var FragmentTag = 7;
|
|
89
|
-
var ContextConsumerTag = 9;
|
|
90
|
-
var ForwardRefTag = 11;
|
|
91
|
-
var SuspenseComponentTag = 13;
|
|
92
|
-
var MemoComponentTag = 14;
|
|
93
|
-
var SimpleMemoComponentTag = 15;
|
|
94
|
-
var DehydratedSuspenseComponentTag = 18;
|
|
95
|
-
var OffscreenComponentTag = 22;
|
|
96
|
-
var LegacyHiddenComponentTag = 23;
|
|
97
|
-
var HostHoistableTag = 26;
|
|
98
|
-
var HostSingletonTag = 27;
|
|
99
|
-
var CONCURRENT_MODE_NUMBER = 60111;
|
|
100
|
-
var CONCURRENT_MODE_SYMBOL_STRING = "Symbol(react.concurrent_mode)";
|
|
101
|
-
var DEPRECATED_ASYNC_MODE_SYMBOL_STRING = "Symbol(react.async_mode)";
|
|
102
|
-
var PerformedWork = 1;
|
|
103
|
-
var Placement = 2;
|
|
104
|
-
var Hydrating = 4096;
|
|
105
|
-
var Update = 4;
|
|
106
|
-
var Cloned = 8;
|
|
107
|
-
var ChildDeletion = 16;
|
|
108
|
-
var ContentReset = 32;
|
|
109
|
-
var Snapshot = 1024;
|
|
110
|
-
var Visibility = 8192;
|
|
111
|
-
var MutationMask = Placement | Update | ChildDeletion | ContentReset | Hydrating | Visibility | Snapshot;
|
|
112
|
-
var isHostFiber = (fiber) => {
|
|
113
|
-
switch (fiber.tag) {
|
|
114
|
-
case HostComponentTag:
|
|
115
|
-
// @ts-expect-error: it exists
|
|
116
|
-
case HostHoistableTag:
|
|
117
|
-
// @ts-expect-error: it exists
|
|
118
|
-
case HostSingletonTag:
|
|
119
|
-
return true;
|
|
120
|
-
default:
|
|
121
|
-
return typeof fiber.type === "string";
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
var isCompositeFiber = (fiber) => {
|
|
125
|
-
switch (fiber.tag) {
|
|
126
|
-
case FunctionComponentTag:
|
|
127
|
-
case ClassComponentTag:
|
|
128
|
-
case SimpleMemoComponentTag:
|
|
129
|
-
case MemoComponentTag:
|
|
130
|
-
case ForwardRefTag:
|
|
131
|
-
return true;
|
|
132
|
-
default:
|
|
133
|
-
return false;
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
var didFiberRender = (fiber) => {
|
|
137
|
-
const nextProps = fiber.memoizedProps;
|
|
138
|
-
const prevProps = fiber.alternate?.memoizedProps || {};
|
|
139
|
-
const flags = fiber.flags ?? fiber.effectTag ?? 0;
|
|
140
|
-
switch (fiber.tag) {
|
|
141
|
-
case ClassComponentTag:
|
|
142
|
-
case FunctionComponentTag:
|
|
143
|
-
case ContextConsumerTag:
|
|
144
|
-
case ForwardRefTag:
|
|
145
|
-
case MemoComponentTag:
|
|
146
|
-
case SimpleMemoComponentTag: {
|
|
147
|
-
return (flags & PerformedWork) === PerformedWork;
|
|
148
|
-
}
|
|
149
|
-
default:
|
|
150
|
-
if (!fiber.alternate) return true;
|
|
151
|
-
return prevProps !== nextProps || fiber.alternate.memoizedState !== fiber.memoizedState || fiber.alternate.ref !== fiber.ref;
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
var didFiberCommit = (fiber) => {
|
|
155
|
-
return Boolean(
|
|
156
|
-
(fiber.flags & (MutationMask | Cloned)) !== 0 || (fiber.subtreeFlags & (MutationMask | Cloned)) !== 0
|
|
157
|
-
);
|
|
158
|
-
};
|
|
159
|
-
var shouldFilterFiber = (fiber) => {
|
|
160
|
-
switch (fiber.tag) {
|
|
161
|
-
case DehydratedSuspenseComponentTag:
|
|
162
|
-
return true;
|
|
163
|
-
case HostTextTag:
|
|
164
|
-
case FragmentTag:
|
|
165
|
-
case LegacyHiddenComponentTag:
|
|
166
|
-
case OffscreenComponentTag:
|
|
167
|
-
return true;
|
|
168
|
-
case HostRootTag:
|
|
169
|
-
return false;
|
|
170
|
-
default: {
|
|
171
|
-
const symbolOrNumber = typeof fiber.type === "object" && fiber.type !== null ? fiber.type.$$typeof : fiber.type;
|
|
172
|
-
const typeSymbol = typeof symbolOrNumber === "symbol" ? symbolOrNumber.toString() : symbolOrNumber;
|
|
173
|
-
switch (typeSymbol) {
|
|
174
|
-
case CONCURRENT_MODE_NUMBER:
|
|
175
|
-
case CONCURRENT_MODE_SYMBOL_STRING:
|
|
176
|
-
case DEPRECATED_ASYNC_MODE_SYMBOL_STRING:
|
|
177
|
-
return true;
|
|
178
|
-
default:
|
|
179
|
-
return false;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
var getNearestHostFibers = (fiber) => {
|
|
185
|
-
const hostFibers = [];
|
|
186
|
-
const stack = [];
|
|
187
|
-
if (isHostFiber(fiber)) {
|
|
188
|
-
hostFibers.push(fiber);
|
|
189
|
-
} else if (fiber.child) {
|
|
190
|
-
stack.push(fiber.child);
|
|
191
|
-
}
|
|
192
|
-
while (stack.length) {
|
|
193
|
-
const currentNode = stack.pop();
|
|
194
|
-
if (!currentNode) break;
|
|
195
|
-
if (isHostFiber(currentNode)) {
|
|
196
|
-
hostFibers.push(currentNode);
|
|
197
|
-
} else if (currentNode.child) {
|
|
198
|
-
stack.push(currentNode.child);
|
|
199
|
-
}
|
|
200
|
-
if (currentNode.sibling) {
|
|
201
|
-
stack.push(currentNode.sibling);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
return hostFibers;
|
|
205
|
-
};
|
|
206
|
-
var getType = (type) => {
|
|
207
|
-
const currentType = type;
|
|
208
|
-
if (typeof currentType === "function") {
|
|
209
|
-
return currentType;
|
|
210
|
-
}
|
|
211
|
-
if (typeof currentType === "object" && currentType) {
|
|
212
|
-
return getType(
|
|
213
|
-
currentType.type || currentType.render
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
return null;
|
|
217
|
-
};
|
|
218
|
-
var getDisplayName = (type) => {
|
|
219
|
-
const currentType = type;
|
|
220
|
-
if (typeof currentType !== "function" && !(typeof currentType === "object" && currentType)) {
|
|
221
|
-
return null;
|
|
222
|
-
}
|
|
223
|
-
const name = currentType.displayName || currentType.name || null;
|
|
224
|
-
if (name) return name;
|
|
225
|
-
const unwrappedType = getType(currentType);
|
|
226
|
-
if (!unwrappedType) return null;
|
|
227
|
-
return unwrappedType.displayName || unwrappedType.name || null;
|
|
228
|
-
};
|
|
229
|
-
var isUsingRDT = () => {
|
|
230
|
-
return "reactDevtoolsAgent" in getRDTHook();
|
|
231
|
-
};
|
|
232
|
-
var detectReactBuildType = (renderer) => {
|
|
233
|
-
try {
|
|
234
|
-
if (typeof renderer.version === "string" && renderer.bundleType > 0) {
|
|
235
|
-
return "development";
|
|
236
|
-
}
|
|
237
|
-
} catch {
|
|
238
|
-
}
|
|
239
|
-
return "production";
|
|
240
|
-
};
|
|
241
|
-
var fiberId = 0;
|
|
242
|
-
var fiberIdMap = /* @__PURE__ */ new WeakMap();
|
|
243
|
-
var setFiberId = (fiber, id = fiberId++) => {
|
|
244
|
-
fiberIdMap.set(fiber, id);
|
|
245
|
-
};
|
|
246
|
-
var getFiberId = (fiber) => {
|
|
247
|
-
let id = fiberIdMap.get(fiber);
|
|
248
|
-
if (!id && fiber.alternate) {
|
|
249
|
-
id = fiberIdMap.get(fiber.alternate);
|
|
250
|
-
}
|
|
251
|
-
if (!id) {
|
|
252
|
-
id = fiberId++;
|
|
253
|
-
setFiberId(fiber, id);
|
|
254
|
-
}
|
|
255
|
-
return id;
|
|
256
|
-
};
|
|
257
|
-
var mountFiberRecursively = (onRender, firstChild, traverseSiblings) => {
|
|
258
|
-
let fiber = firstChild;
|
|
259
|
-
while (fiber != null) {
|
|
260
|
-
if (!fiberIdMap.has(fiber)) {
|
|
261
|
-
getFiberId(fiber);
|
|
262
|
-
}
|
|
263
|
-
const shouldIncludeInTree = !shouldFilterFiber(fiber);
|
|
264
|
-
if (shouldIncludeInTree && didFiberRender(fiber)) {
|
|
265
|
-
onRender(fiber, "mount");
|
|
266
|
-
}
|
|
267
|
-
if (fiber.tag === SuspenseComponentTag) {
|
|
268
|
-
const isTimedOut = fiber.memoizedState !== null;
|
|
269
|
-
if (isTimedOut) {
|
|
270
|
-
const primaryChildFragment = fiber.child;
|
|
271
|
-
const fallbackChildFragment = primaryChildFragment ? primaryChildFragment.sibling : null;
|
|
272
|
-
if (fallbackChildFragment) {
|
|
273
|
-
const fallbackChild = fallbackChildFragment.child;
|
|
274
|
-
if (fallbackChild !== null) {
|
|
275
|
-
mountFiberRecursively(onRender, fallbackChild, false);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
} else {
|
|
279
|
-
let primaryChild = null;
|
|
280
|
-
if (fiber.child !== null) {
|
|
281
|
-
primaryChild = fiber.child.child;
|
|
282
|
-
}
|
|
283
|
-
if (primaryChild !== null) {
|
|
284
|
-
mountFiberRecursively(onRender, primaryChild, false);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
} else if (fiber.child != null) {
|
|
288
|
-
mountFiberRecursively(onRender, fiber.child, true);
|
|
289
|
-
}
|
|
290
|
-
fiber = traverseSiblings ? fiber.sibling : null;
|
|
291
|
-
}
|
|
292
|
-
};
|
|
293
|
-
var updateFiberRecursively = (onRender, nextFiber, prevFiber, parentFiber) => {
|
|
294
|
-
if (!fiberIdMap.has(nextFiber)) {
|
|
295
|
-
getFiberId(nextFiber);
|
|
296
|
-
}
|
|
297
|
-
if (!prevFiber) return;
|
|
298
|
-
if (!fiberIdMap.has(prevFiber)) {
|
|
299
|
-
getFiberId(prevFiber);
|
|
300
|
-
}
|
|
301
|
-
const isSuspense = nextFiber.tag === SuspenseComponentTag;
|
|
302
|
-
const shouldIncludeInTree = !shouldFilterFiber(nextFiber);
|
|
303
|
-
if (shouldIncludeInTree && didFiberRender(nextFiber)) {
|
|
304
|
-
onRender(nextFiber, "update");
|
|
305
|
-
}
|
|
306
|
-
const prevDidTimeout = isSuspense && prevFiber.memoizedState !== null;
|
|
307
|
-
const nextDidTimeOut = isSuspense && nextFiber.memoizedState !== null;
|
|
308
|
-
if (prevDidTimeout && nextDidTimeOut) {
|
|
309
|
-
const nextFallbackChildSet = nextFiber.child?.sibling ?? null;
|
|
310
|
-
const prevFallbackChildSet = prevFiber.child?.sibling ?? null;
|
|
311
|
-
if (nextFallbackChildSet !== null && prevFallbackChildSet !== null) {
|
|
312
|
-
updateFiberRecursively(
|
|
313
|
-
onRender,
|
|
314
|
-
nextFallbackChildSet,
|
|
315
|
-
prevFallbackChildSet);
|
|
316
|
-
}
|
|
317
|
-
} else if (prevDidTimeout && !nextDidTimeOut) {
|
|
318
|
-
const nextPrimaryChildSet = nextFiber.child;
|
|
319
|
-
if (nextPrimaryChildSet !== null) {
|
|
320
|
-
mountFiberRecursively(onRender, nextPrimaryChildSet, true);
|
|
321
|
-
}
|
|
322
|
-
} else if (!prevDidTimeout && nextDidTimeOut) {
|
|
323
|
-
unmountFiberChildrenRecursively(onRender, prevFiber);
|
|
324
|
-
const nextFallbackChildSet = nextFiber.child?.sibling ?? null;
|
|
325
|
-
if (nextFallbackChildSet !== null) {
|
|
326
|
-
mountFiberRecursively(onRender, nextFallbackChildSet, true);
|
|
327
|
-
}
|
|
328
|
-
} else if (nextFiber.child !== prevFiber.child) {
|
|
329
|
-
let nextChild = nextFiber.child;
|
|
330
|
-
while (nextChild) {
|
|
331
|
-
if (nextChild.alternate) {
|
|
332
|
-
const prevChild = nextChild.alternate;
|
|
333
|
-
updateFiberRecursively(
|
|
334
|
-
onRender,
|
|
335
|
-
nextChild,
|
|
336
|
-
prevChild);
|
|
337
|
-
} else {
|
|
338
|
-
mountFiberRecursively(onRender, nextChild, false);
|
|
339
|
-
}
|
|
340
|
-
nextChild = nextChild.sibling;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
};
|
|
344
|
-
var unmountFiber = (onRender, fiber) => {
|
|
345
|
-
const isRoot = fiber.tag === HostRootTag;
|
|
346
|
-
if (isRoot || !shouldFilterFiber(fiber)) {
|
|
347
|
-
onRender(fiber, "unmount");
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
var unmountFiberChildrenRecursively = (onRender, fiber) => {
|
|
351
|
-
const isTimedOutSuspense = fiber.tag === SuspenseComponentTag && fiber.memoizedState !== null;
|
|
352
|
-
let child = fiber.child;
|
|
353
|
-
if (isTimedOutSuspense) {
|
|
354
|
-
const primaryChildFragment = fiber.child;
|
|
355
|
-
const fallbackChildFragment = primaryChildFragment?.sibling ?? null;
|
|
356
|
-
child = fallbackChildFragment?.child ?? null;
|
|
357
|
-
}
|
|
358
|
-
while (child !== null) {
|
|
359
|
-
if (child.return !== null) {
|
|
360
|
-
unmountFiber(onRender, child);
|
|
361
|
-
unmountFiberChildrenRecursively(onRender, child);
|
|
362
|
-
}
|
|
363
|
-
child = child.sibling;
|
|
364
|
-
}
|
|
365
|
-
};
|
|
366
|
-
var commitId = 0;
|
|
367
|
-
var rootInstanceMap = /* @__PURE__ */ new WeakMap();
|
|
368
|
-
var traverseRenderedFibers = (root, onRender) => {
|
|
369
|
-
const fiber = "current" in root ? root.current : root;
|
|
370
|
-
let rootInstance = rootInstanceMap.get(root);
|
|
371
|
-
if (!rootInstance) {
|
|
372
|
-
rootInstance = { prevFiber: null, id: commitId++ };
|
|
373
|
-
rootInstanceMap.set(root, rootInstance);
|
|
374
|
-
}
|
|
375
|
-
const { prevFiber } = rootInstance;
|
|
376
|
-
if (!fiber) {
|
|
377
|
-
unmountFiber(onRender, fiber);
|
|
378
|
-
} else if (prevFiber !== null) {
|
|
379
|
-
const wasMounted = prevFiber && prevFiber.memoizedState != null && prevFiber.memoizedState.element != null && // A dehydrated root is not considered mounted
|
|
380
|
-
prevFiber.memoizedState.isDehydrated !== true;
|
|
381
|
-
const isMounted = fiber.memoizedState != null && fiber.memoizedState.element != null && // A dehydrated root is not considered mounted
|
|
382
|
-
fiber.memoizedState.isDehydrated !== true;
|
|
383
|
-
if (!wasMounted && isMounted) {
|
|
384
|
-
mountFiberRecursively(onRender, fiber, false);
|
|
385
|
-
} else if (wasMounted && isMounted) {
|
|
386
|
-
updateFiberRecursively(onRender, fiber, fiber.alternate);
|
|
387
|
-
} else if (wasMounted && !isMounted) {
|
|
388
|
-
unmountFiber(onRender, fiber);
|
|
389
|
-
}
|
|
390
|
-
} else {
|
|
391
|
-
mountFiberRecursively(onRender, fiber, true);
|
|
392
|
-
}
|
|
393
|
-
rootInstance.prevFiber = fiber;
|
|
394
|
-
};
|
|
395
|
-
var createFiberVisitor = ({
|
|
396
|
-
onRender
|
|
397
|
-
}) => {
|
|
398
|
-
return (_rendererID, root, _state) => {
|
|
399
|
-
traverseRenderedFibers(root, onRender);
|
|
400
|
-
};
|
|
401
|
-
};
|
|
402
|
-
var instrument = (options) => {
|
|
403
|
-
return getRDTHook(() => {
|
|
404
|
-
const rdtHook = getRDTHook();
|
|
405
|
-
options.onActive?.();
|
|
406
|
-
rdtHook._instrumentationSource = options.name ?? BIPPY_INSTRUMENTATION_STRING;
|
|
407
|
-
const prevOnCommitFiberRoot = rdtHook.onCommitFiberRoot;
|
|
408
|
-
if (options.onCommitFiberRoot) {
|
|
409
|
-
rdtHook.onCommitFiberRoot = (rendererID, root, priority) => {
|
|
410
|
-
if (prevOnCommitFiberRoot)
|
|
411
|
-
prevOnCommitFiberRoot(rendererID, root, priority);
|
|
412
|
-
options.onCommitFiberRoot?.(rendererID, root, priority);
|
|
413
|
-
};
|
|
414
|
-
}
|
|
415
|
-
const prevOnCommitFiberUnmount = rdtHook.onCommitFiberUnmount;
|
|
416
|
-
if (options.onCommitFiberUnmount) {
|
|
417
|
-
rdtHook.onCommitFiberUnmount = (rendererID, root) => {
|
|
418
|
-
if (prevOnCommitFiberUnmount)
|
|
419
|
-
prevOnCommitFiberUnmount(rendererID, root);
|
|
420
|
-
options.onCommitFiberUnmount?.(rendererID, root);
|
|
421
|
-
};
|
|
422
|
-
}
|
|
423
|
-
const prevOnPostCommitFiberRoot = rdtHook.onPostCommitFiberRoot;
|
|
424
|
-
if (options.onPostCommitFiberRoot) {
|
|
425
|
-
rdtHook.onPostCommitFiberRoot = (rendererID, root) => {
|
|
426
|
-
if (prevOnPostCommitFiberRoot)
|
|
427
|
-
prevOnPostCommitFiberRoot(rendererID, root);
|
|
428
|
-
options.onPostCommitFiberRoot?.(rendererID, root);
|
|
429
|
-
};
|
|
430
|
-
}
|
|
431
|
-
});
|
|
432
|
-
};
|
|
433
|
-
var secure = (options, secureOptions = {}) => {
|
|
434
|
-
const onActive = options.onActive;
|
|
435
|
-
const isRDTHookInstalled = hasRDTHook();
|
|
436
|
-
const isRDT = isUsingRDT();
|
|
437
|
-
let timeout;
|
|
438
|
-
let isProduction = false;
|
|
439
|
-
options.onActive = () => {
|
|
440
|
-
clearTimeout(timeout);
|
|
441
|
-
let isSecure = true;
|
|
442
|
-
try {
|
|
443
|
-
onActive?.();
|
|
444
|
-
const rdtHook = getRDTHook();
|
|
445
|
-
for (const renderer of rdtHook.renderers.values()) {
|
|
446
|
-
const [majorVersion] = renderer.version.split(".");
|
|
447
|
-
if (Number(majorVersion) < (secureOptions.minReactMajorVersion ?? 17)) {
|
|
448
|
-
isSecure = false;
|
|
449
|
-
}
|
|
450
|
-
const buildType = detectReactBuildType(renderer);
|
|
451
|
-
if (buildType !== "development") {
|
|
452
|
-
isProduction = true;
|
|
453
|
-
if (!secureOptions.dangerouslyRunInProduction) {
|
|
454
|
-
isSecure = false;
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
} catch (err) {
|
|
459
|
-
secureOptions.onError?.(err);
|
|
460
|
-
}
|
|
461
|
-
if (!isSecure) {
|
|
462
|
-
options.onCommitFiberRoot = void 0;
|
|
463
|
-
options.onCommitFiberUnmount = void 0;
|
|
464
|
-
options.onPostCommitFiberRoot = void 0;
|
|
465
|
-
options.onActive = void 0;
|
|
466
|
-
return;
|
|
467
|
-
}
|
|
468
|
-
try {
|
|
469
|
-
const onCommitFiberRoot = options.onCommitFiberRoot;
|
|
470
|
-
if (onCommitFiberRoot) {
|
|
471
|
-
options.onCommitFiberRoot = (rendererID, root, priority) => {
|
|
472
|
-
try {
|
|
473
|
-
onCommitFiberRoot(rendererID, root, priority);
|
|
474
|
-
} catch (err) {
|
|
475
|
-
secureOptions.onError?.(err);
|
|
476
|
-
}
|
|
477
|
-
};
|
|
478
|
-
}
|
|
479
|
-
const onCommitFiberUnmount = options.onCommitFiberUnmount;
|
|
480
|
-
if (onCommitFiberUnmount) {
|
|
481
|
-
options.onCommitFiberUnmount = (rendererID, root) => {
|
|
482
|
-
try {
|
|
483
|
-
onCommitFiberUnmount(rendererID, root);
|
|
484
|
-
} catch (err) {
|
|
485
|
-
secureOptions.onError?.(err);
|
|
486
|
-
}
|
|
487
|
-
};
|
|
488
|
-
}
|
|
489
|
-
const onPostCommitFiberRoot = options.onPostCommitFiberRoot;
|
|
490
|
-
if (onPostCommitFiberRoot) {
|
|
491
|
-
options.onPostCommitFiberRoot = (rendererID, root) => {
|
|
492
|
-
try {
|
|
493
|
-
onPostCommitFiberRoot(rendererID, root);
|
|
494
|
-
} catch (err) {
|
|
495
|
-
secureOptions.onError?.(err);
|
|
496
|
-
}
|
|
497
|
-
};
|
|
498
|
-
}
|
|
499
|
-
} catch (err) {
|
|
500
|
-
secureOptions.onError?.(err);
|
|
501
|
-
}
|
|
502
|
-
};
|
|
503
|
-
if (!isRDTHookInstalled && !isRDT) {
|
|
504
|
-
timeout = setTimeout(() => {
|
|
505
|
-
if (!isProduction) {
|
|
506
|
-
secureOptions.onError?.();
|
|
507
|
-
}
|
|
508
|
-
stop();
|
|
509
|
-
}, secureOptions.installCheckTimeout ?? 100);
|
|
510
|
-
}
|
|
511
|
-
return options;
|
|
512
|
-
};
|
|
513
|
-
|
|
514
|
-
// inline-worker:__inline-worker
|
|
515
|
-
function inlineWorker(scriptText) {
|
|
516
|
-
let blob = new Blob([scriptText], { type: "text/javascript" });
|
|
517
|
-
let url = URL.createObjectURL(blob);
|
|
518
|
-
let worker2 = new Worker(url);
|
|
519
|
-
URL.revokeObjectURL(url);
|
|
520
|
-
return worker2;
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
// src/scan/offscreen-canvas.worker.ts
|
|
524
|
-
function Worker2() {
|
|
525
|
-
return inlineWorker('var Y="Menlo,Consolas,Monaco,Liberation Mono,Lucida Console,monospace";var C=(t,l)=>Math.floor(t+(l-t)*.2);var _="115,97,230";var $=t=>{let l=new Map;for(let i of t){let{name:h,count:e}=i;l.set(h,(l.get(h)||0)+e)}let u=new Map;for(let[i,h]of l.entries()){let e=u.get(h);e?e.push(i):u.set(h,[i])}let p=Array.from(u.entries()).sort(([i],[h])=>h-i),a=p.length,r="";for(let i=0;i<a;i++){let[h,e]=p[i],n=`${e.slice(0,4).join(", ")} \\xD7${h}`;n.length>40&&(n=`${n.slice(0,40)}\\u2026`),i!==a-1&&(n+=", "),r+=n}return r.length>40?`${r.slice(0,40)}\\u2026`:r},S=t=>{let l=0;for(let u of t)l+=u.width*u.height;return l};var N=(t,l)=>{let u=t.getContext("2d",{alpha:!0});return u&&u.scale(l,l),u},X=(t,l,u,p)=>{t.clearRect(0,0,l.width/u,l.height/u);let a=new Map,r=new Map;for(let e of p.values()){let{x:n,y:c,width:s,height:f,targetX:o,targetY:d,targetWidth:g,targetHeight:m,frame:x}=e;o!==n&&(e.x=C(n,o)),d!==c&&(e.y=C(c,d)),g!==s&&(e.width=C(s,g)),m!==f&&(e.height=C(f,m));let O=`${o!=null?o:n},${d!=null?d:c}`,y=`${O},${g!=null?g:s},${m!=null?m:f}`,R=a.get(O);R?R.push(e):a.set(O,[e]);let M=1-x/45;e.frame++;let E=r.get(y)||{x:n,y:c,width:s,height:f,alpha:M};M>E.alpha&&(E.alpha=M),r.set(y,E)}for(let e of r.values()){let{x:n,y:c,width:s,height:f,alpha:o}=e;t.strokeStyle=`rgba(${_},${o})`,t.lineWidth=1,t.beginPath(),t.rect(n,c,s,f),t.stroke(),t.fillStyle=`rgba(${_},${o*.1})`,t.fill()}t.font=`11px ${Y}`;let i=new Map;t.textRendering="optimizeSpeed";for(let e of a.values()){let n=e[0],{x:c,y:s,frame:f}=n,o=1-f/45,d=$(e),{width:g}=t.measureText(d),m=11;i.set(`${c},${s},${g},${d}`,{text:d,width:g,height:m,alpha:o,x:c,y:s,outlines:e});let x=s-m-4;if(x<0&&(x=0),f>45)for(let O of e)p.delete(String(O.id))}let h=Array.from(i.entries()).sort(([e,n],[c,s])=>S(s.outlines)-S(n.outlines));for(let[e,n]of h)if(i.has(e))for(let[c,s]of i.entries()){if(e===c)continue;let{x:f,y:o,width:d,height:g}=n,{x:m,y:x,width:O,height:y}=s;f+d>m&&m+O>f&&o+g>x&&x+y>o&&(n.text=$([...n.outlines,...s.outlines]),n.width=t.measureText(n.text).width,i.delete(c))}for(let e of i.values()){let{x:n,y:c,alpha:s,width:f,height:o,text:d}=e,g=c-o-4;g<0&&(g=0),t.fillStyle=`rgba(${_},${s})`,t.fillRect(n,g,f+4,o+4),t.fillStyle=`rgba(255,255,255,${s})`,t.fillText(d,n+2,g+o)}return p.size>0};var A=null,w=null,b=1,L=new Map,T=null,v=()=>{if(!w||!A)return;X(w,A,b,L)?T=requestAnimationFrame(v):T=null};self.onmessage=t=>{let{type:l}=t.data;if(l==="init"&&(A=t.data.canvas,b=t.data.dpr,A&&(A.width=t.data.width,A.height=t.data.height,w=N(A,b))),!(!A||!w)){if(l==="resize"){b=t.data.dpr,A.width=t.data.width*b,A.height=t.data.height*b,w.resetTransform(),w.scale(b,b),v();return}if(l==="draw-outlines"){let{data:u,names:p}=t.data,a=new Float32Array(u);for(let r=0;r<a.length;r+=7){let i=a[r+2],h=a[r+3],e=a[r+4],n=a[r+5],c=a[r+6],s={id:a[r],name:p[r/7],count:a[r+1],x:i,y:h,width:e,height:n,frame:0,targetX:i,targetY:h,targetWidth:e,targetHeight:n,didCommit:c},f=String(s.id),o=L.get(f);o?(o.count++,o.frame=0,o.targetX=i,o.targetY=h,o.targetWidth=e,o.targetHeight=n,o.didCommit=c):L.set(f,s)}T||(T=requestAnimationFrame(v));return}if(l==="scroll"){let{deltaX:u,deltaY:p}=t.data;for(let a of L.values()){let r=a.x-u,i=a.y-p;a.targetX=r,a.targetY=i}}}};\n');
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
// src/scan/canvas.ts
|
|
529
|
-
var OUTLINE_ARRAY_SIZE = 7;
|
|
530
|
-
var MONO_FONT = "Menlo,Consolas,Monaco,Liberation Mono,Lucida Console,monospace";
|
|
531
|
-
var INTERPOLATION_SPEED = 0.2;
|
|
532
|
-
var lerp = (start, end) => {
|
|
533
|
-
return Math.floor(start + (end - start) * INTERPOLATION_SPEED);
|
|
534
|
-
};
|
|
535
|
-
var MAX_PARTS_LENGTH = 4;
|
|
536
|
-
var MAX_LABEL_LENGTH = 40;
|
|
537
|
-
var TOTAL_FRAMES = 45;
|
|
538
|
-
var primaryColor = "115,97,230";
|
|
539
|
-
var getLabelText = (outlines) => {
|
|
540
|
-
const nameByCount = /* @__PURE__ */ new Map();
|
|
541
|
-
for (const outline of outlines) {
|
|
542
|
-
const { name, count } = outline;
|
|
543
|
-
nameByCount.set(name, (nameByCount.get(name) || 0) + count);
|
|
544
|
-
}
|
|
545
|
-
const countByNames = /* @__PURE__ */ new Map();
|
|
546
|
-
for (const [name, count] of nameByCount.entries()) {
|
|
547
|
-
const names = countByNames.get(count);
|
|
548
|
-
if (names) {
|
|
549
|
-
names.push(name);
|
|
550
|
-
} else {
|
|
551
|
-
countByNames.set(count, [name]);
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
const partsEntries = Array.from(countByNames.entries()).sort(
|
|
555
|
-
([countA], [countB]) => countB - countA
|
|
556
|
-
);
|
|
557
|
-
const partsLength = partsEntries.length;
|
|
558
|
-
let labelText = "";
|
|
559
|
-
for (let i = 0; i < partsLength; i++) {
|
|
560
|
-
const [count, names] = partsEntries[i];
|
|
561
|
-
let part = `${names.slice(0, MAX_PARTS_LENGTH).join(", ")} \xD7${count}`;
|
|
562
|
-
if (part.length > MAX_LABEL_LENGTH) {
|
|
563
|
-
part = `${part.slice(0, MAX_LABEL_LENGTH)}\u2026`;
|
|
564
|
-
}
|
|
565
|
-
if (i !== partsLength - 1) {
|
|
566
|
-
part += ", ";
|
|
567
|
-
}
|
|
568
|
-
labelText += part;
|
|
569
|
-
}
|
|
570
|
-
if (labelText.length > MAX_LABEL_LENGTH) {
|
|
571
|
-
return `${labelText.slice(0, MAX_LABEL_LENGTH)}\u2026`;
|
|
572
|
-
}
|
|
573
|
-
return labelText;
|
|
574
|
-
};
|
|
575
|
-
var getAreaFromOutlines = (outlines) => {
|
|
576
|
-
let area = 0;
|
|
577
|
-
for (const outline of outlines) {
|
|
578
|
-
area += outline.width * outline.height;
|
|
579
|
-
}
|
|
580
|
-
return area;
|
|
581
|
-
};
|
|
582
|
-
var updateOutlines = (activeOutlines2, outlines) => {
|
|
583
|
-
for (const { id, name, count, x, y, width, height, didCommit } of outlines) {
|
|
584
|
-
const outline = {
|
|
585
|
-
id,
|
|
586
|
-
name,
|
|
587
|
-
count,
|
|
588
|
-
x,
|
|
589
|
-
y,
|
|
590
|
-
width,
|
|
591
|
-
height,
|
|
592
|
-
frame: 0,
|
|
593
|
-
targetX: x,
|
|
594
|
-
targetY: y,
|
|
595
|
-
targetWidth: width,
|
|
596
|
-
targetHeight: height,
|
|
597
|
-
didCommit
|
|
598
|
-
};
|
|
599
|
-
const key = String(outline.id);
|
|
600
|
-
const existingOutline = activeOutlines2.get(key);
|
|
601
|
-
if (existingOutline) {
|
|
602
|
-
existingOutline.count++;
|
|
603
|
-
existingOutline.frame = 0;
|
|
604
|
-
existingOutline.targetX = x;
|
|
605
|
-
existingOutline.targetY = y;
|
|
606
|
-
existingOutline.targetWidth = width;
|
|
607
|
-
existingOutline.targetHeight = height;
|
|
608
|
-
existingOutline.didCommit = didCommit;
|
|
609
|
-
} else {
|
|
610
|
-
activeOutlines2.set(key, outline);
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
};
|
|
614
|
-
var updateScroll = (activeOutlines2, deltaX, deltaY) => {
|
|
615
|
-
for (const outline of activeOutlines2.values()) {
|
|
616
|
-
const newX = outline.x - deltaX;
|
|
617
|
-
const newY = outline.y - deltaY;
|
|
618
|
-
outline.targetX = newX;
|
|
619
|
-
outline.targetY = newY;
|
|
620
|
-
}
|
|
621
|
-
};
|
|
622
|
-
var initCanvas = (canvas2, dpr2) => {
|
|
623
|
-
const ctx2 = canvas2.getContext("2d", { alpha: true });
|
|
624
|
-
if (ctx2) {
|
|
625
|
-
ctx2.scale(dpr2, dpr2);
|
|
626
|
-
}
|
|
627
|
-
return ctx2;
|
|
628
|
-
};
|
|
629
|
-
var drawCanvas = (ctx2, canvas2, dpr2, activeOutlines2) => {
|
|
630
|
-
ctx2.clearRect(0, 0, canvas2.width / dpr2, canvas2.height / dpr2);
|
|
631
|
-
const groupedOutlinesMap = /* @__PURE__ */ new Map();
|
|
632
|
-
const rectMap = /* @__PURE__ */ new Map();
|
|
633
|
-
for (const outline of activeOutlines2.values()) {
|
|
634
|
-
const {
|
|
635
|
-
x,
|
|
636
|
-
y,
|
|
637
|
-
width,
|
|
638
|
-
height,
|
|
639
|
-
targetX,
|
|
640
|
-
targetY,
|
|
641
|
-
targetWidth,
|
|
642
|
-
targetHeight,
|
|
643
|
-
frame
|
|
644
|
-
} = outline;
|
|
645
|
-
if (targetX !== x) {
|
|
646
|
-
outline.x = lerp(x, targetX);
|
|
647
|
-
}
|
|
648
|
-
if (targetY !== y) {
|
|
649
|
-
outline.y = lerp(y, targetY);
|
|
650
|
-
}
|
|
651
|
-
if (targetWidth !== width) {
|
|
652
|
-
outline.width = lerp(width, targetWidth);
|
|
653
|
-
}
|
|
654
|
-
if (targetHeight !== height) {
|
|
655
|
-
outline.height = lerp(height, targetHeight);
|
|
656
|
-
}
|
|
657
|
-
const labelKey = `${targetX ?? x},${targetY ?? y}`;
|
|
658
|
-
const rectKey = `${labelKey},${targetWidth ?? width},${targetHeight ?? height}`;
|
|
659
|
-
const outlines = groupedOutlinesMap.get(labelKey);
|
|
660
|
-
if (outlines) {
|
|
661
|
-
outlines.push(outline);
|
|
662
|
-
} else {
|
|
663
|
-
groupedOutlinesMap.set(labelKey, [outline]);
|
|
664
|
-
}
|
|
665
|
-
const alpha = 1 - frame / TOTAL_FRAMES;
|
|
666
|
-
outline.frame++;
|
|
667
|
-
const rect = rectMap.get(rectKey) || {
|
|
668
|
-
x,
|
|
669
|
-
y,
|
|
670
|
-
width,
|
|
671
|
-
height,
|
|
672
|
-
alpha
|
|
673
|
-
};
|
|
674
|
-
if (alpha > rect.alpha) {
|
|
675
|
-
rect.alpha = alpha;
|
|
676
|
-
}
|
|
677
|
-
rectMap.set(rectKey, rect);
|
|
678
|
-
}
|
|
679
|
-
for (const rect of rectMap.values()) {
|
|
680
|
-
const { x, y, width, height, alpha } = rect;
|
|
681
|
-
ctx2.strokeStyle = `rgba(${primaryColor},${alpha})`;
|
|
682
|
-
ctx2.lineWidth = 1;
|
|
683
|
-
ctx2.beginPath();
|
|
684
|
-
ctx2.rect(x, y, width, height);
|
|
685
|
-
ctx2.stroke();
|
|
686
|
-
ctx2.fillStyle = `rgba(${primaryColor},${alpha * 0.1})`;
|
|
687
|
-
ctx2.fill();
|
|
688
|
-
}
|
|
689
|
-
ctx2.font = `11px ${MONO_FONT}`;
|
|
690
|
-
const labelMap = /* @__PURE__ */ new Map();
|
|
691
|
-
ctx2.textRendering = "optimizeSpeed";
|
|
692
|
-
for (const outlines of groupedOutlinesMap.values()) {
|
|
693
|
-
const first = outlines[0];
|
|
694
|
-
const { x, y, frame } = first;
|
|
695
|
-
const alpha = 1 - frame / TOTAL_FRAMES;
|
|
696
|
-
const text = getLabelText(outlines);
|
|
697
|
-
const { width } = ctx2.measureText(text);
|
|
698
|
-
const height = 11;
|
|
699
|
-
labelMap.set(`${x},${y},${width},${text}`, {
|
|
700
|
-
text,
|
|
701
|
-
width,
|
|
702
|
-
height,
|
|
703
|
-
alpha,
|
|
704
|
-
x,
|
|
705
|
-
y,
|
|
706
|
-
outlines
|
|
707
|
-
});
|
|
708
|
-
if (frame > TOTAL_FRAMES) {
|
|
709
|
-
for (const outline of outlines) {
|
|
710
|
-
activeOutlines2.delete(String(outline.id));
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
const sortedLabels = Array.from(labelMap.entries()).sort(
|
|
715
|
-
([_, a], [__, b]) => {
|
|
716
|
-
return getAreaFromOutlines(b.outlines) - getAreaFromOutlines(a.outlines);
|
|
717
|
-
}
|
|
718
|
-
);
|
|
719
|
-
for (const [labelKey, label] of sortedLabels) {
|
|
720
|
-
if (!labelMap.has(labelKey)) continue;
|
|
721
|
-
for (const [otherKey, otherLabel] of labelMap.entries()) {
|
|
722
|
-
if (labelKey === otherKey) continue;
|
|
723
|
-
const { x, y, width, height } = label;
|
|
724
|
-
const {
|
|
725
|
-
x: otherX,
|
|
726
|
-
y: otherY,
|
|
727
|
-
width: otherWidth,
|
|
728
|
-
height: otherHeight
|
|
729
|
-
} = otherLabel;
|
|
730
|
-
if (x + width > otherX && otherX + otherWidth > x && y + height > otherY && otherY + otherHeight > y) {
|
|
731
|
-
label.text = getLabelText([...label.outlines, ...otherLabel.outlines]);
|
|
732
|
-
label.width = ctx2.measureText(label.text).width;
|
|
733
|
-
labelMap.delete(otherKey);
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
for (const label of labelMap.values()) {
|
|
738
|
-
const { x, y, alpha, width, height, text } = label;
|
|
739
|
-
let labelY = y - height - 4;
|
|
740
|
-
if (labelY < 0) {
|
|
741
|
-
labelY = 0;
|
|
742
|
-
}
|
|
743
|
-
ctx2.fillStyle = `rgba(${primaryColor},${alpha})`;
|
|
744
|
-
ctx2.fillRect(x, labelY, width + 4, height + 4);
|
|
745
|
-
ctx2.fillStyle = `rgba(255,255,255,${alpha})`;
|
|
746
|
-
ctx2.fillText(text, x + 2, labelY + height);
|
|
747
|
-
}
|
|
748
|
-
return activeOutlines2.size > 0;
|
|
749
|
-
};
|
|
750
|
-
|
|
751
|
-
// src/scan/index.ts
|
|
752
|
-
var worker = null;
|
|
753
|
-
var canvas = null;
|
|
754
|
-
var ctx = null;
|
|
755
|
-
var dpr = 1;
|
|
756
|
-
var animationFrameId = null;
|
|
757
|
-
var activeOutlines = /* @__PURE__ */ new Map();
|
|
758
|
-
var blueprintMap = /* @__PURE__ */ new WeakMap();
|
|
759
|
-
var blueprintMapKeys = /* @__PURE__ */ new Set();
|
|
760
|
-
var outlineFiber = (fiber) => {
|
|
761
|
-
if (!isCompositeFiber(fiber)) return;
|
|
762
|
-
const name = typeof fiber.type === "string" ? fiber.type : getDisplayName(fiber);
|
|
763
|
-
if (!name) return;
|
|
764
|
-
const blueprint = blueprintMap.get(fiber);
|
|
765
|
-
const nearestFibers = getNearestHostFibers(fiber);
|
|
766
|
-
const didCommit = didFiberCommit(fiber);
|
|
767
|
-
if (!blueprint) {
|
|
768
|
-
blueprintMap.set(fiber, {
|
|
769
|
-
name,
|
|
770
|
-
count: 1,
|
|
771
|
-
elements: nearestFibers.map((fiber2) => fiber2.stateNode),
|
|
772
|
-
didCommit: didCommit ? 1 : 0
|
|
773
|
-
});
|
|
774
|
-
blueprintMapKeys.add(fiber);
|
|
775
|
-
} else {
|
|
776
|
-
blueprint.count++;
|
|
777
|
-
}
|
|
778
|
-
};
|
|
779
|
-
var mergeRects = (rects) => {
|
|
780
|
-
const firstRect = rects[0];
|
|
781
|
-
if (rects.length === 1) return firstRect;
|
|
782
|
-
let minX;
|
|
783
|
-
let minY;
|
|
784
|
-
let maxX;
|
|
785
|
-
let maxY;
|
|
786
|
-
for (let i = 0, len = rects.length; i < len; i++) {
|
|
787
|
-
const rect = rects[i];
|
|
788
|
-
minX = minX == null ? rect.x : Math.min(minX, rect.x);
|
|
789
|
-
minY = minY == null ? rect.y : Math.min(minY, rect.y);
|
|
790
|
-
maxX = maxX == null ? rect.x + rect.width : Math.max(maxX, rect.x + rect.width);
|
|
791
|
-
maxY = maxY == null ? rect.y + rect.height : Math.max(maxY, rect.y + rect.height);
|
|
792
|
-
}
|
|
793
|
-
if (minX == null || minY == null || maxX == null || maxY == null) {
|
|
794
|
-
return rects[0];
|
|
795
|
-
}
|
|
796
|
-
return new DOMRect(minX, minY, maxX - minX, maxY - minY);
|
|
797
|
-
};
|
|
798
|
-
var getRectMap = (elements) => {
|
|
799
|
-
return new Promise((resolve) => {
|
|
800
|
-
const rects = /* @__PURE__ */ new Map();
|
|
801
|
-
const observer = new IntersectionObserver((entries) => {
|
|
802
|
-
for (let i = 0, len = entries.length; i < len; i++) {
|
|
803
|
-
const entry = entries[i];
|
|
804
|
-
const element = entry.target;
|
|
805
|
-
const rect = entry.boundingClientRect;
|
|
806
|
-
if (entry.isIntersecting && rect.width && rect.height) {
|
|
807
|
-
rects.set(element, rect);
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
observer.disconnect();
|
|
811
|
-
resolve(rects);
|
|
812
|
-
});
|
|
813
|
-
for (let i = 0, len = elements.length; i < len; i++) {
|
|
814
|
-
const element = elements[i];
|
|
815
|
-
observer.observe(element);
|
|
816
|
-
}
|
|
817
|
-
});
|
|
818
|
-
};
|
|
819
|
-
var SupportedArrayBuffer = typeof SharedArrayBuffer !== "undefined" ? SharedArrayBuffer : ArrayBuffer;
|
|
820
|
-
var flushOutlines = async () => {
|
|
821
|
-
const elements = [];
|
|
822
|
-
for (const fiber of blueprintMapKeys) {
|
|
823
|
-
const blueprint = blueprintMap.get(fiber);
|
|
824
|
-
if (!blueprint) continue;
|
|
825
|
-
for (let i = 0; i < blueprint.elements.length; i++) {
|
|
826
|
-
elements.push(blueprint.elements[i]);
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
const rectsMap = await getRectMap(elements);
|
|
830
|
-
const blueprints = [];
|
|
831
|
-
const blueprintRects = [];
|
|
832
|
-
const blueprintIds = [];
|
|
833
|
-
for (const fiber of blueprintMapKeys) {
|
|
834
|
-
const blueprint = blueprintMap.get(fiber);
|
|
835
|
-
if (!blueprint) continue;
|
|
836
|
-
const rects = [];
|
|
837
|
-
for (let i = 0; i < blueprint.elements.length; i++) {
|
|
838
|
-
const element = blueprint.elements[i];
|
|
839
|
-
const rect = rectsMap.get(element);
|
|
840
|
-
if (!rect) continue;
|
|
841
|
-
rects.push(rect);
|
|
842
|
-
}
|
|
843
|
-
blueprintMap.delete(fiber);
|
|
844
|
-
blueprintMapKeys.delete(fiber);
|
|
845
|
-
if (!rects.length) continue;
|
|
846
|
-
blueprints.push(blueprint);
|
|
847
|
-
blueprintRects.push(mergeRects(rects));
|
|
848
|
-
blueprintIds.push(getFiberId(fiber));
|
|
849
|
-
}
|
|
850
|
-
const arrayBuffer = new SupportedArrayBuffer(
|
|
851
|
-
blueprints.length * OUTLINE_ARRAY_SIZE * 4
|
|
852
|
-
);
|
|
853
|
-
const sharedView = new Float32Array(arrayBuffer);
|
|
854
|
-
const blueprintNames = new Array(blueprints.length);
|
|
855
|
-
let outlineData;
|
|
856
|
-
for (let i = 0, len = blueprints.length; i < len; i++) {
|
|
857
|
-
const blueprint = blueprints[i];
|
|
858
|
-
const id = blueprintIds[i];
|
|
859
|
-
const { x, y, width, height } = blueprintRects[i];
|
|
860
|
-
const { count, name, didCommit } = blueprint;
|
|
861
|
-
if (worker) {
|
|
862
|
-
const scaledIndex = i * OUTLINE_ARRAY_SIZE;
|
|
863
|
-
sharedView[scaledIndex] = id;
|
|
864
|
-
sharedView[scaledIndex + 1] = count;
|
|
865
|
-
sharedView[scaledIndex + 2] = x;
|
|
866
|
-
sharedView[scaledIndex + 3] = y;
|
|
867
|
-
sharedView[scaledIndex + 4] = width;
|
|
868
|
-
sharedView[scaledIndex + 5] = height;
|
|
869
|
-
sharedView[scaledIndex + 6] = didCommit;
|
|
870
|
-
blueprintNames[i] = name;
|
|
871
|
-
} else {
|
|
872
|
-
outlineData ||= new Array(blueprints.length);
|
|
873
|
-
outlineData[i] = {
|
|
874
|
-
id,
|
|
875
|
-
name,
|
|
876
|
-
count,
|
|
877
|
-
x,
|
|
878
|
-
y,
|
|
879
|
-
width,
|
|
880
|
-
height,
|
|
881
|
-
didCommit
|
|
882
|
-
};
|
|
883
|
-
}
|
|
884
|
-
}
|
|
885
|
-
if (worker) {
|
|
886
|
-
worker.postMessage({
|
|
887
|
-
type: "draw-outlines",
|
|
888
|
-
data: arrayBuffer,
|
|
889
|
-
names: blueprintNames
|
|
890
|
-
});
|
|
891
|
-
} else if (canvas && ctx && outlineData) {
|
|
892
|
-
updateOutlines(activeOutlines, outlineData);
|
|
893
|
-
if (!animationFrameId) {
|
|
894
|
-
animationFrameId = requestAnimationFrame(draw);
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
};
|
|
898
|
-
var draw = () => {
|
|
899
|
-
if (!ctx || !canvas) return;
|
|
900
|
-
const shouldContinue = drawCanvas(ctx, canvas, dpr, activeOutlines);
|
|
901
|
-
if (shouldContinue) {
|
|
902
|
-
animationFrameId = requestAnimationFrame(draw);
|
|
903
|
-
} else {
|
|
904
|
-
animationFrameId = null;
|
|
905
|
-
}
|
|
906
|
-
};
|
|
907
|
-
var CANVAS_HTML_STR = `<canvas style="position:fixed;top:0;left:0;pointer-events:none;z-index:2147483646" aria-hidden="true"></canvas>`;
|
|
908
|
-
var IS_OFFSCREEN_CANVAS_WORKER_SUPPORTED = typeof OffscreenCanvas !== "undefined" && typeof Worker2 !== "undefined";
|
|
909
|
-
var getDpr = () => {
|
|
910
|
-
return Math.min(window.devicePixelRatio || 1, 2);
|
|
911
|
-
};
|
|
912
|
-
var getCanvasEl = () => {
|
|
913
|
-
const host = document.createElement("div");
|
|
914
|
-
host.setAttribute("data-react-scan", "true");
|
|
915
|
-
const shadowRoot = host.attachShadow({ mode: "open" });
|
|
916
|
-
shadowRoot.innerHTML = CANVAS_HTML_STR;
|
|
917
|
-
const canvasEl = shadowRoot.firstChild;
|
|
918
|
-
if (!canvasEl) return null;
|
|
919
|
-
dpr = getDpr();
|
|
920
|
-
canvas = canvasEl;
|
|
921
|
-
const { innerWidth, innerHeight } = window;
|
|
922
|
-
canvasEl.style.width = `${innerWidth}px`;
|
|
923
|
-
canvasEl.style.height = `${innerHeight}px`;
|
|
924
|
-
const width = innerWidth * dpr;
|
|
925
|
-
const height = innerHeight * dpr;
|
|
926
|
-
canvasEl.width = width;
|
|
927
|
-
canvasEl.height = height;
|
|
928
|
-
if (IS_OFFSCREEN_CANVAS_WORKER_SUPPORTED) {
|
|
929
|
-
try {
|
|
930
|
-
worker = Worker2();
|
|
931
|
-
const offscreenCanvas = canvasEl.transferControlToOffscreen();
|
|
932
|
-
worker.postMessage(
|
|
933
|
-
{
|
|
934
|
-
type: "init",
|
|
935
|
-
canvas: offscreenCanvas,
|
|
936
|
-
width: canvasEl.width,
|
|
937
|
-
height: canvasEl.height,
|
|
938
|
-
dpr
|
|
939
|
-
},
|
|
940
|
-
[offscreenCanvas]
|
|
941
|
-
);
|
|
942
|
-
} catch {
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
if (!worker) {
|
|
946
|
-
ctx = initCanvas(canvasEl, dpr);
|
|
947
|
-
}
|
|
948
|
-
let isResizeScheduled = false;
|
|
949
|
-
window.addEventListener("resize", () => {
|
|
950
|
-
if (!isResizeScheduled) {
|
|
951
|
-
isResizeScheduled = true;
|
|
952
|
-
setTimeout(() => {
|
|
953
|
-
const width2 = window.innerWidth;
|
|
954
|
-
const height2 = window.innerHeight;
|
|
955
|
-
dpr = getDpr();
|
|
956
|
-
canvasEl.style.width = `${width2}px`;
|
|
957
|
-
canvasEl.style.height = `${height2}px`;
|
|
958
|
-
if (worker) {
|
|
959
|
-
worker.postMessage({
|
|
960
|
-
type: "resize",
|
|
961
|
-
width: width2,
|
|
962
|
-
height: height2,
|
|
963
|
-
dpr
|
|
964
|
-
});
|
|
965
|
-
} else {
|
|
966
|
-
canvasEl.width = width2 * dpr;
|
|
967
|
-
canvasEl.height = height2 * dpr;
|
|
968
|
-
if (ctx) {
|
|
969
|
-
ctx.resetTransform();
|
|
970
|
-
ctx.scale(dpr, dpr);
|
|
971
|
-
}
|
|
972
|
-
draw();
|
|
973
|
-
}
|
|
974
|
-
isResizeScheduled = false;
|
|
975
|
-
});
|
|
976
|
-
}
|
|
977
|
-
});
|
|
978
|
-
let prevScrollX = window.scrollX;
|
|
979
|
-
let prevScrollY = window.scrollY;
|
|
980
|
-
let isScrollScheduled = false;
|
|
981
|
-
window.addEventListener("scroll", () => {
|
|
982
|
-
if (!isScrollScheduled) {
|
|
983
|
-
isScrollScheduled = true;
|
|
984
|
-
setTimeout(() => {
|
|
985
|
-
const { scrollX, scrollY } = window;
|
|
986
|
-
const deltaX = scrollX - prevScrollX;
|
|
987
|
-
const deltaY = scrollY - prevScrollY;
|
|
988
|
-
prevScrollX = scrollX;
|
|
989
|
-
prevScrollY = scrollY;
|
|
990
|
-
if (worker) {
|
|
991
|
-
worker.postMessage({
|
|
992
|
-
type: "scroll",
|
|
993
|
-
deltaX,
|
|
994
|
-
deltaY
|
|
995
|
-
});
|
|
996
|
-
} else {
|
|
997
|
-
requestAnimationFrame(() => {
|
|
998
|
-
updateScroll(activeOutlines, deltaX, deltaY);
|
|
999
|
-
});
|
|
1000
|
-
}
|
|
1001
|
-
isScrollScheduled = false;
|
|
1002
|
-
}, 16 * 2);
|
|
1003
|
-
}
|
|
1004
|
-
});
|
|
1005
|
-
setInterval(() => {
|
|
1006
|
-
if (blueprintMapKeys.size) {
|
|
1007
|
-
flushOutlines();
|
|
1008
|
-
}
|
|
1009
|
-
}, 16 * 2);
|
|
1010
|
-
shadowRoot.appendChild(canvasEl);
|
|
1011
|
-
return host;
|
|
1012
|
-
};
|
|
1013
|
-
var hasStopped = () => {
|
|
1014
|
-
return globalThis.__REACT_SCAN_STOP__;
|
|
1015
|
-
};
|
|
1016
|
-
var stop2 = () => {
|
|
1017
|
-
globalThis.__REACT_SCAN_STOP__ = true;
|
|
1018
|
-
cleanup();
|
|
1019
|
-
};
|
|
1020
|
-
var hasCleanedUp = false;
|
|
1021
|
-
var cleanup = () => {
|
|
1022
|
-
if (hasCleanedUp) return;
|
|
1023
|
-
hasCleanedUp = true;
|
|
1024
|
-
const host = document.querySelector("[data-react-scan]");
|
|
1025
|
-
if (host) {
|
|
1026
|
-
host.remove();
|
|
1027
|
-
}
|
|
1028
|
-
};
|
|
1029
|
-
var init = () => {
|
|
1030
|
-
cleanup();
|
|
1031
|
-
if (hasStopped()) return;
|
|
1032
|
-
const visit = createFiberVisitor({
|
|
1033
|
-
onRender(fiber) {
|
|
1034
|
-
if (document.hidden) return;
|
|
1035
|
-
outlineFiber(fiber);
|
|
1036
|
-
},
|
|
1037
|
-
onError() {
|
|
1038
|
-
}
|
|
1039
|
-
});
|
|
1040
|
-
instrument(
|
|
1041
|
-
secure(
|
|
1042
|
-
{
|
|
1043
|
-
onActive() {
|
|
1044
|
-
if (hasStopped()) return;
|
|
1045
|
-
const host = getCanvasEl();
|
|
1046
|
-
if (host) {
|
|
1047
|
-
document.documentElement.appendChild(host);
|
|
1048
|
-
}
|
|
1049
|
-
},
|
|
1050
|
-
onCommitFiberRoot(rendererID, root) {
|
|
1051
|
-
if (hasStopped()) return cleanup();
|
|
1052
|
-
visit(rendererID, root);
|
|
1053
|
-
}
|
|
1054
|
-
},
|
|
1055
|
-
{
|
|
1056
|
-
dangerouslyRunInProduction: true,
|
|
1057
|
-
onError(error) {
|
|
1058
|
-
console.warn(
|
|
1059
|
-
"React Scan did not install correctly.\n\n{link to install doc}",
|
|
1060
|
-
error
|
|
1061
|
-
);
|
|
1062
|
-
}
|
|
1063
|
-
}
|
|
1064
|
-
)
|
|
1065
|
-
);
|
|
1066
|
-
};
|
|
1067
|
-
if (typeof window !== "undefined") {
|
|
1068
|
-
init();
|
|
1069
|
-
}
|
|
1070
|
-
|
|
1071
|
-
export { cleanup, flushOutlines, getCanvasEl, getRectMap, hasStopped, outlineFiber, stop2 as stop };
|