TextPage.vue 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  1. <template>
  2. <div ref="main" class="main">
  3. <div v-show="toggleLayout" class="layout">
  4. <div v-html="page1"></div>
  5. </div>
  6. <div v-show="!toggleLayout" class="layout">
  7. <div v-html="page2"></div>
  8. </div>
  9. <div v-show="showStatusBar" ref="statusBar" class="layout">
  10. <div v-html="statusBar"></div>
  11. </div>
  12. <div ref="layoutEvents" class="layout events" @mousedown.prevent.stop="onMouseDown" @mouseup.prevent.stop="onMouseUp"
  13. @wheel.prevent.stop="onMouseWheel"
  14. @touchstart.stop="onTouchStart" @touchend.stop="onTouchEnd" @touchcancel.prevent.stop="onTouchCancel"
  15. oncontextmenu="return false;">
  16. <div v-show="showStatusBar" v-html="statusBarClickable" @mousedown.prevent.stop @touchstart.stop
  17. @click.prevent.stop="onStatusBarClick"></div>
  18. <div v-show="fontsLoading" ref="fontsLoading"></div>
  19. </div>
  20. <!-- невидимым делать нельзя, вовремя не подгружаютя шрифты -->
  21. <canvas ref="offscreenCanvas" class="layout" style="width: 0px; height: 0px"></canvas>
  22. </div>
  23. </template>
  24. <script>
  25. //-----------------------------------------------------------------------------
  26. import Vue from 'vue';
  27. import Component from 'vue-class-component';
  28. import {loadCSS} from 'fg-loadcss';
  29. import _ from 'lodash';
  30. import {sleep} from '../../../share/utils';
  31. import bookManager from '../share/bookManager';
  32. import DrawHelper from './DrawHelper';
  33. const minLayoutWidth = 100;
  34. export default @Component({
  35. watch: {
  36. bookPos: function(newValue) {
  37. this.debouncedEmitPosChange(newValue);
  38. this.draw();
  39. },
  40. },
  41. })
  42. class TextPage extends Vue {
  43. toggleLayout = false;
  44. showStatusBar = false;
  45. page1 = null;
  46. page2 = null;
  47. statusBar = null;
  48. statusBarClickable = null;
  49. fontsLoading = null;
  50. lastBook = null;
  51. bookPos = 0;
  52. fontStyle = null;
  53. fontSize = null;
  54. fontName = null;
  55. meta = null;
  56. created() {
  57. this.drawHelper = new DrawHelper();
  58. this.commit = this.$store.commit;
  59. this.dispatch = this.$store.dispatch;
  60. this.config = this.$store.state.config;
  61. this.reader = this.$store.state.reader;
  62. this.debouncedEmitPosChange = _.debounce((newValue) => {
  63. this.$emit('book-pos-changed', {bookPos: newValue, bookPosSeen: this.bookPosSeen});
  64. }, 1000);
  65. this.debouncedStartClickRepeat = _.debounce((x, y) => {
  66. this.startClickRepeat(x, y);
  67. }, 800);
  68. this.debouncedPrepareNextPage = _.debounce(() => {
  69. this.prepareNextPage();
  70. }, 100);
  71. this.debouncedDrawStatusBar = _.throttle(() => {
  72. this.drawStatusBar();
  73. }, 60);
  74. this.$root.$on('resize', () => {this.$nextTick(this.onResize)});
  75. this.mobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent);
  76. }
  77. mounted() {
  78. this.context = this.$refs.offscreenCanvas.getContext('2d');
  79. }
  80. hex2rgba(hex, alpha = 1) {
  81. const [r, g, b] = hex.match(/\w\w/g).map(x => parseInt(x, 16));
  82. return `rgba(${r},${g},${b},${alpha})`;
  83. }
  84. calcDrawProps() {
  85. //preloaded fonts
  86. this.fontShifts = {//%
  87. ReaderDefault: 0,
  88. Roboto: 0,
  89. OpenSans: 0,
  90. Rubik: 0,
  91. Avrile: -10,
  92. Arimo: 0,
  93. GEO_1: 10,
  94. }
  95. if (!this.fontShifts.hasOwnProperty(this.fontName))
  96. this.fontShifts[this.fontName] = this.fontVertShift;
  97. this.fontList = [];
  98. for (let fontName in this.fontShifts)
  99. this.fontList.push(`12px ${fontName}`);
  100. //widths
  101. this.realWidth = this.$refs.main.clientWidth;
  102. this.realHeight = this.$refs.main.clientHeight;
  103. this.$refs.layoutEvents.style.width = this.realWidth + 'px';
  104. this.$refs.layoutEvents.style.height = this.realHeight + 'px';
  105. this.w = this.realWidth - 2*this.indent;
  106. this.h = this.realHeight - (this.showStatusBar ? this.statusBarHeight : 0);
  107. this.lineHeight = this.fontSize + this.lineInterval;
  108. this.pageLineCount = Math.floor(this.h/this.lineHeight);
  109. if (this.parsed) {
  110. this.parsed.p = this.p;
  111. this.parsed.w = this.w;// px, ширина текста
  112. this.parsed.font = this.font;
  113. this.parsed.wordWrap = this.wordWrap;
  114. let t = '';
  115. while (this.measureText(t, {}) < this.w) t += 'Щ';
  116. this.parsed.maxWordLength = t.length - 1;
  117. this.parsed.measureText = this.measureText;
  118. }
  119. //сообщение "Загрузка шрифтов..."
  120. const flText = 'Загрузка шрифта...';
  121. this.$refs.fontsLoading.innerHTML = flText;
  122. const fontsLoadingStyle = this.$refs.fontsLoading.style;
  123. fontsLoadingStyle.position = 'absolute';
  124. fontsLoadingStyle.fontSize = this.fontSize + 'px';
  125. fontsLoadingStyle.top = (this.realHeight/2 - 2*this.fontSize) + 'px';
  126. fontsLoadingStyle.left = (this.realWidth - this.measureText(flText, {}))/2 + 'px';
  127. //stuff
  128. this.statusBarColor = this.hex2rgba(this.textColor, this.statusBarColorAlpha);
  129. this.currentTransition = '';
  130. this.pageChangeDirectionDown = true;
  131. this.fontShift = (this.fontShifts[this.fontName] ? this.fontShifts[this.fontName] : 0)/100;
  132. //drawHelper
  133. this.drawHelper.realWidth = this.realWidth;
  134. this.drawHelper.realHeight = this.realHeight;
  135. this.drawHelper.backgroundColor = this.backgroundColor;
  136. this.drawHelper.statusBarColor = this.statusBarColor;
  137. this.drawHelper.fontName = this.fontName;
  138. this.drawHelper.fontShift = this.fontShift;
  139. this.drawHelper.measureText = this.measureText;
  140. this.drawHelper.measureTextFont = this.measureTextFont;
  141. this.$refs.statusBar.style.left = '0px';
  142. this.$refs.statusBar.style.top = (this.statusBarTop ? 1 : this.realHeight - this.statusBarHeight) + 'px';
  143. this.statusBarClickable = this.drawHelper.statusBarClickable(this.statusBarTop, this.statusBarHeight);
  144. }
  145. measureText(text, style) {// eslint-disable-line no-unused-vars
  146. this.context.font = this.fontByStyle(style);
  147. return this.context.measureText(text).width;
  148. }
  149. measureTextFont(text, font) {// eslint-disable-line no-unused-vars
  150. this.context.font = font;
  151. return this.context.measureText(text).width;
  152. }
  153. async checkLoadedFonts() {
  154. let loaded = await Promise.all(this.fontList.map(font => document.fonts.check(font)));
  155. if (loaded.some(r => !r)) {
  156. loaded = await Promise.all(this.fontList.map(font => document.fonts.load(font)));
  157. if (loaded.some(r => !r.length))
  158. throw new Error('some font not loaded');
  159. }
  160. }
  161. async loadFonts() {
  162. this.fontsLoading = true;
  163. if (!this.fontsLoaded)
  164. this.fontsLoaded = {};
  165. //загрузка дин.шрифта
  166. const loaded = this.fontsLoaded[this.fontCssUrl];
  167. if (this.fontCssUrl && !loaded) {
  168. loadCSS(this.fontCssUrl);
  169. this.fontsLoaded[this.fontCssUrl] = 1;
  170. }
  171. const waitingTime = 10*1000;
  172. const delay = 100;
  173. let i = 0;
  174. //ждем шрифты
  175. while (i < waitingTime/delay) {
  176. i++;
  177. try {
  178. await this.checkLoadedFonts();
  179. i = waitingTime;
  180. } catch (e) {
  181. await sleep(delay);
  182. }
  183. }
  184. if (i !== waitingTime) {
  185. this.$notify.error({
  186. title: 'Ошибка загрузки',
  187. message: 'Некоторые шрифты не удалось загрузить'
  188. });
  189. }
  190. this.fontsLoading = false;
  191. }
  192. showBook() {
  193. this.$refs.main.focus();
  194. this.toggleLayout = false;
  195. this.book = null;
  196. this.meta = null;
  197. this.fb2 = null;
  198. this.parsed = null;
  199. this.linesUp = null;
  200. this.linesDown = null;
  201. //default draw props
  202. this.textColor = '#000000';
  203. this.backgroundColor = '#478355';
  204. this.fontStyle = '';// 'bold','italic'
  205. this.fontSize = 36;// px
  206. this.fontName = 'GEO_1';
  207. this.fontCssUrl = '';
  208. this.fontVertShift = 0;
  209. this.lineInterval = 6;// px, межстрочный интервал
  210. this.textAlignJustify = true;// выравнивание по ширине
  211. this.p = 50;// px, отступ параграфа
  212. this.indent = 15;// px, отступ всего текста слева и справа
  213. this.wordWrap = true;
  214. this.keepLastToFirst = true;// перенос последней строки в первую при листании
  215. this.showStatusBar = true;
  216. this.statusBarTop = false;// top, bottom
  217. this.statusBarHeight = 19;// px
  218. this.statusBarColorAlpha = 0.4;
  219. this.pageChangeTransition = '';// '' - нет, downShift, rightShift, thaw - протаивание, blink - мерцание
  220. this.pageChangeTransitionSpeed = 50; //0-100%
  221. this.calcDrawProps();
  222. this.draw();// пока не загрузили, очистим канвас
  223. if (this.lastBook) {
  224. (async() => {
  225. const isParsed = await bookManager.hasBookParsed(this.lastBook);
  226. if (!isParsed) {
  227. return;
  228. }
  229. this.book = await bookManager.getBook(this.lastBook);
  230. this.meta = bookManager.metaOnly(this.book);
  231. this.fb2 = this.meta.fb2;
  232. const authorName = _.compact([
  233. this.fb2.lastName,
  234. this.fb2.firstName,
  235. this.fb2.middleName
  236. ]).join(' ');
  237. this.title = _.compact([
  238. authorName,
  239. this.fb2.bookTitle
  240. ]).join(' - ');
  241. this.$root.$emit('set-app-title', this.title);
  242. this.parsed = this.book.parsed;
  243. this.calcDrawProps();
  244. await this.loadFonts();
  245. //this.draw();
  246. // шрифты хрен знает когда подгружаются, поэтому
  247. let i = 0;
  248. this.parsed.force = true;
  249. while (i < 10) {
  250. this.draw();
  251. await sleep(1000);
  252. i++;
  253. }
  254. this.parsed.force = false;
  255. this.refreshTime();
  256. })();
  257. }
  258. }
  259. onResize() {
  260. this.calcDrawProps();
  261. this.draw();
  262. }
  263. get font() {
  264. return `${this.fontStyle} ${this.fontSize}px ${this.fontName}`;
  265. }
  266. fontByStyle(style) {
  267. return `${style.italic ? 'italic' : ''} ${style.bold ? 'bold' : ''} ${this.fontSize}px ${this.fontName}`;
  268. }
  269. draw() {
  270. if (this.w < minLayoutWidth) {
  271. this.page1 = null;
  272. this.page2 = null;
  273. this.statusBar = null;
  274. return;
  275. }
  276. if (this.book && this.bookPos > 0 && this.bookPos >= this.parsed.textLength) {
  277. this.doEnd();
  278. return;
  279. }
  280. this.toggleLayout = !this.toggleLayout;
  281. if (this.pageChangeDirectionDown && this.pagePrepared && this.bookPos == this.bookPosPrepared) {
  282. this.linesDown = this.linesDownNext;
  283. this.linesUp = this.linesUpNext;
  284. } else {
  285. if (this.toggleLayout)
  286. this.page1 = this.drawPage(this.bookPos);
  287. else
  288. this.page2 = this.drawPage(this.bookPos);
  289. }
  290. if (this.currentTransition) {
  291. //this.currentTransition
  292. //this.pageChangeTransitionSpeed
  293. //this.pageChangeDirectionDown
  294. //curr to next transition
  295. //пока заглушка
  296. }
  297. this.currentTransition = '';
  298. this.pageChangeDirectionDown = false;//true только если PgDown
  299. this.pagePrepared = false;
  300. this.debouncedPrepareNextPage();
  301. this.debouncedDrawStatusBar();
  302. }
  303. drawPage(bookPos, nextChangeLines) {
  304. if (!this.lastBook)
  305. return;
  306. let out = `<div class="layout" style="width: ${this.realWidth}px; height: ${this.realHeight}px;` +
  307. ` color: ${this.textColor}; background-color: ${this.backgroundColor}">`;
  308. if (!this.book || !this.parsed.textLength) {
  309. out += '</div>';
  310. return out;
  311. }
  312. const spaceWidth = this.measureText(' ', {});
  313. const lines = this.parsed.getLines(bookPos, 2*this.pageLineCount);
  314. if (!nextChangeLines) {
  315. this.linesDown = lines;
  316. this.linesUp = this.parsed.getLines(bookPos, -2*this.pageLineCount);
  317. } else {
  318. this.linesDownNext = lines;
  319. this.linesUpNext = this.parsed.getLines(bookPos, -2*this.pageLineCount);
  320. }
  321. let y = -this.lineInterval/2 + (this.h - this.pageLineCount*this.lineHeight)/2 + this.fontSize*this.fontShift;
  322. if (this.showStatusBar)
  323. y += this.statusBarHeight*(this.statusBarTop ? 1 : 0);
  324. let len = lines.length;
  325. len = (len > this.pageLineCount ? len = this.pageLineCount : len);
  326. for (let i = 0; i < len; i++) {
  327. const line = lines[i];
  328. /* line:
  329. {
  330. begin: Number,
  331. end: Number,
  332. first: Boolean,
  333. last: Boolean,
  334. parts: array of {
  335. style: {bold: Boolean, italic: Boolean, center: Boolean}
  336. text: String,
  337. }
  338. }*/
  339. let indent = this.indent + (line.first ? this.p : 0);
  340. let lineText = '';
  341. let center = false;
  342. let centerStyle = {};
  343. for (const part of line.parts) {
  344. lineText += part.text;
  345. center = center || part.style.center;
  346. if (part.style.center)
  347. centerStyle = part.style.center;
  348. }
  349. let filled = false;
  350. // если выравнивание по ширине включено
  351. if (this.textAlignJustify && !line.last && !center) {
  352. const words = lineText.split(' ');
  353. if (words.length > 1) {
  354. const spaceCount = words.length - 1;
  355. const space = (this.w - line.width + spaceWidth*spaceCount)/spaceCount;
  356. let x = indent;
  357. for (const part of line.parts) {
  358. const font = this.fontByStyle(part.style);
  359. let partWords = part.text.split(' ');
  360. for (let i = 0; i < partWords.length; i++) {
  361. let word = partWords[i];
  362. out += this.drawHelper.fillText(word, x, y, font);
  363. x += this.measureText(word, part.style) + (i < partWords.length - 1 ? space : 0);
  364. }
  365. }
  366. filled = true;
  367. }
  368. }
  369. // просто выводим текст
  370. if (!filled) {
  371. let x = indent;
  372. x = (center ? this.indent + (this.w - this.measureText(lineText, centerStyle))/2 : x);
  373. for (const part of line.parts) {
  374. let text = part.text;
  375. const font = this.fontByStyle(part.style);
  376. out += this.drawHelper.fillText(text, x, y, font);
  377. x += this.measureText(text, part.style);
  378. }
  379. }
  380. y += this.lineHeight;
  381. }
  382. out += '</div>';
  383. return out;
  384. }
  385. drawStatusBar() {
  386. if (this.w < minLayoutWidth) {
  387. this.statusBar = null;
  388. return;
  389. }
  390. if (this.showStatusBar && this.linesDown) {
  391. const lines = this.linesDown;
  392. let i = this.pageLineCount;
  393. if (this.keepLastToFirst)
  394. i--;
  395. i = (i > lines.length - 1 ? lines.length - 1 : i);
  396. if (i >= 0) {
  397. let message = this.statusBarMessage;
  398. if (!message)
  399. message = this.title;
  400. this.statusBar = this.drawHelper.drawStatusBar(this.statusBarTop, this.statusBarHeight,
  401. lines[i].end, this.parsed.textLength, message);
  402. this.bookPosSeen = lines[i].end;
  403. }
  404. }
  405. }
  406. blinkCachedLoadMessage(state) {
  407. if (state === 'finish') {
  408. this.statusBarMessage = '';
  409. } else if (state) {
  410. this.statusBarMessage = 'Книга загружена из кеша';
  411. } else {
  412. this.statusBarMessage = ' ';
  413. }
  414. this.drawStatusBar();
  415. }
  416. async refreshTime() {
  417. if (!this.timeRefreshing) {
  418. this.timeRefreshing = true;
  419. await sleep(60*1000);
  420. if (this.book && this.parsed.textLength) {
  421. this.debouncedDrawStatusBar();
  422. }
  423. this.timeRefreshing = false;
  424. this.refreshTime();
  425. }
  426. }
  427. prepareNextPage() {
  428. // подготовка следующей страницы заранее
  429. if (!this.book || !this.parsed.textLength || !this.linesDown)
  430. return;
  431. if (!this.preparing) {
  432. this.preparing = true;
  433. (async() => {
  434. await sleep(100);
  435. if (this.cancelPrepare) {
  436. this.preparing = false;
  437. return;
  438. }
  439. let i = this.pageLineCount;
  440. if (this.keepLastToFirst)
  441. i--;
  442. if (i >= 0 && this.linesDown.length > i) {
  443. this.bookPosPrepared = this.linesDown[i].begin;
  444. if (this.toggleLayout)
  445. this.page2 = this.drawPage(this.bookPosPrepared, true);//наоборот
  446. else
  447. this.page1 = this.drawPage(this.bookPosPrepared, true);
  448. this.pagePrepared = true;
  449. }
  450. this.preparing = false;
  451. })();
  452. }
  453. }
  454. doDown() {
  455. if (this.linesDown && this.linesDown.length > this.pageLineCount) {
  456. this.bookPos = this.linesDown[1].begin;
  457. }
  458. }
  459. doUp() {
  460. if (this.linesUp && this.linesUp.length > 1) {
  461. this.bookPos = this.linesUp[1].begin;
  462. }
  463. }
  464. doPageDown() {
  465. if (this.linesDown) {
  466. let i = this.pageLineCount;
  467. if (this.keepLastToFirst)
  468. i--;
  469. if (i >= 0 && this.linesDown.length >= 2*i) {
  470. this.currentTransition = this.pageChangeTransition;
  471. this.pageChangeDirectionDown = true;
  472. this.bookPos = this.linesDown[i].begin;
  473. } else
  474. this.doEnd();
  475. }
  476. }
  477. doPageUp() {
  478. if (this.linesUp) {
  479. let i = this.pageLineCount;
  480. if (this.keepLastToFirst)
  481. i--;
  482. i = (i > this.linesUp.length - 1 ? this.linesUp.length - 1 : i);
  483. if (i >= 0 && this.linesUp.length > i) {
  484. this.currentTransition = this.pageChangeTransition;
  485. this.pageChangeDirectionDown = false;
  486. this.bookPos = this.linesUp[i].begin;
  487. }
  488. }
  489. }
  490. doHome() {
  491. this.bookPos = 0;
  492. }
  493. doEnd() {
  494. if (this.parsed.para.length) {
  495. let i = this.parsed.para.length - 1;
  496. let lastPos = this.parsed.para[i].offset + this.parsed.para[i].length - 1;
  497. const lines = this.parsed.getLines(lastPos, -this.pageLineCount);
  498. i = this.pageLineCount - 1;
  499. i = (i > lines.length - 1 ? lines.length - 1 : i);
  500. this.bookPos = lines[i].begin;
  501. }
  502. }
  503. doToolBarToggle() {
  504. this.$emit('tool-bar-toggle');
  505. }
  506. keyHook(event) {
  507. //console.log(event.code);
  508. if (event.type == 'keydown') {
  509. switch (event.code) {
  510. case 'ArrowDown':
  511. this.doDown();
  512. break;
  513. case 'ArrowUp':
  514. this.doUp();
  515. break;
  516. case 'PageDown':
  517. case 'ArrowRight':
  518. case 'Space':
  519. this.doPageDown();
  520. break;
  521. case 'PageUp':
  522. case 'ArrowLeft':
  523. case 'Backspace':
  524. this.doPageUp();
  525. break;
  526. case 'Home':
  527. this.doHome();
  528. break;
  529. case 'End':
  530. this.doEnd();
  531. break;
  532. case 'Enter':
  533. case 'Backquote'://`
  534. case 'KeyF':
  535. if (this.fullScreenToggle)
  536. this.fullScreenToggle();
  537. break;
  538. case 'Tab':
  539. this.doToolBarToggle();
  540. event.preventDefault();
  541. event.stopPropagation();
  542. break;
  543. }
  544. }
  545. }
  546. async startClickRepeat(pointX, pointY) {
  547. this.repX = pointX;
  548. this.repY = pointY;
  549. if (!this.repInit && this.repDoing) {
  550. this.repInit = true;
  551. let delay = 400;
  552. while (this.repDoing) {
  553. this.handleClick(pointX, pointY);
  554. await sleep(delay);
  555. if (delay > 15)
  556. delay *= 0.8;
  557. }
  558. this.repInit = false;
  559. }
  560. }
  561. endClickRepeat() {
  562. this.repDoing = false;
  563. }
  564. onTouchStart(event) {
  565. if (!this.mobile)
  566. return;
  567. this.endClickRepeat();
  568. if (event.touches.length == 1) {
  569. const touch = event.touches[0];
  570. const rect = event.target.getBoundingClientRect();
  571. const x = touch.pageX - rect.left;
  572. const y = touch.pageY - rect.top;
  573. if (this.handleClick(x, y)) {
  574. this.repDoing = true;
  575. this.debouncedStartClickRepeat(x, y);
  576. }
  577. }
  578. }
  579. onTouchEnd() {
  580. if (!this.mobile)
  581. return;
  582. this.endClickRepeat();
  583. }
  584. onTouchCancel() {
  585. if (!this.mobile)
  586. return;
  587. this.endClickRepeat();
  588. }
  589. onMouseDown(event) {
  590. if (this.mobile)
  591. return;
  592. this.endClickRepeat();
  593. if (event.button == 0) {
  594. if (this.handleClick(event.offsetX, event.offsetY)) {
  595. this.repDoing = true;
  596. this.debouncedStartClickRepeat(event.offsetX, event.offsetY);
  597. }
  598. } else if (event.button == 2) {
  599. this.doToolBarToggle();
  600. }
  601. }
  602. onMouseUp() {
  603. if (this.mobile)
  604. return;
  605. this.endClickRepeat();
  606. }
  607. onMouseWheel(event) {
  608. if (this.mobile)
  609. return;
  610. if (event.deltaY > 0) {
  611. this.doDown();
  612. } else if (event.deltaY < 0) {
  613. this.doUp();
  614. }
  615. }
  616. onStatusBarClick() {
  617. window.open(this.meta.url, '_blank');
  618. }
  619. handleClick(pointX, pointY) {
  620. const mouseLegend = {
  621. 40: {30: 'PgUp', 100: 'PgDown'},
  622. 60: {40: 'Up', 60: 'Menu', 100: 'Down'},
  623. 100: {30: 'PgUp', 100: 'PgDown'}
  624. };
  625. const w = pointX/this.realWidth*100;
  626. const h = pointY/this.realHeight*100;
  627. let action = '';
  628. loops: {
  629. for (const x in mouseLegend) {
  630. for (const y in mouseLegend[x]) {
  631. if (w < x && h < y) {
  632. action = mouseLegend[x][y];
  633. break loops;
  634. }
  635. }
  636. }
  637. }
  638. switch (action) {
  639. case 'Down' ://Down
  640. this.doDown();
  641. break;
  642. case 'Up' ://Up
  643. this.doUp();
  644. break;
  645. case 'PgDown' ://PgDown
  646. this.doPageDown();
  647. break;
  648. case 'PgUp' ://PgUp
  649. this.doPageUp();
  650. break;
  651. case 'Menu' :
  652. this.doToolBarToggle();
  653. break;
  654. default :
  655. // Nothing
  656. }
  657. return (action && action != 'Menu');
  658. }
  659. }
  660. //-----------------------------------------------------------------------------
  661. </script>
  662. <style scoped>
  663. .main {
  664. flex: 1;
  665. margin: 0;
  666. padding: 0;
  667. overflow: hidden;
  668. position: relative;
  669. min-width: 200px;
  670. }
  671. .layout {
  672. margin: 0;
  673. padding: 0;
  674. position: absolute;
  675. z-index: 10;
  676. }
  677. .events {
  678. z-index: 20;
  679. background-color: rgba(0,0,0,0);
  680. }
  681. </style>