@lark-apaas/miaoda-inspector 0.1.0-alpha.1

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 (74) hide show
  1. package/LICENSE +13 -0
  2. package/README.md +1 -0
  3. package/dist/es/Inspector/Inspector.js +179 -0
  4. package/dist/es/Inspector/Overlay.js +400 -0
  5. package/dist/es/Inspector/hooks/index.js +3 -0
  6. package/dist/es/Inspector/hooks/use-effect-event.js +15 -0
  7. package/dist/es/Inspector/hooks/use-layout-effect.js +3 -0
  8. package/dist/es/Inspector/hooks/use-mouse.js +22 -0
  9. package/dist/es/Inspector/index.js +1 -0
  10. package/dist/es/Inspector/utils/fiber.js +61 -0
  11. package/dist/es/Inspector/utils/highlight.js +74 -0
  12. package/dist/es/Inspector/utils/index.js +3 -0
  13. package/dist/es/Inspector/utils/inspect.js +119 -0
  14. package/dist/es/Inspector/utils/overlay.js +20 -0
  15. package/dist/es/MiaodaInspector/MiaodaInspector.css +46 -0
  16. package/dist/es/MiaodaInspector/MiaodaInspector.js +397 -0
  17. package/dist/es/MiaodaInspector/index.js +1 -0
  18. package/dist/es/config/ui-config.js +787 -0
  19. package/dist/es/index.js +2 -0
  20. package/dist/es/types/iframe-events.js +1 -0
  21. package/dist/es/types/index.js +1 -0
  22. package/dist/es/utils/config-mapper.js +163 -0
  23. package/dist/es/utils/css.js +5 -0
  24. package/dist/es/utils/index.js +3 -0
  25. package/dist/es/utils/origin.js +19 -0
  26. package/dist/es/utils/style-calculator.js +158 -0
  27. package/dist/lib/Inspector/Inspector.js +203 -0
  28. package/dist/lib/Inspector/Overlay.js +419 -0
  29. package/dist/lib/Inspector/hooks/index.js +20 -0
  30. package/dist/lib/Inspector/hooks/use-effect-event.js +25 -0
  31. package/dist/lib/Inspector/hooks/use-layout-effect.js +13 -0
  32. package/dist/lib/Inspector/hooks/use-mouse.js +32 -0
  33. package/dist/lib/Inspector/index.js +11 -0
  34. package/dist/lib/Inspector/utils/fiber.js +95 -0
  35. package/dist/lib/Inspector/utils/highlight.js +84 -0
  36. package/dist/lib/Inspector/utils/index.js +20 -0
  37. package/dist/lib/Inspector/utils/inspect.js +153 -0
  38. package/dist/lib/Inspector/utils/overlay.js +39 -0
  39. package/dist/lib/MiaodaInspector/MiaodaInspector.css +46 -0
  40. package/dist/lib/MiaodaInspector/MiaodaInspector.js +447 -0
  41. package/dist/lib/MiaodaInspector/index.js +11 -0
  42. package/dist/lib/config/ui-config.js +797 -0
  43. package/dist/lib/index.js +21 -0
  44. package/dist/lib/types/iframe-events.js +4 -0
  45. package/dist/lib/types/index.js +47 -0
  46. package/dist/lib/utils/config-mapper.js +182 -0
  47. package/dist/lib/utils/css.js +20 -0
  48. package/dist/lib/utils/index.js +61 -0
  49. package/dist/lib/utils/origin.js +44 -0
  50. package/dist/lib/utils/style-calculator.js +207 -0
  51. package/dist/types/Inspector/Inspector.d.ts +102 -0
  52. package/dist/types/Inspector/Overlay.d.ts +71 -0
  53. package/dist/types/Inspector/hooks/index.d.ts +3 -0
  54. package/dist/types/Inspector/hooks/use-effect-event.d.ts +9 -0
  55. package/dist/types/Inspector/hooks/use-layout-effect.d.ts +2 -0
  56. package/dist/types/Inspector/hooks/use-mouse.d.ts +9 -0
  57. package/dist/types/Inspector/index.d.ts +1 -0
  58. package/dist/types/Inspector/utils/fiber.d.ts +34 -0
  59. package/dist/types/Inspector/utils/highlight.d.ts +8 -0
  60. package/dist/types/Inspector/utils/index.d.ts +3 -0
  61. package/dist/types/Inspector/utils/inspect.d.ts +110 -0
  62. package/dist/types/Inspector/utils/overlay.d.ts +30 -0
  63. package/dist/types/MiaodaInspector/MiaodaInspector.d.ts +47 -0
  64. package/dist/types/MiaodaInspector/index.d.ts +1 -0
  65. package/dist/types/config/ui-config.d.ts +49 -0
  66. package/dist/types/index.d.ts +4 -0
  67. package/dist/types/types/iframe-events.d.ts +155 -0
  68. package/dist/types/types/index.d.ts +1 -0
  69. package/dist/types/utils/config-mapper.d.ts +12 -0
  70. package/dist/types/utils/css.d.ts +2 -0
  71. package/dist/types/utils/index.d.ts +3 -0
  72. package/dist/types/utils/origin.d.ts +9 -0
  73. package/dist/types/utils/style-calculator.d.ts +19 -0
  74. package/package.json +48 -0
