section-hint.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { getBoundingBoxByverticalNote } from '/src/pages/detail/helpers'
  2. import SettingState from '/src/pages/detail/setting-state'
  3. import { formatZoom } from './utils'
  4. export default class SectionHint {
  5. constructor() {
  6. // this.parentEl = parentEl || document.body
  7. this.init()
  8. }
  9. currentNote = null
  10. // parentEl = document.body
  11. el = document.createElement('div')
  12. span = document.createElement('span')
  13. init() {
  14. this.el.id = 'section-hint' + Math.floor(Math.random() * 100000)
  15. this.hide()
  16. // console.log(this.parentEl)
  17. // this.parentEl.appendChild(this.el)
  18. }
  19. showForElement(currentNote: any) {
  20. if (this.currentNote === currentNote) {
  21. return
  22. }
  23. if (!this.el) {
  24. this.el = document.createElement('div')
  25. this.init()
  26. this.show()
  27. }
  28. this.currentNote = currentNote
  29. const stave = getBoundingBoxByverticalNote(currentNote)
  30. const container = document.querySelector('#osmdSvgPage1')
  31. if (stave) {
  32. const { x, y, width, height } = stave
  33. this.el.id = 'custom-cursor-bg-hint'
  34. this.el.style.position = 'absolute'
  35. this.el.style.top = formatZoom(y) + 'px'
  36. this.el.style.left = formatZoom(x) + 'px'
  37. this.el.style.width = formatZoom(width) + 'px'
  38. this.el.style.height = formatZoom(height) + 'px'
  39. this.el.style.zIndex = '-1'
  40. // currentNote.osdmContext?.cursor?.container.appendChild(this.el)
  41. container?.parentNode?.appendChild(this.el)
  42. }
  43. }
  44. hide() {
  45. this.el.style.display = 'none'
  46. }
  47. show() {
  48. this.el.style.display = ''
  49. }
  50. destroy() {
  51. this.currentNote = null
  52. this.hide()
  53. // this.el.remove()
  54. }
  55. }
  56. export interface ISectionHint {
  57. el: HTMLDivElement
  58. init: () => void
  59. hide: () => void
  60. show: () => void
  61. destroy: () => void
  62. showForElement: (currentNote: any) => void
  63. }