vite-plugin-vue-devtools 1.0.0-rc.7 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/README.md +8 -172
  2. package/dist/client/assets/css-a-KJtBLB.js +505 -0
  3. package/dist/client/assets/diff--l9-nN5b.js +1 -0
  4. package/dist/client/assets/html-5-AIf93y.js +74 -0
  5. package/dist/client/assets/index-NNrCE7Vx.css +1 -0
  6. package/dist/client/assets/index-U-H6nGkn.js +1080 -0
  7. package/dist/client/assets/javascript-Of8SnKfU.js +699 -0
  8. package/dist/client/assets/json-t1qiHl76.js +25 -0
  9. package/dist/client/assets/onig-mBJmD8D5.js +1 -0
  10. package/dist/client/assets/shellscript-h1L64xId.js +4 -0
  11. package/dist/client/assets/typescript-b1Nw_bQe.js +666 -0
  12. package/dist/client/assets/unocss-runtime-kftsoZPE.js +2 -0
  13. package/dist/client/assets/vitesse-dark-5VceXvs6.js +1 -0
  14. package/dist/client/assets/vitesse-light-HOMMxGxw.js +1 -0
  15. package/dist/client/assets/vue-apis-Nh9IahXf.js +1 -0
  16. package/dist/client/assets/vue-html-eJ6eRCYJ.js +1 -0
  17. package/dist/client/assets/vue-nOwTje1i.js +2002 -0
  18. package/dist/client/assets/yaml-FtfhlYqU.js +200 -0
  19. package/dist/client/color-scheme.js +6 -0
  20. package/dist/client/css-hXHVOlj5.js +511 -0
  21. package/dist/client/devtools-panel.css +1 -0
  22. package/dist/client/devtools-panel.js +77722 -0
  23. package/dist/client/diff-nydZCsp5.js +7 -0
  24. package/dist/client/html-r4dic7N6.js +84 -0
  25. package/dist/client/index.html +13 -21
  26. package/dist/client/javascript-iu2g-HpL.js +705 -0
  27. package/dist/client/json-6ED1Ntns.js +31 -0
  28. package/dist/client/onig-NuJRzyUz.js +4 -0
  29. package/dist/client/shellscript-lFevXvOp.js +10 -0
  30. package/dist/client/typescript-SzFP_hYV.js +672 -0
  31. package/dist/client/unocss-runtime-c8-Zzj4C.js +1974 -0
  32. package/dist/client/vitesse-dark-Q3b2Vb5y.js +683 -0
  33. package/dist/client/vitesse-light-T_UJmsth.js +681 -0
  34. package/dist/client/vue-apis-j7ljdRbm.js +1127 -0
  35. package/dist/client/vue-html-IdJrwrVJ.js +16 -0
  36. package/dist/client/vue-vFbCUJfs.js +2118 -0
  37. package/dist/client/yaml-n_HyS7lr.js +206 -0
  38. package/dist/vite.cjs +116 -13794
  39. package/dist/vite.d.cts +6 -9
  40. package/dist/vite.d.mts +6 -9
  41. package/dist/vite.d.ts +6 -9
  42. package/dist/vite.mjs +113 -13774
  43. package/package.json +18 -19
  44. package/src/overlay/devtools-overlay.css +1 -0
  45. package/src/overlay/devtools-overlay.js +4 -0
  46. package/src/overlay.js +77 -0
  47. package/README.zh-CN.md +0 -186
  48. package/client.d.ts +0 -63
  49. package/dist/client/assets/DrawerRight.vue_vue_type_script_setup_true_lang-d7a700af.js +0 -81
  50. package/dist/client/assets/IconButton.vue_vue_type_script_setup_true_lang-68ea38ae.js +0 -26
  51. package/dist/client/assets/IconTitle.vue_vue_type_script_setup_true_lang-2d6fc9fc.js +0 -30
  52. package/dist/client/assets/IframeView.vue_vue_type_script_setup_true_lang-5622761a.js +0 -96
  53. package/dist/client/assets/PanelGrids-ffc0170f.js +0 -15
  54. package/dist/client/assets/SectionBlock-0024395a.css +0 -18
  55. package/dist/client/assets/SectionBlock-90af9bd1.js +0 -109
  56. package/dist/client/assets/StateFields.vue_vue_type_script_setup_true_lang-9c2bccf7.js +0 -381
  57. package/dist/client/assets/Switch.vue_vue_type_script_setup_true_lang-2f0bd7d3.js +0 -87
  58. package/dist/client/assets/TextInput.vue_vue_type_script_setup_true_lang-3d5cce68.js +0 -38
  59. package/dist/client/assets/__eyedropper-a70b4bf1.js +0 -149
  60. package/dist/client/assets/_commonjsHelpers-7e83dbf2.js +0 -34
  61. package/dist/client/assets/assets-db2b2e23.js +0 -1597
  62. package/dist/client/assets/component-docs-12ec703a.js +0 -195
  63. package/dist/client/assets/components-a4ae8bec.js +0 -790
  64. package/dist/client/assets/data-5bcd0de2.js +0 -399
  65. package/dist/client/assets/dayjs.min-f03ccd82.js +0 -13
  66. package/dist/client/assets/documentations-87ef4bbe.js +0 -276
  67. package/dist/client/assets/fuse.esm-c317b696.js +0 -1782
  68. package/dist/client/assets/graph-e80ad5ff.js +0 -52092
  69. package/dist/client/assets/index-36a8f2c8.js +0 -18551
  70. package/dist/client/assets/index-b5475fe0.css +0 -482
  71. package/dist/client/assets/inspect-2dd6a256.js +0 -20
  72. package/dist/client/assets/jse-theme-dark-2b1853c1.js +0 -1565
  73. package/dist/client/assets/jse-theme-dark-351d62d5.css +0 -114
  74. package/dist/client/assets/npm-832f3f2c.css +0 -209
  75. package/dist/client/assets/npm-be49d241.js +0 -550
  76. package/dist/client/assets/overview-a871ef56.js +0 -303
  77. package/dist/client/assets/pages-039ef724.js +0 -561
  78. package/dist/client/assets/pinia-7ed2c830.svg +0 -1
  79. package/dist/client/assets/pinia-d2307c92.js +0 -108
  80. package/dist/client/assets/rerender-trace-3afd48a1.css +0 -14
  81. package/dist/client/assets/rerender-trace-df5d6ca3.js +0 -436
  82. package/dist/client/assets/routes-419d52e1.js +0 -132
  83. package/dist/client/assets/settings-42304886.js +0 -9652
  84. package/dist/client/assets/settings-7bce89ae.css +0 -11
  85. package/dist/client/assets/splitpanes.es-025c37b2.js +0 -343
  86. package/dist/client/assets/timeline-947c186e.js +0 -1480
  87. package/dist/client/assets/timeline-b315b2e0.css +0 -1
  88. package/dist/client/assets/vue-5d4e674c.svg +0 -1
  89. package/dist/client/assets/vueuse-995374f6.svg +0 -1
  90. package/src/app.js +0 -4
  91. package/src/views/ComponentInspector.vue +0 -68
  92. package/src/views/FrameBox.vue +0 -231
  93. package/src/views/Main.vue +0 -435
  94. package/src/views/RerenderIndicator.vue +0 -37
  95. package/src/views/composables.ts +0 -630
  96. package/src/views/utils.ts +0 -241
