@mobilewright/inspector 0.0.60 → 0.0.62

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 (42) hide show
  1. package/dist/index.d.ts +4 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +42 -8
  4. package/dist/index.js.map +1 -1
  5. package/dist/lib/device-manager.d.ts +24 -9
  6. package/dist/lib/device-manager.d.ts.map +1 -1
  7. package/dist/lib/device-manager.js +95 -14
  8. package/dist/lib/device-manager.js.map +1 -1
  9. package/dist/lib/inspect-screen.d.ts +48 -0
  10. package/dist/lib/inspect-screen.d.ts.map +1 -0
  11. package/dist/lib/inspect-screen.js +105 -0
  12. package/dist/lib/inspect-screen.js.map +1 -0
  13. package/dist/lib/locator-derivation.d.ts +17 -2
  14. package/dist/lib/locator-derivation.d.ts.map +1 -1
  15. package/dist/lib/locator-derivation.js +26 -7
  16. package/dist/lib/locator-derivation.js.map +1 -1
  17. package/dist/lib/timeout.d.ts +3 -0
  18. package/dist/lib/timeout.d.ts.map +1 -0
  19. package/dist/lib/timeout.js +9 -0
  20. package/dist/lib/timeout.js.map +1 -0
  21. package/dist/routes/device-actions.d.ts +7 -0
  22. package/dist/routes/device-actions.d.ts.map +1 -0
  23. package/dist/routes/device-actions.js +105 -0
  24. package/dist/routes/device-actions.js.map +1 -0
  25. package/dist/routes/devices.d.ts +1 -1
  26. package/dist/routes/devices.d.ts.map +1 -1
  27. package/dist/routes/devices.js +10 -11
  28. package/dist/routes/devices.js.map +1 -1
  29. package/dist/routes/inspect.d.ts.map +1 -1
  30. package/dist/routes/inspect.js +22 -92
  31. package/dist/routes/inspect.js.map +1 -1
  32. package/package.json +3 -3
  33. package/public/codegen.html +161 -0
  34. package/public/css/app.css +337 -2
  35. package/public/fonts/codicon-LICENSE.txt +21 -0
  36. package/public/fonts/codicon.ttf +0 -0
  37. package/public/index.html +3 -2
  38. package/public/js/app.js +203 -55
  39. package/public/js/codegen.js +425 -0
  40. package/public/js/inspect.js +7 -0
  41. package/public/js/view-tree.js +182 -0
  42. package/public/logo.png +0 -0
package/public/js/app.js CHANGED
@@ -1,4 +1,4 @@
1
- // Mobilewright Inspector frontend. No framework, no build step.
1
+ // Shared Mobilewright Inspector frontend, used by inspect.js and codegen.js. No framework, no build step.
2
2
 
3
3
  // ---- Pure locator utilities ----
4
4
 
@@ -9,7 +9,7 @@ function locatorKey(locator) {
9
9
  return `${locator.kind}:${locator.value}`
10
10
  }
11
11
 