@@ -0,0 +1,419 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for (var name in all)
7
+ Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
10
+ });
11
+ }
12
+ _export(exports, {
13
+ Overlay: function() {
14
+ return Overlay;
15
+ },
16
+ ClickOverlay: function() {
17
+ return ClickOverlay;
18
+ }
19
+ });
20
+ const _utils = require("./utils");
21
+ const overlayStyles = {
22
+ padding: "transparent",
23
+ margin: "transparent",
24
+ border: "transparent"
25
+ };
26
+ function boxWrap(dims, what, node) {
27
+ Object.assign(node.style, {
28
+ borderTopWidth: `${dims[`${what}Top`]}px`,
29
+ borderLeftWidth: `${dims[`${what}Left`]}px`,
30
+ borderRightWidth: `${dims[`${what}Right`]}px`,
31
+ borderBottomWidth: `${dims[`${what}Bottom`]}px`,
32
+ borderStyle: "solid"
33
+ });
34
+ }
35
+ function findTipPos(dims, bounds, tipSize) {
36
+ const tipHeight = Math.max(tipSize.height, 20);
37
+ const tipWidth = Math.max(tipSize.width, 60);
38
+ const margin = 4;
39
+ let top;
40
+ if (dims.top - tipHeight - margin >= bounds.top) {
41
+ top = dims.top - tipHeight - margin;
42
+ } else if (dims.top + dims.height + tipHeight <= bounds.top + bounds.height) {
43
+ if (dims.top + dims.height < bounds.top + 0) {
44
+ top = bounds.top + margin;
45
+ } else {
46
+ top = dims.top + dims.height + margin;
47
+ }
48
+ } else if (dims.top - tipHeight <= bounds.top + bounds.height) {
49
+ if (dims.top - tipHeight - margin < bounds.top + margin) {
50
+ top = bounds.top + margin;
51
+ } else {
52
+ top = dims.top - tipHeight - margin;
53
+ }
54
+ } else {
55
+ top = bounds.top + bounds.height - tipHeight - margin;
56
+ }
57
+ let { left } = dims;
58
+ if (dims.left < bounds.left) {
59
+ left = bounds.left;
60
+ }
61
+ if (dims.left + tipWidth > bounds.left + bounds.width) {
62
+ left = bounds.left + bounds.width - tipWidth;
63
+ }
64
+ return {
65
+ style: {
66
+ top: `${top}px`,
67
+ // 目前 box 的样式是设置的 outline,为了对齐要向左偏移 1px
68
+ left: `${left - 1}px`
69
+ }
70
+ };
71
+ }
72
+ class OverlayRect {
73
+ remove() {
74
+ if (this.node.parentNode) {
75
+ this.node.parentNode.removeChild(this.node);
76
+ }
77
+ }
78
+ update(box, dims) {
79
+ boxWrap(dims, "margin", this.node);
80
+ boxWrap(dims, "border", this.border);
81
+ boxWrap(dims, "padding", this.padding);
82
+ Object.assign(this.content.style, {
83
+ height: `${box.height - dims.borderTop - dims.borderBottom - dims.paddingTop - dims.paddingBottom}px`,
84
+ width: `${box.width - dims.borderLeft - dims.borderRight - dims.paddingLeft - dims.paddingRight}px`
85
+ });
86
+ Object.assign(this.node.style, {
87
+ top: `${box.top - dims.marginTop}px`,
88
+ left: `${box.left - dims.marginLeft}px`
89
+ });
90
+ }
91
+ constructor(doc, container) {
92
+ this.node = doc.createElement("div");
93
+ this.border = doc.createElement("div");
94
+ this.padding = doc.createElement("div");
95
+ this.content = doc.createElement("div");
96
+ this.border.style.borderColor = overlayStyles.border;
97
+ this.padding.style.borderColor = overlayStyles.padding;
98
+ Object.assign(this.node.style, {
99
+ borderColor: overlayStyles.margin,
100
+ pointerEvents: "none",
101
+ position: "fixed",
102
+ outline: "1px dashed #1456f0"
103
+ });
104
+ this.node.style.zIndex = "10000000";
105
+ this.node.appendChild(this.border);
106
+ this.border.appendChild(this.padding);
107
+ this.padding.appendChild(this.content);
108
+ container.prepend(this.node);
109
+ }
110
+ }
111
+ class ClickOverlayRect {
112
+ remove() {
113
+ if (this.node.parentNode) {
114
+ this.node.parentNode.removeChild(this.node);
115
+ }
116
+ }
117
+ update(box, dims) {
118
+ Object.assign(this.node.style, {
119
+ top: `${box.top - 1 - dims.marginTop}px`,
120
+ left: `${box.left - 1 - dims.marginLeft}px`,
121
+ width: `${box.width + dims.marginLeft + dims.marginRight + 2}px`,
122
+ height: `${box.height + dims.marginTop + dims.marginBottom + 2}px`
123
+ });
124
+ }
125
+ constructor(doc, container) {
126
+ this.node = doc.createElement("div");
127
+ this.border = doc.createElement("div");
128
+ Object.assign(this.border.style, {
129
+ pointerEvents: "none",
130
+ position: "absolute",
131
+ top: "0",
132
+ left: "0",
133
+ width: "100%",
134
+ height: "100%",
135
+ boxSizing: "border-box",
136
+ border: "1px solid #1456f0"
137
+ });
138
+ Object.assign(this.node.style, {
139
+ pointerEvents: "none",
140
+ position: "fixed",
141
+ zIndex: "9999999"
142
+ });
143
+ this.node.appendChild(this.border);
144
+ container.appendChild(this.node);
145
+ }
146
+ }
147
+ class OverlayTip {
148
+ remove() {
149
+ if (this.tip.parentNode) {
150
+ this.tip.parentNode.removeChild(this.tip);
151
+ }
152
+ }
153
+ updateText(name) {
154
+ this.titleDiv.textContent = name;
155
+ }
156
+ updatePosition(dims, bounds) {
157
+ const tipRect = this.tip.getBoundingClientRect();
158
+ const tipPos = findTipPos(dims, bounds, {
159
+ width: tipRect.width,
160
+ height: tipRect.height
161
+ });
162
+ Object.assign(this.tip.style, tipPos.style);
163
+ if (dims.width === 0 || dims.height === 0) {
164
+ this.invisible();
165
+ } else {
166
+ Object.assign(this.tip.style, {
167
+ display: "flex"
168
+ });
169
+ }
170
+ }
171
+ invisible() {
172
+ Object.assign(this.tip.style, {
173
+ display: "none"
174
+ });
175
+ }
176
+ constructor(doc, container) {
177
+ this.tip = doc.createElement("div");
178
+ Object.assign(this.tip.style, {
179
+ display: "flex",
180
+ flexFlow: "row nowrap",
181
+ alignItems: "center",
182
+ backgroundColor: "#1456f0",
183
+ borderRadius: "6px",
184
+ fontFamily: '"SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace',
185
+ fontWeight: "bold",
186
+ padding: "1px 12px",
187
+ pointerEvents: "none",
188
+ position: "fixed",
189
+ fontSize: "14px",
190
+ lineHeight: "22px",
191
+ whiteSpace: "nowrap"
192
+ });
193
+ this.nameSpan = doc.createElement("span");
194
+ this.tip.appendChild(this.nameSpan);
195
+ Object.assign(this.nameSpan.style, {
196
+ display: "flex",
197
+ flexDirection: "column"
198
+ });
199
+ this.titleDiv = doc.createElement("div");
200
+ this.nameSpan.appendChild(this.titleDiv);
201
+ Object.assign(this.titleDiv.style, {
202
+ color: "#fff",
203
+ fontSize: "14px",
204
+ borderRadius: "6px"
205
+ });
206
+ this.tip.style.zIndex = "10000000";
207
+ container.appendChild(this.tip);
208
+ }
209
+ }
210
+ class Overlay {
211
+ remove() {
212
+ this.tip.remove();
213
+ this.rects.forEach((rect) => {
214
+ rect.remove();
215
+ });
216
+ this.rects.length = 0;
217
+ if (this.container.parentNode) {
218
+ this.container.parentNode.removeChild(this.container);
219
+ }
220
+ this.removeCallback();
221
+ }
222
+ setRemoveCallback(callback) {
223
+ this.removeCallback = callback.bind(this);
224
+ }
225
+ inspect(nodes, name, info) {
226
+ this.resizeObserver.disconnect();
227
+ const elements = nodes.filter((node) => node.nodeType === Node.ELEMENT_NODE);
228
+ this.currentElements = nodes;
229
+ while (this.rects.length > elements.length) {
230
+ const rect = this.rects.pop();
231
+ rect === null || rect === void 0 ? void 0 : rect.remove();
232
+ }
233
+ if (elements.length === 0) {
234
+ return;
235
+ }
236
+ elements.forEach((element) => {
237
+ this.resizeObserver.observe(element);
238
+ });
239
+ this.updatePositions(elements, name, info);
240
+ }
241
+ updatePositions(nodes, name, info) {
242
+ const elements = nodes.filter((node) => node.nodeType === Node.ELEMENT_NODE);
243
+ while (this.rects.length > elements.length) {
244
+ const rect = this.rects.pop();
245
+ rect === null || rect === void 0 ? void 0 : rect.remove();
246
+ }
247
+ if (elements.length === 0) {
248
+ return;
249
+ }
250
+ while (this.rects.length < elements.length) {
251
+ this.rects.push(new OverlayRect(this.window.document, this.container));
252
+ }
253
+ const outerBox = {
254
+ top: Number.POSITIVE_INFINITY,
255
+ right: Number.NEGATIVE_INFINITY,
256
+ bottom: Number.NEGATIVE_INFINITY,
257
+ left: Number.POSITIVE_INFINITY
258
+ };
259
+ elements.forEach((element, index) => {
260
+ const box = (0, _utils.getNestedBoundingClientRect)(element, this.window);
261
+ const dims = (0, _utils.getElementDimensions)(element);
262
+ outerBox.top = Math.min(outerBox.top, box.top - dims.marginTop);
263
+ outerBox.right = Math.max(outerBox.right, box.left + box.width + dims.marginRight);
264
+ outerBox.bottom = Math.max(outerBox.bottom, box.top + box.height + dims.marginBottom);
265
+ outerBox.left = Math.min(outerBox.left, box.left - dims.marginLeft);
266
+ const rect = this.rects[index];
267
+ rect.update(box, dims);
268
+ });
269
+ if (!name) {
270
+ name = elements[0].nodeName.toLowerCase();
271
+ }
272
+ this.currentName = name;
273
+ if (this.handleCodeInfo) {
274
+ const [displayName] = this.handleCodeInfo(name || "", info);
275
+ this.tip.updateText(displayName);
276
+ } else {
277
+ this.tip.updateText(name);
278
+ }
279
+ const tipBounds = (0, _utils.getNestedBoundingClientRect)(this.tipBoundsWindow.document.documentElement, this.window);
280
+ this.tip.updatePosition({
281
+ top: outerBox.top,
282
+ left: outerBox.left,
283
+ height: outerBox.bottom - outerBox.top,
284
+ width: outerBox.right - outerBox.left
285
+ }, {
286
+ top: tipBounds.top + this.tipBoundsWindow.scrollY,
287
+ left: tipBounds.left + this.tipBoundsWindow.scrollX,
288
+ height: this.tipBoundsWindow.innerHeight,
289
+ width: this.tipBoundsWindow.innerWidth
290
+ });
291
+ }
292
+ clearRect() {
293
+ var _this_rects;
294
+ (_this_rects = this.rects) === null || _this_rects === void 0 ? void 0 : _this_rects.forEach((rect) => {
295
+ rect.remove();
296
+ });
297
+ this.rects.length = 0;
298
+ this.tip.invisible();
299
+ }
300
+ constructor(handleCodeInfo) {
301
+ this.handleCodeInfo = handleCodeInfo;
302
+ const currentWindow = window.__REACT_DEVTOOLS_TARGET_WINDOW__ || window;
303
+ this.window = currentWindow;
304
+ const tipBoundsWindow = window.__REACT_DEVTOOLS_TARGET_WINDOW__ || window;
305
+ this.tipBoundsWindow = tipBoundsWindow;
306
+ const doc = currentWindow.document;
307
+ this.container = doc.createElement("div");
308
+ this.container.style.zIndex = "10000000";
309
+ this.tip = new OverlayTip(doc, this.container);
310
+ this.rects = [];
311
+ this.removeCallback = () => {
312
+ };
313
+ let rafId = null;
314
+ this.resizeObserver = new ResizeObserver(() => {
315
+ if (rafId) {
316
+ cancelAnimationFrame(rafId);
317
+ }
318
+ rafId = requestAnimationFrame(() => {
319
+ if (this.currentElements && this.currentName) {
320
+ this.updatePositions(this.currentElements, this.currentName);
321
+ }
322
+ });
323
+ });
324
+ doc.body.appendChild(this.container);
325
+ }
326
+ }
327
+ class ClickOverlay {
328
+ remove() {
329
+ this.tip.remove();
330
+ if (this.rect) {
331
+ this.rect.remove();
332
+ this.rect = null;
333
+ }
334
+ this.currentElement = null;
335
+ this.resizeObserver.disconnect();
336
+ this.currentName = void 0;
337
+ if (this.container.parentNode) {
338
+ this.container.parentNode.removeChild(this.container);
339
+ }
340
+ }
341
+ highlight(element, name) {
342
+ if (!this.rect) {
343
+ this.rect = new ClickOverlayRect(this.window.document, this.container);
344
+ }
345
+ this.resizeObserver.disconnect();
346
+ this.currentElement = element;
347
+ if (!name) {
348
+ name = element.nodeName.toLowerCase();
349
+ }
350
+ this.currentName = name;
351
+ this.tip.updateText(name);
352
+ this.updatePosition(element);
353
+ this.resizeObserver.observe(element);
354
+ }
355
+ updatePosition(element) {
356
+ var _this_rect;
357
+ const outerBox = {
358
+ top: Number.POSITIVE_INFINITY,
359
+ right: Number.NEGATIVE_INFINITY,
360
+ bottom: Number.NEGATIVE_INFINITY,
361
+ left: Number.POSITIVE_INFINITY
362
+ };
363
+ const box = (0, _utils.getNestedBoundingClientRect)(element, this.window);
364
+ const dims = (0, _utils.getElementDimensions)(element);
365
+ outerBox.top = Math.min(outerBox.top, box.top - dims.marginTop);
366
+ outerBox.right = Math.max(outerBox.right, box.left + box.width + dims.marginRight);
367
+ outerBox.bottom = Math.max(outerBox.bottom, box.top + box.height + dims.marginBottom);
368
+ outerBox.left = Math.min(outerBox.left, box.left - dims.marginLeft);
369
+ (_this_rect = this.rect) === null || _this_rect === void 0 ? void 0 : _this_rect.update(box, dims);
370
+ const tipBounds = (0, _utils.getNestedBoundingClientRect)(this.tipBoundsWindow.document.documentElement, this.window);
371
+ if (box.width === 0 || box.height === 0) {
372
+ this.tip.invisible();
373
+ }
374
+ this.tip.updatePosition({
375
+ top: outerBox.top,
376
+ left: outerBox.left,
377
+ height: outerBox.bottom - outerBox.top,
378
+ width: outerBox.right - outerBox.left
379
+ }, {
380
+ top: tipBounds.top + this.tipBoundsWindow.scrollY,
381
+ left: tipBounds.left + this.tipBoundsWindow.scrollX,
382
+ height: this.tipBoundsWindow.innerHeight,
383
+ width: this.tipBoundsWindow.innerWidth
384
+ });
385
+ }
386
+ clearRect() {
387
+ var _this_rect;
388
+ (_this_rect = this.rect) === null || _this_rect === void 0 ? void 0 : _this_rect.remove();
389
+ this.tip.invisible();
390
+ }
391
+ constructor(positionUpdate) {
392
+ this.currentElement = null;
393
+ this.currentName = void 0;
394
+ this.positionUpdate = positionUpdate;
395
+ const currentWindow = window.__REACT_DEVTOOLS_TARGET_WINDOW__ || window;
396
+ this.window = currentWindow;
397
+ const tipBoundsWindow = window.__REACT_DEVTOOLS_TARGET_WINDOW__ || window;
398
+ this.tipBoundsWindow = tipBoundsWindow;
399
+ const doc = currentWindow.document;
400
+ this.container = doc.createElement("div");
401
+ this.container.style.zIndex = "9999999";
402
+ this.tip = new OverlayTip(doc, this.container);
403
+ this.rect = null;
404
+ let rafId = null;
405
+ this.resizeObserver = new ResizeObserver(() => {
406
+ var _this_positionUpdate, _this;
407
+ if (rafId) {
408
+ cancelAnimationFrame(rafId);
409
+ }
410
+ rafId = requestAnimationFrame(() => {
411
+ if (this.currentElement) {
412
+ this.updatePosition(this.currentElement);
413
+ }
414
+ });
415
+ (_this_positionUpdate = (_this = this).positionUpdate) === null || _this_positionUpdate === void 0 ? void 0 : _this_positionUpdate.call(_this);
416
+ });
417
+ doc.body.appendChild(this.container);
418
+ }
419
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ _export_star(require("./use-layout-effect"), exports);
6
+ _export_star(require("./use-effect-event"), exports);
7
+ _export_star(require("./use-mouse"), exports);
8
+ function _export_star(from, to) {
9
+ Object.keys(from).forEach(function(k) {
10
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
11
+ Object.defineProperty(to, k, {
12
+ enumerable: true,
13
+ get: function() {
14
+ return from[k];
15
+ }
16
+ });
17
+ }
18
+ });
19
+ return from;
20
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "useEffectEvent", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return useEffectEvent;
9
+ }
10
+ });
11
+ const _react = require("react");
12
+ const useEffectEvent = (callback) => {
13
+ const callbackRef = (0, _react.useRef)(callback);
14
+ callbackRef.current = (0, _react.useMemo)(() => callback, [
15
+ callback
16
+ ]);
17
+ const stableRef = (0, _react.useRef)();
18
+ if (!stableRef.current) {
19
+ stableRef.current = function(...args) {
20
+ var _callbackRef_current;
21
+ return (_callbackRef_current = callbackRef.current) === null || _callbackRef_current === void 0 ? void 0 : _callbackRef_current.apply(this, args);
22
+ };
23
+ }
24
+ return stableRef.current;
25
+ };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "useLayoutEffect", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return useLayoutEffect;
9
+ }
10
+ });
11
+ const _react = require("react");
12
+ var _window_document, _window;
13
+ const useLayoutEffect = typeof window !== "undefined" && ((_window = window) === null || _window === void 0 ? void 0 : (_window_document = _window.document) === null || _window_document === void 0 ? void 0 : _window_document.createElement) ? _react.useLayoutEffect : _react.useEffect;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "useMousePosition", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return useMousePosition;
9
+ }
10
+ });
11
+ const _react = require("react");
12
+ const useMousePosition = ({ disable }) => {
13
+ const mouseRef = (0, _react.useRef)({
14
+ x: 0,
15
+ y: 0
16
+ });
17
+ const recordMousePoint = (ev) => {
18
+ mouseRef.current.x = ev.clientX;
19
+ mouseRef.current.y = ev.clientY;
20
+ };
21
+ (0, _react.useEffect)(() => {
22
+ if (!disable) {
23
+ document.addEventListener("mousemove", recordMousePoint, true);
24
+ }
25
+ return () => {
26
+ document.removeEventListener("mousemove", recordMousePoint, true);
27
+ };
28
+ }, [
29
+ disable
30
+ ]);
31
+ return mouseRef;
32
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "Inspector", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return _Inspector.Inspector;
9
+ }
10
+ });
11
+ const _Inspector = require("./Inspector");
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for (var name in all)
7
+ Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
10
+ });
11
+ }
12
+ _export(exports, {
13
+ isNativeTagFiber: function() {
14
+ return isNativeTagFiber;
15
+ },
16
+ isReactSymbolFiber: function() {
17
+ return isReactSymbolFiber;
18
+ },
19
+ isForwardRef: function() {
20
+ return isForwardRef;
21
+ },
22
+ getElementFiber: function() {
23
+ return getElementFiber;
24
+ },
25
+ getElementFiberUpward: function() {
26
+ return getElementFiberUpward;
27
+ },
28
+ getDirectParentFiber: function() {
29
+ return getDirectParentFiber;
30
+ },
31
+ getFiberName: function() {
32
+ return getFiberName;
33
+ }
34
+ });
35
+ const isNativeTagFiber = (fiber) => typeof (fiber === null || fiber === void 0 ? void 0 : fiber.type) === "string";
36
+ const isReactSymbolFiber = (fiber) => {
37
+ var _fiber_type;
38
+ return typeof (fiber === null || fiber === void 0 ? void 0 : (_fiber_type = fiber.type) === null || _fiber_type === void 0 ? void 0 : _fiber_type.$$typeof) === "symbol";
39
+ };
40
+ const isForwardRef = (fiber) => {
41
+ var _fiber_type;
42
+ return (fiber === null || fiber === void 0 ? void 0 : (_fiber_type = fiber.type) === null || _fiber_type === void 0 ? void 0 : _fiber_type.$$typeof) === Symbol.for("react.forward_ref");
43
+ };
44
+ const getElementFiber = (element) => {
45
+ const fiberKey = Object.keys(element).find((key) => (
46
+ /**
47
+ * for react <= v16.13.1
48
+ * https://github.com/facebook/react/blob/v16.13.1/packages/react-dom/src/client/ReactDOMComponentTree.js#L21
49
+ */
50
+ key.startsWith("__reactInternalInstance$") || /**
51
+ * for react >= v16.14.0
52
+ * https://github.com/facebook/react/blob/v16.14.0/packages/react-dom/src/client/ReactDOMComponentTree.js#L39
53
+ */
54
+ key.startsWith("__reactFiber$")
55
+ ));
56
+ if (fiberKey) {
57
+ return element[fiberKey];
58
+ }
59
+ return void 0;
60
+ };
61
+ const getElementFiberUpward = (element) => {
62
+ if (!element)
63
+ return void 0;
64
+ const fiber = getElementFiber(element);
65
+ if (fiber)
66
+ return fiber;
67
+ return getElementFiberUpward(element.parentElement);
68
+ };
69
+ const getDirectParentFiber = (child) => {
70
+ let current = child.return;
71
+ while (current) {
72
+ if (!isReactSymbolFiber(current)) {
73
+ return current;
74
+ }
75
+ current = current.return;
76
+ }
77
+ return null;
78
+ };
79
+ const getFiberName = (fiber) => {
80
+ var _fiber_pendingProps;
81
+ const fiberType = fiber === null || fiber === void 0 ? void 0 : fiber.type;
82
+ if (!fiberType)
83
+ return void 0;
84
+ const { displayName, name } = fiberType;
85
+ if (fiber === null || fiber === void 0 ? void 0 : (_fiber_pendingProps = fiber.pendingProps) === null || _fiber_pendingProps === void 0 ? void 0 : _fiber_pendingProps["data-miaoda-component-name"]) {
86
+ return fiber.pendingProps["data-miaoda-component-name"];
87
+ }
88
+ if (typeof displayName === "string") {
89
+ return displayName;
90
+ }
91
+ if (typeof name === "string") {
92
+ return name;
93
+ }
94
+ return void 0;
95
+ };
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "setupHighlighter", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return setupHighlighter;
9
+ }
10
+ });
11
+ let iframesListeningTo = /* @__PURE__ */ new Set();
12
+ function setupHighlighter(handlers) {
13
+ function onClick(event) {
14
+ var _handlers_onClick;
15
+ event.preventDefault();
16
+ event.stopPropagation();
17
+ (_handlers_onClick = handlers.onClick) === null || _handlers_onClick === void 0 ? void 0 : _handlers_onClick.call(handlers, event.target);
18
+ }
19
+ function onMouseEvent(event) {
20
+ event.stopPropagation();
21
+ }
22
+ function onPointerDown(event) {
23
+ event.stopPropagation();
24
+ }
25
+ function onPointerOver(event) {
26
+ var _handlers_onPointerOver;
27
+ event.preventDefault();
28
+ event.stopPropagation();
29
+ const target = event.target;
30
+ if (target.tagName === "IFRAME") {
31
+ const iframe = target;
32
+ try {
33
+ if (!iframesListeningTo.has(iframe)) {
34
+ const window1 = iframe.contentWindow;
35
+ registerListenersOnWindow(window1);
36
+ iframesListeningTo.add(iframe);
37
+ }
38
+ } catch (error) {
39
+ }
40
+ }
41
+ (_handlers_onPointerOver = handlers.onPointerOver) === null || _handlers_onPointerOver === void 0 ? void 0 : _handlers_onPointerOver.call(handlers, event.target);
42
+ }
43
+ function onPointerUp(event) {
44
+ event.preventDefault();
45
+ event.stopPropagation();
46
+ }
47
+ function removeListenersOnWindow(window1) {
48
+ if (window1 && typeof window1.removeEventListener === "function") {
49
+ window1.removeEventListener("click", onClick, true);
50
+ window1.removeEventListener("mousedown", onMouseEvent, true);
51
+ window1.removeEventListener("mouseover", onMouseEvent, true);
52
+ window1.removeEventListener("mouseup", onMouseEvent, true);
53
+ window1.removeEventListener("pointerdown", onPointerDown, true);
54
+ window1.removeEventListener("pointerover", onPointerOver, true);
55
+ window1.removeEventListener("pointerup", onPointerUp, true);
56
+ }
57
+ }
58
+ function stopInspectingNative() {
59
+ removeListenersOnWindow(window);
60
+ iframesListeningTo.forEach((frame) => {
61
+ try {
62
+ removeListenersOnWindow(frame.contentWindow);
63
+ } catch (error) {
64
+ }
65
+ });
66
+ iframesListeningTo = /* @__PURE__ */ new Set();
67
+ }
68
+ function registerListenersOnWindow(window1) {
69
+ if (window1 && typeof window1.addEventListener === "function") {
70
+ window1.addEventListener("click", onClick, true);
71
+ window1.addEventListener("mousedown", onMouseEvent, true);
72
+ window1.addEventListener("mouseover", onMouseEvent, true);
73
+ window1.addEventListener("mouseup", onMouseEvent, true);
74
+ window1.addEventListener("pointerdown", onPointerDown, true);
75
+ window1.addEventListener("pointerover", onPointerOver, true);
76
+ window1.addEventListener("pointerup", onPointerUp, true);
77
+ }
78
+ }
79
+ function startInspectingNative() {
80
+ registerListenersOnWindow(window);
81
+ }
82
+ startInspectingNative();
83
+ return stopInspectingNative;
84
+ }