@@ -1,630 +0,0 @@
1
- import { computed, onMounted, reactive, ref, shallowRef, watchEffect } from 'vue'
2
- import type { CSSProperties, ComponentInternalInstance, Ref } from 'vue'
3
- import { getInstanceName } from '@vite-plugin-vue-devtools/core'
4
- import { clamp, createDebounceFn, useObjectStorage, useScreenSafeArea, useWindowEventListener, warn } from './utils'
5
-
6
- interface DevToolsFrameState {
7
- width: number
8
- height: number
9
- top: number
10
- left: number
11
- open: boolean
12
- route: string
13
- position: string
14
- isFirstVisit: boolean
15
- closeOnOutsideClick: boolean
16
- minimizePanelInactive: number
17
- }
18
-
19
- interface ComponentInspectorBounds {
20
- width: number
21
- height: number
22
- top: number
23
- left: number
24
- }
25
-
26
- // ---- state ----
27
- export const PANEL_PADDING = 10
28
- export const PANEL_MIN = 20
29
- export const PANEL_MAX = 100
30
-
31
- export const popupWindow = shallowRef<Window | null>(null)
32
-
33
- export const state = useObjectStorage<DevToolsFrameState>('__vue-devtools-frame-state__', {
34
- width: 80,
35
- height: 60,
36
- top: 0,
37
- left: 50,
38
- open: false,
39
- route: '/',
40
- position: 'bottom',
41
- isFirstVisit: true,
42
- closeOnOutsideClick: false,
43
- minimizePanelInactive: 5000,
44
- })
45
-
46
- // ---- useIframe ----
47
- export function useIframe(clientUrl: string, onLoad: () => void) {
48
- const iframe = ref<HTMLIFrameElement>()
49
- function getIframe() {
50
- if (iframe.value)
51
- return iframe.value
52
- iframe.value = document.createElement('iframe')
53
- iframe.value.id = 'vue-devtools-iframe'
54
- iframe.value.src = clientUrl
55
- iframe.value.setAttribute('data-v-inspector-ignore', 'true')
56
- iframe.value.onload = onLoad
57
- return iframe.value
58
- }
59
-
60
- return {
61
- getIframe,
62
- iframe,
63
- }
64
- }
65
-
66
- // ---- useInspector ----
67
- type OpenInEditorFnFromPlugin = (baseUrl: string, filePath: string, line?: number, column?: number) => void
68
-
69
- export function useInspector() {
70
- const inspectorEnabled = ref(false)
71
- const inspectorLoaded = ref(false)
72
-
73
- const enable = () => {
74
- window.__VUE_INSPECTOR__?.enable()
75
- inspectorEnabled.value = true
76
- }
77
-
78
- const disable = () => {
79
- window.__VUE_INSPECTOR__?.disable()
80
- inspectorEnabled.value = false
81
- }
82
-
83
- const openInEditor = ref< (filePath: string, line?: number, column?: number) => void>()
84
-
85
- const getBaseUrl = () => {
86
- const { protocol, hostname, port } = window.location
87
- return `${protocol}//${hostname}:${port}`
88
- }
89
-
90
- const registerOpenInEditor = (openInEditorFn: OpenInEditorFnFromPlugin) => {
91
- openInEditor.value = (filePath: string, line?: number, column?: number) => {
92
- openInEditorFn(getBaseUrl(), filePath, line ?? 1, column ?? 1)
93
- }
94
- }
95
-
96
- const setupInspector = () => {
97
- const componentInspector = window.__VUE_INSPECTOR__
98
- if (componentInspector) {
99
- const _openInEditor = componentInspector.openInEditor
100
- componentInspector.openInEditor = async (...params: any[]) => {
101
- disable()
102
- _openInEditor(...params)
103
- }
104
- registerOpenInEditor(_openInEditor)
105
- }
106
- }
107
-
108
- const waitForInspectorInit = () => {
109
- let total = 0
110
- const timer = setInterval(() => {
111
- if (window.__VUE_INSPECTOR__) {
112
- clearInterval(timer)
113
- inspectorLoaded.value = true
114
- setupInspector()
115
- total += 30
116
- }
117
- if (total >=/* 2s */ 2000) {
118
- clearInterval(timer)
119
- warn('Unable to load inspector')
120
- }
121
- }, 30)
122
- }
123
-
124
- useWindowEventListener('keydown', (e: KeyboardEvent) => {
125
- if (!inspectorEnabled.value || !inspectorLoaded.value)
126
- return
127
- if (e.key === 'Escape')
128
- disable()
129
- })
130
-
131
- waitForInspectorInit()
132
-
133
- return {
134
- toggleInspector() {
135
- if (!inspectorLoaded.value)
136
- return
137
- inspectorEnabled.value ? disable() : enable()
138
- },
139
- inspectorEnabled,
140
- enableInspector: enable,
141
- disableInspector: disable,
142
- setupInspector,
143
- inspectorLoaded,
144
- openInEditor,
145
- waitForInspectorInit,
146
- }
147
- }
148
-
149
- // ---- usePanelVisible ----
150
- export function usePanelVisible() {
151
- const visible = computed({
152
- get() {
153
- return state.value.open
154
- },
155
- set(value) {
156
- state.value.open = value
157
- },
158
- })
159
-
160
- const toggleVisible = () => {
161
- visible.value = !visible.value
162
- }
163
-
164
- const closePanel = () => {
165
- if (!visible.value)
166
- return
167
- visible.value = false
168
- if (popupWindow.value) {
169
- try {
170
- popupWindow.value.close()
171
- }
172
- catch { }
173
- popupWindow.value = null
174
- }
175
- }
176
-
177
- onMounted(() => {
178
- useWindowEventListener('keydown', (e) => {
179
- // cmd + shift + D in <macOS>
180
- // alt + shift + D in <Windows>
181
- if (e.code === 'KeyD' && e.altKey && e.shiftKey)
182
- toggleVisible()
183
- })
184
- })
185
-
186
- return {
187
- panelVisible: visible,
188
- togglePanelVisible: toggleVisible,
189
- closePanel,
190
- }
191
- }
192
-
193
- // ---- usePipMode ----
194
- export function usePiPMode(iframeGetter: () => HTMLIFrameElement | undefined, hook: object) {
195
- // Experimental: Picture-in-Picture mode
196
- // https://developer.chrome.com/docs/web-platform/document-picture-in-picture/
197
- // @ts-expect-error experimental API
198
- const documentPictureInPicture = window.documentPictureInPicture
199
- async function popup() {
200
- const iframe = iframeGetter()
201
- let isSuccess = true
202
- try {
203
- const pip = popupWindow.value = await documentPictureInPicture.requestWindow({
204
- width: Math.round(window.innerWidth * state.value.width / 100),
205
- height: Math.round(window.innerHeight * state.value.height / 100),
206
- })
207
- const style = pip.document.createElement('style')
208
- style.innerHTML = `
209
- body {
210
- margin: 0;
211
- padding: 0;
212
- }
213
- iframe {
214
- width: 100vw;
215
- height: 100vh;
216
- border: none;
217
- outline: none;
218
- }
219
- `
220
- pip.__VUE_DEVTOOLS_GLOBAL_HOOK__ = hook
221
- pip.__VUE_DEVTOOLS_IS_POPUP__ = true
222
- pip.document.title = 'Vue DevTools'
223
- pip.document.head.appendChild(style)
224
- pip.document.body.appendChild(iframe)
225
- pip.addEventListener('resize', () => {
226
- state.value.width = Math.round(pip.innerWidth / window.innerWidth * 100)
227
- state.value.height = Math.round(pip.innerHeight / window.innerHeight * 100)
228
- })
229
- pip.addEventListener('pagehide', () => {
230
- popupWindow.value = null
231
- pip.close()
232
- })
233
- }
234
- catch (error) {
235
- isSuccess = false
236
- console.error(`[vite-plugin-vue-devtools] Open popup mode failed: ${(error as DOMException).message}`)
237
- }
238
- return isSuccess
239
- }
240
- return {
241
- popup,
242
- }
243
- }
244
-
245
- // ---- usePosition ----
246
- const SNAP_THRESHOLD = 2
247
-
248
- function snapToPoints(value: number) {
249
- if (value < 5)
250
- return 0
251
- if (value > 95)
252
- return 100
253
- if (Math.abs(value - 50) < SNAP_THRESHOLD)
254
- return 50
255
- return value
256
- }
257
-
258
- export function usePosition(panelEl: Ref<HTMLElement | undefined>) {
259
- const isHovering = ref(false)
260
- const isDragging = ref(false)
261
- const draggingOffset = reactive({ x: 0, y: 0 })
262
- const windowSize = reactive({ width: 0, height: 0 })
263
- const mousePosition = reactive({ x: 0, y: 0 })
264
- const panelMargins = reactive({
265
- left: 10,
266
- top: 10,
267
- right: 10,
268
- bottom: 10,
269
- })
270
- let _timer: ReturnType<typeof setTimeout> | null = null
271
-
272
- const safeArea = useScreenSafeArea()
273
-
274
- watchEffect(() => {
275
- panelMargins.left = safeArea.left.value + 10
276
- panelMargins.top = safeArea.top.value + 10
277
- panelMargins.right = safeArea.right.value + 10
278
- panelMargins.bottom = safeArea.bottom.value + 10
279
- })
280
-
281
- const onPointerDown = (e: PointerEvent) => {
282
- isDragging.value = true
283
- const { left, top, width, height } = panelEl.value!.getBoundingClientRect()
284
- draggingOffset.x = e.clientX - left - width / 2
285
- draggingOffset.y = e.clientY - top - height / 2
286
- }
287
-
288
- const setWindowSize = () => {
289
- windowSize.width = window.innerWidth
290
- windowSize.height = window.innerHeight
291
- }
292
-
293
- const bringUp = () => {
294
- isHovering.value = true
295
- if (state.value.minimizePanelInactive < 0)
296
- return
297
- if (_timer)
298
- clearTimeout(_timer)
299
- _timer = setTimeout(() => {
300
- isHovering.value = false
301
- }, +state.value.minimizePanelInactive || 0)
302
- }
303
-
304
- onMounted(() => {
305
- setWindowSize()
306
-
307
- bringUp()
308
-
309
- useWindowEventListener('resize', () => {
310
- setWindowSize()
311
- })
312
-
313
- useWindowEventListener('pointerup', () => {
314
- isDragging.value = false
315
- })
316
- useWindowEventListener('pointerleave', () => {
317
- isDragging.value = false
318
- })
319
- useWindowEventListener('pointermove', (e) => {
320
- if (!isDragging.value)
321
- return
322
-
323
- const centerX = windowSize.width / 2
324
- const centerY = windowSize.height / 2
325
-
326
- const x = e.clientX - draggingOffset.x
327
- const y = e.clientY - draggingOffset.y
328
-
329
- mousePosition.x = x
330
- mousePosition.y = y
331
-
332
- // Get position
333
- const deg = Math.atan2(y - centerY, x - centerX)
334
- const HORIZONTAL_MARGIN = 70
335
- const TL = Math.atan2(0 - centerY + HORIZONTAL_MARGIN, 0 - centerX)
336
- const TR = Math.atan2(0 - centerY + HORIZONTAL_MARGIN, windowSize.width - centerX)
337
- const BL = Math.atan2(windowSize.height - HORIZONTAL_MARGIN - centerY, 0 - centerX)
338
- const BR = Math.atan2(windowSize.height - HORIZONTAL_MARGIN - centerY, windowSize.width - centerX)
339
-
340
- state.value.position = (deg >= TL && deg <= TR)
341
- ? 'top'
342
- : (deg >= TR && deg <= BR)
343
- ? 'right'
344
- : (deg >= BR && deg <= BL)
345
- ? 'bottom'
346
- : 'left'
347
-
348
- state.value.left = snapToPoints(x / windowSize.width * 100)
349
- state.value.top = snapToPoints(y / windowSize.height * 100)
350
- })
351
- })
352
-
353
- const isVertical = computed(() => state.value.position === 'left' || state.value.position === 'right')
354
- const isHidden = computed(() => {
355
- if (state.value.minimizePanelInactive < 0)
356
- return false
357
- if (state.value.minimizePanelInactive === 0)
358
- return true
359
- // @ts-expect-error compatibility
360
- const isTouchDevice = 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0
361
- return !isDragging.value
362
- && !state.value.open
363
- && !isHovering.value
364
- && !isTouchDevice
365
- && state.value.minimizePanelInactive
366
- })
367
-
368
- const anchorPos = computed(() => {
369
- const halfWidth = (panelEl.value?.clientWidth || 0) / 2
370
- const halfHeight = (panelEl.value?.clientHeight || 0) / 2
371
-
372
- const left = state.value.left * windowSize.width / 100
373
- const top = state.value.top * windowSize.height / 100
374
-
375
- switch (state.value.position) {
376
- case 'top':
377
- return {
378
- left: clamp(left, halfWidth + panelMargins.left, windowSize.width - halfWidth - panelMargins.right),
379
- top: panelMargins.top + halfHeight,
380
- }
381
- case 'right':
382
- return {
383
- left: windowSize.width - panelMargins.right - halfHeight,
384
- top: clamp(top, halfWidth + panelMargins.top, windowSize.height - halfWidth - panelMargins.bottom),
385
- }
386
- case 'left':
387
- return {
388
- left: panelMargins.left + halfHeight,
389
- top: clamp(top, halfWidth + panelMargins.top, windowSize.height - halfWidth - panelMargins.bottom),
390
- }
391
- case 'bottom':
392
- default:
393
- return {
394
- left: clamp(left, halfWidth + panelMargins.left, windowSize.width - halfWidth - panelMargins.right),
395
- top: windowSize.height - panelMargins.bottom - halfHeight,
396
- }
397
- }
398
- })
399
-
400
- const anchorStyle = computed(() => ({ left: `${anchorPos.value.left}px`, top: `${anchorPos.value.top}px` }))
401
-
402
- const iframeStyle = computed(() => {
403
- // eslint-disable-next-line no-unused-expressions, no-sequences
404
- mousePosition.x, mousePosition.y
405
-
406
- const halfHeight = (panelEl.value?.clientHeight || 0) / 2
407
-
408
- const frameMargin = {
409
- left: panelMargins.left + halfHeight,
410
- top: panelMargins.top + halfHeight,
411
- right: panelMargins.right + halfHeight,
412
- bottom: panelMargins.bottom + halfHeight,
413
- }
414
-
415
- const marginHorizontal = frameMargin.left + frameMargin.right
416
- const marginVertical = frameMargin.top + frameMargin.bottom
417
-
418
- const maxWidth = windowSize.width - marginHorizontal
419
- const maxHeight = windowSize.height - marginVertical
420
-
421
- const style: CSSProperties = {
422
- zIndex: -1,
423
- pointerEvents: isDragging.value ? 'none' : 'auto',
424
- width: `min(${state.value.width}vw, calc(100vw - ${marginHorizontal}px))`,
425
- height: `min(${state.value.height}vh, calc(100vh - ${marginVertical}px))`,
426
- }
427
-
428
- const anchor = anchorPos.value
429
- const width = Math.min(maxWidth, state.value.width * windowSize.width / 100)
430
- const height = Math.min(maxHeight, state.value.height * windowSize.height / 100)
431
-
432
- const anchorX = anchor?.left || 0
433
- const anchorY = anchor?.top || 0
434
-
435
- switch (state.value.position) {
436
- case 'top':
437
- case 'bottom':
438
- style.left = 0
439
- style.transform = 'translate(-50%, 0)'
440
- if ((anchorX - frameMargin.left) < width / 2)
441
- style.left = `${width / 2 - anchorX + frameMargin.left}px`
442
- else if ((windowSize.width - anchorX - frameMargin.right) < width / 2)
443
- style.left = `${windowSize.width - anchorX - width / 2 - frameMargin.right}px`
444
- break
445
- case 'right':
446
- case 'left':
447
- style.top = 0
448
- style.transform = 'translate(0, -50%)'
449
- if ((anchorY - frameMargin.top) < height / 2)
450
- style.top = `${height / 2 - anchorY + frameMargin.top}px`
451
- else if ((windowSize.height - anchorY - frameMargin.bottom) < height / 2)
452
- style.top = `${windowSize.height - anchorY - height / 2 - frameMargin.bottom}px`
453
- break
454
- }
455
-
456
- switch (state.value.position) {
457
- case 'top':
458
- style.top = 0
459
- break
460
- case 'right':
461
- style.right = 0
462
- break
463
- case 'left':
464
- style.left = 0
465
- break
466
- case 'bottom':
467
- default:
468
- style.bottom = 0
469
- break
470
- }
471
-
472
- return style
473
- })
474
-
475
- const panelStyle = computed(() => {
476
- const style: any = {
477
- transform: isVertical.value
478
- ? `translate(${isHidden.value ? `calc(-50% ${state.value.position === 'right' ? '+' : '-'} 15px)` : '-50%'}, -50%) rotate(90deg)`
479
- : `translate(-50%, ${isHidden.value ? `calc(-50% ${state.value.position === 'top' ? '-' : '+'} 15px)` : '-50%'})`,
480
- }
481
- if (isHidden.value) {
482
- switch (state.value.position) {
483
- case 'top':
484
- case 'right':
485
- style.borderTopLeftRadius = '0'
486
- style.borderTopRightRadius = '0'
487
- break
488
- case 'bottom':
489
- case 'left':
490
- style.borderBottomLeftRadius = '0'
491
- style.borderBottomRightRadius = '0'
492
- break
493
- }
494
- }
495
- if (isDragging.value)
496
- style.transition = 'none !important'
497
- return style
498
- })
499
-
500
- return {
501
- isHidden,
502
- isDragging,
503
- isVertical,
504
- anchorStyle,
505
- iframeStyle,
506
- panelStyle,
507
- onPointerDown,
508
- bringUp,
509
- }
510
- }
511
-
512
- // ---- useHighlightComponent ----
513
-
514
- export function useHighlightComponent() {
515
- const name = ref('')
516
- const overlayVisible = ref(false)
517
- const initialBounds = {
518
- width: 0,
519
- height: 0,
520
- left: 0,
521
- top: 0,
522
- }
523
- const bounds = ref<ComponentInspectorBounds>(initialBounds)
524
-
525
- function highlight(_name: string, _bounds: ComponentInspectorBounds) {
526
- name.value = _name
527
- bounds.value = _bounds
528
- overlayVisible.value = true
529
- }
530
-
531
- function unHighlight() {
532
- bounds.value = initialBounds
533
- overlayVisible.value = false
534
- }
535
-
536
- let inspectInstance: ComponentInternalInstance | null = null
537
- let inspectClickCallback: ((instance: ComponentInternalInstance) => void) | null = null
538
-
539
- const inspectFn = (e: MouseEvent) => {
540
- const target = e.target as { __vueParentComponent?: ComponentInternalInstance }
541
- if (target) {
542
- const instance = target.__vueParentComponent
543
- if (instance) {
544
- const el = instance.vnode.el as HTMLElement | undefined
545
- if (el && el.nodeType === Node.ELEMENT_NODE) {
546
- inspectInstance = instance
547
- highlight(getInstanceName(instance), el.getBoundingClientRect())
548
- return
549
- }
550
- }
551
- }
552
- inspectInstance = null
553
- }
554
-
555
- const inspectClickFn = (e: MouseEvent) => {
556
- e.preventDefault()
557
- e.stopPropagation()
558
- if (inspectInstance) {
559
- inspectClickCallback!(inspectInstance)
560
- stopInspect()
561
- }
562
- }
563
-
564
- function startInspect(cb?: (instance: ComponentInternalInstance) => void) {
565
- if (!inspectClickCallback)
566
- inspectClickCallback = cb ?? (() => {})
567
- useWindowEventListener('mouseover', inspectFn)
568
- useWindowEventListener('click', inspectClickFn)
569
- }
570
-
571
- function stopInspect() {
572
- window.removeEventListener('mouseover', inspectFn)
573
- window.removeEventListener('click', inspectClickFn)
574
- unHighlight()
575
- inspectInstance = null
576
- inspectClickCallback = null
577
- }
578
-
579
- return {
580
- name,
581
- overlayVisible,
582
- bounds,
583
- highlight,
584
- unHighlight,
585
- startInspect,
586
- stopInspect,
587
- }
588
- }
589
-
590
- // use rerender highlight
591
-
592
- interface RerenderHighlightData {
593
- name: string
594
- rerenderCount: number
595
- bound: {
596
- width: number
597
- height: number
598
- left: number
599
- top: number
600
- }
601
- debounceFn: () => void
602
- }
603
-
604
- const rerenderHighlightMap = ref<Map</* component instance uid */string, RerenderHighlightData>>(new Map())
605
-
606
- function updateRerenderHighlightInfo(uid: string, name: string, bound: RerenderHighlightData['bound']) {
607
- const data = rerenderHighlightMap.value.get(uid)
608
- if (!data) {
609
- const debounceFn = createDebounceFn(() => {
610
- rerenderHighlightMap.value.delete(uid)
611
- }, 3000)
612
- rerenderHighlightMap.value.set(uid, {
613
- rerenderCount: 0,
614
- bound,
615
- debounceFn,
616
- name,
617
- })
618
- debounceFn()
619
- return
620
- }
621
- data.rerenderCount += 1
622
- data.debounceFn()
623
- }
624
-
625
- export function useRerenderHighlight() {
626
- return {
627
- rerenderHighlightMap,
628
- updateRerenderHighlightInfo,
629
- }
630
- }