12
- function escQ(s) {
12
+ export function escQ(s) {
13
13
  return s
14
14
  .replace(/\\/g, '\\\\')
15
15
  .replace(/'/g, "\\'")
@@ -31,6 +31,19 @@ function locatorLabel(locator) {
31
31
  return ''
32
32
  }
33
33
 
34
+ // The code that selects this element: its best locator, plus .nth() when the query engine
35
+ // resolves that locator to several elements (el.match comes from the server).
36
+ export function locatorCode(el) {
37
+ if (!el.locator) {
38
+ return null
39
+ }
40
+ const base = locatorLabel(el.locator)
41
+ if (el.match && el.match.count > 1) {
42
+ return `${base}.nth(${el.match.index})`
43
+ }
44
+ return base
45
+ }
46
+
34
47
  function buildDuplicateSet(elements) {
35
48
  const counts = new Map()
36
49
  for (const el of elements) {
@@ -46,7 +59,7 @@ function buildDuplicateSet(elements) {
46
59
  // ---- ScreenshotPane ----
47
60
  // Owns the screenshot image, SVG highlight overlay, and placeholder state.
48
61
 
49
- class ScreenshotPane {
62
+ export class ScreenshotPane {
50
63
  #img
51
64
  #overlay
52
65
  #placeholder
@@ -54,6 +67,7 @@ class ScreenshotPane {
54
67
  #placeholderSub
55
68
  #logicalWidth = 0
56
69
  #logicalHeight = 0
70
+ #deviceScale = 0 // device pixels per logical point, e.g. 3 on most iPhones
57
71
  #elements = []
58
72
  #hiddenIndices = new Set()
59
73
  #selectedIndex = null
@@ -61,8 +75,12 @@ class ScreenshotPane {
61
75
  #screenshotPane // cached pane element for #constrainSize
62
76
  // O(1) lookup from element index to its SVG rect; rebuilt on each renderHighlights call.
63
77
  #rectByIndex = new Map()
78
+ #showAllHighlights
79
+ #hoverRect = null
64
80
 
65
- constructor() {
81
+ // showAllHighlights: false draws no element boxes, only the one passed to showHoverBox (codegen).
82
+ constructor({ showAllHighlights = true } = {}) {
83
+ this.#showAllHighlights = showAllHighlights
66
84
  this.#img = document.getElementById('screenshot-img')
67
85
  this.#overlay = document.getElementById('highlight-overlay')
68
86
  this.#placeholder = document.getElementById('no-device-msg')
@@ -74,6 +92,54 @@ class ScreenshotPane {
74
92
 
75
93
  onElementClick(cb) { this.#onClickCb = cb }
76
94
 
95
+ // Report clicks / pointer moves on the screenshot as integer device coordinates (logical points, not image pixels).
96
+ // The third argument is whether Shift was held.
97
+ onScreenTap(cb) {
98
+ this.#img.addEventListener('click', e => cb(...this.#devicePointOf(e), e.shiftKey))
99
+ }
100
+
101
+ onScreenHover(cb) {
102
+ this.#img.addEventListener('mousemove', e => cb(...this.#devicePointOf(e), e.shiftKey))
103
+ this.#img.addEventListener('mouseleave', () => cb(null, null, false))
104
+ }
105
+
106
+ // The smallest visible element under (x, y) that passes `accepts`, or null.
107
+ elementAt(x, y, accepts = () => true) {
108
+ let best = null
109
+ for (const el of this.#visibleElements()) {
110
+ const b = el.bounds
111
+ const isInside = x >= b.x && x < b.x + b.width && y >= b.y && y < b.y + b.height
112
+ if (isInside && accepts(el) && (!best || b.width * b.height < best.bounds.width * best.bounds.height)) {
113
+ best = el
114
+ }
115
+ }
116
+ return best
117
+ }
118
+
119
+ showHoverBox(el) {
120
+ this.#hoverRect?.remove()
121
+ this.#hoverRect = null
122
+ if (!el) {
123
+ return
124
+ }
125
+ const { x, y, width, height } = el.bounds
126
+ const rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect')
127
+ rect.setAttribute('x', x)
128
+ rect.setAttribute('y', y)
129
+ rect.setAttribute('width', width)
130
+ rect.setAttribute('height', height)
131
+ rect.classList.add('hover-rect')
132
+ this.#hoverRect = rect
133
+ this.#overlay.appendChild(rect)
134
+ }
135
+
136
+ #devicePointOf(e) {
137
+ const box = this.#img.getBoundingClientRect()
138
+ const scaleX = (this.#logicalWidth || this.#img.naturalWidth) / box.width
139
+ const scaleY = (this.#logicalHeight || this.#img.naturalHeight) / box.height
140
+ return [Math.round((e.clientX - box.left) * scaleX), Math.round((e.clientY - box.top) * scaleY)]
141
+ }
142
+
77
143
  get isScreenshotHidden() { return this.#img.hidden }
78
144
 
79
145
  showPlaceholder(title, sub = '', loading = false) {
@@ -85,9 +151,10 @@ class ScreenshotPane {
85
151
  this.#placeholder.classList.toggle('loading', loading)
86
152
  }
87
153
 
88
- showScreenshot(dataUrl, logicalWidth = 0, logicalHeight = 0) {
154
+ showScreenshot(dataUrl, logicalWidth = 0, logicalHeight = 0, deviceScale = 0) {
89
155
  this.#logicalWidth = logicalWidth
90
156
  this.#logicalHeight = logicalHeight
157
+ this.#deviceScale = deviceScale
91
158
  this.#placeholder.hidden = true
92
159
  this.#placeholder.classList.remove('loading')
93
160
  this.#img.hidden = false
@@ -112,7 +179,11 @@ class ScreenshotPane {
112
179
 
113
180
  #buildRects() {
114
181
  this.#overlay.innerHTML = ''
182
+ this.#hoverRect = null
115
183
  this.#rectByIndex.clear()
184
+ if (!this.#showAllHighlights) {
185
+ return
186
+ }
116
187
  for (const el of this.#visibleElements()) {
117
188
  const { x, y, width, height } = el.bounds
118
189
  const rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect')
@@ -140,11 +211,27 @@ class ScreenshotPane {
140
211
  )
141
212
  }
142
213
 
214
+ // Ask for a half-size screenshot when the pane can show at most half of the device's
215
+ // pixel height anyway; the full-size image would only be downscaled by the browser.
216
+ preferredScreenshotScale() {
217
+ const devicePixelHeight = this.#logicalHeight * this.#deviceScale
218
+ if (!devicePixelHeight) {
219
+ return 1
220
+ }
221
+ const panePixelHeight = this.#availableHeight() * window.devicePixelRatio
222
+ return panePixelHeight <= devicePixelHeight / 2 ? 0.5 : 1
223
+ }
224
+
225
+ // Height left for the screenshot below anything stacked above it in the pane (codegen's device toolbar).
226
+ #availableHeight() {
227
+ const cs = getComputedStyle(this.#screenshotPane)
228
+ const container = this.#img.parentElement
229
+ return this.#screenshotPane.clientHeight - container.offsetTop - parseFloat(cs.paddingBottom)
230
+ }
231
+
143
232
  #constrainSize() {
144
233
  if (this.#img.hidden) return
145
- const cs = getComputedStyle(this.#screenshotPane)
146
- const availH = this.#screenshotPane.clientHeight - parseFloat(cs.paddingTop) - parseFloat(cs.paddingBottom)
147
- this.#img.style.maxHeight = availH + 'px'
234
+ this.#img.style.maxHeight = this.#availableHeight() + 'px'
148
235
  const vw = this.#logicalWidth || this.#img.naturalWidth
149
236
  const vh = this.#logicalHeight || this.#img.naturalHeight
150
237
  this.#overlay.setAttribute('width', this.#img.offsetWidth)
@@ -156,7 +243,7 @@ class ScreenshotPane {
156
243
  // ---- DetailPane ----
157
244
  // Shows element properties, all locator strategies, raw attributes.
158
245
 
159
- class DetailPane {
246
+ export class DetailPane {
160
247
  #pane
161
248
  #typeEl
162
249
  #locatorsEl
@@ -392,7 +479,7 @@ class ElementsPane {
392
479
  if (!el.locator) row.classList.add('no-locator')
393
480
  if (hiddenIndices.has(el.index)) row.classList.add('element-hidden')
394
481
 
395
- const locLabel = el.locator ? locatorLabel(el.locator) : null
482
+ const locLabel = locatorCode(el)
396
483
  row.setAttribute('aria-label', locLabel ?? `${el.type ?? 'unknown'} (no locator)`)
397
484
 
398
485
  const badge = document.createElement('span')
@@ -457,7 +544,7 @@ class ElementsPane {
457
544
  // ---- Inspector ----
458
545
  // Orchestrates device management, the refresh cycle, and shared selection/visibility state.
459
546
 
460
- class Inspector {
547
+ export class Inspector {
461
548
  #state = {
462
549
  devices: [],
463
550
  activeId: null,
@@ -471,37 +558,60 @@ class Inspector {
471
558
  // Pruned on each refresh to keys present in the new element list.
472
559
  #userOverrides = new Map()
473
560
  #autoRefreshTimer = null
561
+ // Etag of the payload on screen. Cleared whenever the screen stops showing it, so a 304 never
562
+ // leaves a placeholder or another device's state up.
563
+ #shownEtag = null
474
564
  #tickInFlight = false
475
565
  #refreshInFlight = false
476
566
  #connectInFlight = false
477
567
  #consecutiveErrors = 0
478
568
  static #MAX_CONSECUTIVE_ERRORS = 3
479
-
480
- #screenshotPane = new ScreenshotPane()
481
- #elementsPane = new ElementsPane()
482
- #detailPane = new DetailPane()
569
+ static #MIN_FRAME_MS = 100
570
+ // Continuous mode has no refresh controls, so the device list is polled on its own to pick up
571
+ // devices connected after the page opened (and disconnects between frames).
572
+ static #DEVICE_LIST_REFRESH_MS = 5000
573
+
574
+ #screenshotPane
575
+ #elementsPane
576
+ #detailPane
483
577
  #deviceSelect = document.getElementById('device-select')
484
578
  #refreshBtn = document.getElementById('refresh-btn')
485
579
  #autoRefreshToggle = document.getElementById('auto-refresh-toggle')
486
580
  #autoRefreshInterval = document.getElementById('auto-refresh-interval')
487
581
  #statusBar = document.getElementById('status-bar')
488
582
 
489
- constructor() {
583
+ #onActiveDeviceChangeCb
584
+ #isContinuousRefresh
585
+
586
+ // Panes are injectable so pages without an element list (codegen) can pass no-op stand-ins.
587
+ // onActiveDeviceChange(device | null) fires whenever the active device may have changed; it must be idempotent.
588
+ // continuousRefresh: request the next screenshot as soon as the previous one arrives, forever,
589
+ // for pages without the refresh controls (codegen).
590
+ constructor({ screenshotPane = new ScreenshotPane(), elementsPane = new ElementsPane(), detailPane = new DetailPane(), onActiveDeviceChange = null, continuousRefresh = false } = {}) {
591
+ this.#isContinuousRefresh = continuousRefresh
592
+ this.#screenshotPane = screenshotPane
593
+ this.#elementsPane = elementsPane
594
+ this.#detailPane = detailPane
595
+ this.#onActiveDeviceChangeCb = onActiveDeviceChange
490
596
  this.#screenshotPane.onElementClick(i => this.#selectElement(i))
491
597
  this.#elementsPane.onElementClick(i => this.#selectElement(i))
492
598
  this.#elementsPane.onToggleHidden(i => this.#toggleHidden(i))
493
599
  this.#detailPane.onClose(() => { this.#state.selectedIndex = null; this.#screenshotPane.setSelectedIndex(null); this.#elementsPane.setSelectedIndex(null) })
494
600
 
495
- this.#refreshBtn.addEventListener('click', () => this.refresh())
601
+ this.#refreshBtn?.addEventListener('click', () => this.refresh())
496
602
  this.#deviceSelect.addEventListener('change', () => {
497
603
  const opt = this.#deviceSelect.selectedOptions[0]
498
604
  if (!opt?.value) return
499
605
  const device = this.#state.devices.find(d => d.id === opt.value)
500
606
  if (device) this.#connectDevice(device)
501
607
  })
502
- this.#autoRefreshToggle.addEventListener('change', () => this.#applyAutoRefresh())
503
- this.#autoRefreshInterval.addEventListener('change', () => this.#applyAutoRefresh())
608
+ this.#autoRefreshToggle?.addEventListener('change', () => this.#applyAutoRefresh())
609
+ this.#autoRefreshInterval?.addEventListener('change', () => this.#applyAutoRefresh())
504
610
 
611
+ if (continuousRefresh) {
612
+ this.#refreshContinuously()
613
+ setInterval(() => this.#fetchDevices().catch(() => {}), Inspector.#DEVICE_LIST_REFRESH_MS)
614
+ }
505
615
  this.#loadDevices()
506
616
  }
507
617
 
@@ -509,16 +619,28 @@ class Inspector {
509
619
  if (!this.#state.activeId) return
510
620
  if (this.#refreshInFlight) return
511
621
  this.#refreshInFlight = true
512
- this.#refreshBtn.disabled = true
622
+ this.#setRefreshButtonDisabled(true)
513
623
 
514
624
  try {
515
- const res = await fetch('/api/inspect')
625
+ const query = new URLSearchParams({ scale: this.#screenshotPane.preferredScreenshotScale() })
626
+ if (this.#shownEtag) {
627
+ query.set('etag', this.#shownEtag)
628
+ }
629
+ const res = await fetch(`/api/inspect?${query}`)
516
630
  if (res.status === 503) return // another inspect in flight, skip this tick — no state changed yet
631
+ if (res.status === 304) {
632
+ // Screenshot, elements and screen are exactly what is already shown; keep hover and selection.
633
+ // Still reset the status, which may show an earlier failed refresh.
634
+ this.#setStatus(`${this.#state.elements.length} elements`)
635
+ this.#consecutiveErrors = 0
636
+ return
637
+ }
517
638
  this.#setStatus('Loading...', 'loading')
518
639
  if (this.#screenshotPane.isScreenshotHidden) {
519
640
  this.#screenshotPane.showPlaceholder('Loading screenshot...', '', true)
520
641
  }
521
642
  if (res.status === 409) {
643
+ this.#shownEtag = null
522
644
  this.#state.activeId = null
523
645
  this.#state.elements = []
524
646
  this.#state.hiddenIndices = new Set()
@@ -551,10 +673,11 @@ class Inspector {
551
673
 
552
674
  this.#state.hiddenIndices = this.#computeHiddenIndices()
553
675
 
554
- this.#screenshotPane.showScreenshot(data.screenshot, this.#state.logicalWidth, this.#state.logicalHeight)
676
+ this.#screenshotPane.showScreenshot(data.screenshot, this.#state.logicalWidth, this.#state.logicalHeight, data.screen?.scale ?? 0)
555
677
  this.#elementsPane.render(this.#state.elements, this.#state.hiddenIndices)
556
678
  this.#screenshotPane.renderHighlights(this.#state.elements, this.#state.hiddenIndices, null)
557
679
  this.#setStatus(`${this.#state.elements.length} elements`)
680
+ this.#shownEtag = data.etag ?? null
558
681
  this.#consecutiveErrors = 0
559
682
  } catch (err) {
560
683
  this.#consecutiveErrors++
@@ -562,13 +685,14 @@ class Inspector {
562
685
  if (this.#screenshotPane.isScreenshotHidden) {
563
686
  this.#screenshotPane.showPlaceholder('Could not load screenshot', err.message)
564
687
  }
565
- if (this.#consecutiveErrors >= Inspector.#MAX_CONSECUTIVE_ERRORS) {
688
+ // A fixed refresh has no toggle to turn it back on, so it keeps retrying instead.
689
+ if (!this.#isContinuousRefresh && this.#consecutiveErrors >= Inspector.#MAX_CONSECUTIVE_ERRORS) {
566
690
  this.#stopAutoRefresh()
567
691
  this.#setStatus(`Auto-refresh stopped after ${this.#consecutiveErrors} consecutive failures`, 'error')
568
692
  }
569
693
  } finally {
570
694
  this.#refreshInFlight = false
571
- this.#refreshBtn.disabled = false
695
+ this.#setRefreshButtonDisabled(false)
572
696
  }
573
697
  }
574
698
 
@@ -593,6 +717,7 @@ class Inspector {
593
717
  if (this.#state.activeId !== prevActiveId) this.#userOverrides.clear()
594
718
  this.#renderDevicePicker()
595
719
  if (prevActiveId && !this.#state.activeId) {
720
+ this.#shownEtag = null
596
721
  this.#state.elements = []
597
722
  this.#state.selectedIndex = null
598
723
  this.#state.hiddenIndices = new Set()
@@ -603,6 +728,8 @@ class Inspector {
603
728
  }
604
729
 
605
730
  #renderDevicePicker() {
731
+ // Every change of activeId re-renders the picker, so this is the one place to report it.
732
+ this.#onActiveDeviceChangeCb?.(this.#state.devices.find(d => d.id === this.#state.activeId) ?? null)
606
733
  const currentIds = [...this.#deviceSelect.options].filter(o => o.value).map(o => o.value)
607
734
  const newIds = this.#state.devices.map(d => d.id)
608
735
  const sameList = currentIds.length === newIds.length && currentIds.every((id, i) => id === newIds[i])
@@ -638,14 +765,16 @@ class Inspector {
638
765
  if (this.#connectInFlight) return
639
766
  this.#connectInFlight = true
640
767
  this.#setStatus('Connecting...', 'loading')
768
+ this.#shownEtag = null
641
769
  this.#screenshotPane.showPlaceholder('Connecting...', device.name ?? device.id, true)
642
- this.#refreshBtn.disabled = true
770
+ this.#setRefreshButtonDisabled(true)
643
771
  this.#deviceSelect.disabled = true
644
772
  try {
645
- const res = await fetch(`/api/devices/${encodeURIComponent(device.id)}/select`, {
773
+ // The server only accepts JSON POSTs (it keeps other sites from driving the device), hence the empty body.
774
+ const res = await fetch(`/api/devices/select?${new URLSearchParams({ device: device.id })}`, {
646
775
  method: 'POST',
647
776
  headers: { 'Content-Type': 'application/json' },
648
- body: JSON.stringify({ platform: device.platform }),
777
+ body: '{}',
649
778
  })
650
779
  if (!res.ok) {
651
780
  const err = await res.json()
@@ -662,7 +791,7 @@ class Inspector {
662
791
  } finally {
663
792
  this.#connectInFlight = false
664
793
  this.#deviceSelect.disabled = false
665
- this.#refreshBtn.disabled = false
794
+ this.#setRefreshButtonDisabled(false)
666
795
  }
667
796
  }
668
797
 
@@ -714,17 +843,39 @@ class Inspector {
714
843
  this.#autoRefreshInterval.disabled = !this.#autoRefreshToggle.checked
715
844
  this.#consecutiveErrors = 0 // reset when user manually reconfigures auto-refresh
716
845
  if (this.#autoRefreshToggle.checked) {
717
- const ms = Number(this.#autoRefreshInterval.value)
718
- this.#autoRefreshTimer = setInterval(async () => {
719
- if (this.#tickInFlight) return
720
- this.#tickInFlight = true
721
- try {
722
- await this.#fetchDevices().catch(() => {})
723
- await this.refresh()
724
- } finally {
725
- this.#tickInFlight = false
726
- }
727
- }, ms)
846
+ this.#startRefreshTimer(Number(this.#autoRefreshInterval.value))
847
+ }
848
+ }
849
+
850
+ // Back-to-back refreshes. A refresh that returns quickly (no device, error, another one
851
+ // in flight) is padded to MIN_FRAME_MS so the loop never spins.
852
+ async #refreshContinuously() {
853
+ for (;;) {
854
+ const startedAt = performance.now()
855
+ await this.refresh()
856
+ const remainingMs = Inspector.#MIN_FRAME_MS - (performance.now() - startedAt)
857
+ if (remainingMs > 0) {
858
+ await new Promise(resolve => setTimeout(resolve, remainingMs))
859
+ }
860
+ }
861
+ }
862
+
863
+ #startRefreshTimer(ms) {
864
+ this.#autoRefreshTimer = setInterval(async () => {
865
+ if (this.#tickInFlight) return
866
+ this.#tickInFlight = true
867
+ try {
868
+ await this.#fetchDevices().catch(() => {})
869
+ await this.refresh()
870
+ } finally {
871
+ this.#tickInFlight = false
872
+ }
873
+ }, ms)
874
+ }
875
+
876
+ #setRefreshButtonDisabled(isDisabled) {
877
+ if (this.#refreshBtn) {
878
+ this.#refreshBtn.disabled = isDisabled
728
879
  }
729
880
  }
730
881
 
@@ -744,7 +895,7 @@ class Inspector {
744
895
 
745
896
  // ---- Theme ----
746
897
 
747
- function applyTheme(name) {
898
+ export function applyTheme(name) {
748
899
  document.documentElement.setAttribute('data-theme', name)
749
900
  localStorage.setItem('mobilewright-inspector-theme', name)
750
901
  const sel = document.getElementById('theme-select')
@@ -759,12 +910,16 @@ const KEYBOARD_RESIZE_STEP = 16
759
910
 
760
911
  // direction: 1 when the pane is left of its splitter, -1 when right of it.
761
912
  // CSS min/max-width on the pane does the clamping.
762
- function makeResizable(splitter, pane, cssVar, direction) {
913
+ // axis: 'x' resizes the pane's width (vertical splitter), 'y' its height (horizontal splitter).
914
+ export function makeResizable(splitter, pane, cssVar, direction, axis = 'x') {
763
915
  const main = splitter.parentElement
764
916
  const storageKey = 'mobilewright-inspector' + cssVar
917
+ const isVertical = axis === 'y'
918
+ const paneSize = () => isVertical ? pane.offsetHeight : pane.offsetWidth
919
+ const pointerPos = ev => isVertical ? ev.clientY : ev.clientX
765
920
  const setWidth = px => {
766
921
  main.style.setProperty(cssVar, px + 'px')
767
- localStorage.setItem(storageKey, pane.offsetWidth)
922
+ localStorage.setItem(storageKey, paneSize())
768
923
  }
769
924
 
770
925
  const saved = localStorage.getItem(storageKey)
@@ -776,9 +931,9 @@ function makeResizable(splitter, pane, cssVar, direction) {
776
931
  e.preventDefault()
777
932
  splitter.setPointerCapture(e.pointerId)
778
933
  splitter.classList.add('dragging')
779
- const startX = e.clientX
780
- const startWidth = pane.offsetWidth
781
- const onMove = ev => setWidth(startWidth + (ev.clientX - startX) * direction)
934
+ const startPos = pointerPos(e)
935
+ const startSize = paneSize()
936
+ const onMove = ev => setWidth(startSize + (pointerPos(ev) - startPos) * direction)
782
937
  splitter.addEventListener('pointermove', onMove)
783
938
  splitter.addEventListener('lostpointercapture', () => {
784
939
  splitter.removeEventListener('pointermove', onMove)
@@ -787,18 +942,11 @@ function makeResizable(splitter, pane, cssVar, direction) {
787
942
  })
788
943
 
789
944
  splitter.addEventListener('keydown', e => {
790
- const step = { ArrowLeft: -KEYBOARD_RESIZE_STEP, ArrowRight: KEYBOARD_RESIZE_STEP }[e.key]
945
+ const keys = isVertical ? { ArrowUp: -KEYBOARD_RESIZE_STEP, ArrowDown: KEYBOARD_RESIZE_STEP } : { ArrowLeft: -KEYBOARD_RESIZE_STEP, ArrowRight: KEYBOARD_RESIZE_STEP }
946
+ const step = keys[e.key]
791
947
  if (step) {
792
948
  e.preventDefault()
793
- setWidth(pane.offsetWidth + step * direction)
949
+ setWidth(paneSize() + step * direction)
794
950
  }
795
951
  })
796
952
  }
797
-
798
- makeResizable(document.getElementById('screenshot-splitter'), document.getElementById('screenshot-pane'), '--screenshot-width', 1)
799
- makeResizable(document.getElementById('detail-splitter'), document.getElementById('detail-pane'), '--detail-width', -1)
800
-
801
- // ---- Bootstrap ----
802
-
803
- applyTheme(localStorage.getItem('mobilewright-inspector-theme') || 'void')
804
- new Inspector()