TextPage.vue 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  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. if (this.book && this.linesDown && this.linesDown.length < this.pageLineCount)
  303. this.doEnd();
  304. }
  305. drawPage(bookPos, nextChangeLines) {
  306. if (!this.lastBook)
  307. return;
  308. let out = `<div class="layout" style="width: ${this.realWidth}px; height: ${this.realHeight}px;` +
  309. ` color: ${this.textColor}; background-color: ${this.backgroundColor}">`;
  310. if (!this.book || !this.parsed.textLength) {
  311. out += '</div>';
  312. return out;
  313. }
  314. const spaceWidth = this.measureText(' ', {});
  315. const lines = this.parsed.getLines(bookPos, 2*this.pageLineCount);
  316. if (!nextChangeLines) {
  317. this.linesDown = lines;
  318. this.linesUp = this.parsed.getLines(bookPos, -2*this.pageLineCount);
  319. } else {
  320. this.linesDownNext = lines;
  321. this.linesUpNext = this.parsed.getLines(bookPos, -2*this.pageLineCount);
  322. }
  323. let y = -this.lineInterval/2 + (this.h - this.pageLineCount*this.lineHeight)/2 + this.fontSize*this.fontShift;
  324. if (this.showStatusBar)
  325. y += this.statusBarHeight*(this.statusBarTop ? 1 : 0);
  326. let len = lines.length;
  327. len = (len > this.pageLineCount ? len = this.pageLineCount : len);
  328. for (let i = 0; i < len; i++) {
  329. const line = lines[i];
  330. /* line:
  331. {
  332. begin: Number,
  333. end: Number,
  334. first: Boolean,
  335. last: Boolean,
  336. parts: array of {
  337. style: {bold: Boolean, italic: Boolean, center: Boolean}
  338. text: String,
  339. }
  340. }*/
  341. let indent = this.indent + (line.first ? this.p : 0);
  342. let lineText = '';
  343. let center = false;
  344. let centerStyle = {};
  345. for (const part of line.parts) {
  346. lineText += part.text;
  347. center = center || part.style.center;
  348. if (part.style.center)
  349. centerStyle = part.style.center;
  350. }
  351. let filled = false;
  352. // если выравнивание по ширине включено
  353. if (this.textAlignJustify && !line.last && !center) {
  354. const words = lineText.split(' ');
  355. if (words.length > 1) {
  356. const spaceCount = words.length - 1;
  357. const space = (this.w - line.width + spaceWidth*spaceCount)/spaceCount;
  358. let x = indent;
  359. for (const part of line.parts) {
  360. const font = this.fontByStyle(part.style);
  361. let partWords = part.text.split(' ');
  362. for (let i = 0; i < partWords.length; i++) {
  363. let word = partWords[i];
  364. out += this.drawHelper.fillText(word, x, y, font);
  365. x += this.measureText(word, part.style) + (i < partWords.length - 1 ? space : 0);
  366. }
  367. }
  368. filled = true;
  369. }
  370. }
  371. // просто выводим текст
  372. if (!filled) {
  373. let x = indent;
  374. x = (center ? this.indent + (this.w - this.measureText(lineText, centerStyle))/2 : x);
  375. for (const part of line.parts) {
  376. let text = part.text;
  377. const font = this.fontByStyle(part.style);
  378. out += this.drawHelper.fillText(text, x, y, font);
  379. x += this.measureText(text, part.style);
  380. }
  381. }
  382. y += this.lineHeight;
  383. }
  384. out += '</div>';
  385. return out;
  386. }
  387. drawStatusBar() {
  388. if (this.w < minLayoutWidth) {
  389. this.statusBar = null;
  390. return;
  391. }
  392. if (this.showStatusBar && this.linesDown) {
  393. const lines = this.linesDown;
  394. let i = this.pageLineCount;
  395. if (this.keepLastToFirst)
  396. i--;
  397. i = (i > lines.length - 1 ? lines.length - 1 : i);
  398. if (i >= 0) {
  399. let message = this.statusBarMessage;
  400. if (!message)
  401. message = this.title;
  402. this.statusBar = this.drawHelper.drawStatusBar(this.statusBarTop, this.statusBarHeight,
  403. lines[i].end, this.parsed.textLength, message);
  404. this.bookPosSeen = lines[i].end;
  405. }
  406. }
  407. }
  408. blinkCachedLoadMessage(state) {
  409. if (state === 'finish') {
  410. this.statusBarMessage = '';
  411. } else if (state) {
  412. this.statusBarMessage = 'Книга загружена из кеша';
  413. } else {
  414. this.statusBarMessage = ' ';
  415. }
  416. this.drawStatusBar();
  417. }
  418. async refreshTime() {
  419. if (!this.timeRefreshing) {
  420. this.timeRefreshing = true;
  421. await sleep(60*1000);
  422. if (this.book && this.parsed.textLength) {
  423. this.debouncedDrawStatusBar();
  424. }
  425. this.timeRefreshing = false;
  426. this.refreshTime();
  427. }
  428. }
  429. prepareNextPage() {
  430. // подготовка следующей страницы заранее
  431. if (!this.book || !this.parsed.textLength || !this.linesDown)
  432. return;
  433. if (!this.preparing) {
  434. this.preparing = true;
  435. (async() => {
  436. await sleep(100);
  437. if (this.cancelPrepare) {
  438. this.preparing = false;
  439. return;
  440. }
  441. let i = this.pageLineCount;
  442. if (this.keepLastToFirst)
  443. i--;
  444. if (i >= 0 && this.linesDown.length > i) {
  445. this.bookPosPrepared = this.linesDown[i].begin;
  446. if (this.toggleLayout)
  447. this.page2 = this.drawPage(this.bookPosPrepared, true);//наоборот
  448. else
  449. this.page1 = this.drawPage(this.bookPosPrepared, true);
  450. this.pagePrepared = true;
  451. }
  452. this.preparing = false;
  453. })();
  454. }
  455. }
  456. doDown() {
  457. if (this.linesDown && this.linesDown.length > this.pageLineCount) {
  458. this.bookPos = this.linesDown[1].begin;
  459. }
  460. }
  461. doUp() {
  462. if (this.linesUp && this.linesUp.length > 1) {
  463. this.bookPos = this.linesUp[1].begin;
  464. }
  465. }
  466. doPageDown() {
  467. if (this.linesDown) {
  468. let i = this.pageLineCount;
  469. if (this.keepLastToFirst)
  470. i--;
  471. if (i >= 0 && this.linesDown.length >= 2*i) {
  472. this.currentTransition = this.pageChangeTransition;
  473. this.pageChangeDirectionDown = true;
  474. this.bookPos = this.linesDown[i].begin;
  475. } else
  476. this.doEnd();
  477. }
  478. }
  479. doPageUp() {
  480. if (this.linesUp) {
  481. let i = this.pageLineCount;
  482. if (this.keepLastToFirst)
  483. i--;
  484. i = (i > this.linesUp.length - 1 ? this.linesUp.length - 1 : i);
  485. if (i >= 0 && this.linesUp.length > i) {
  486. this.currentTransition = this.pageChangeTransition;
  487. this.pageChangeDirectionDown = false;
  488. this.bookPos = this.linesUp[i].begin;
  489. }
  490. }
  491. }
  492. doHome() {
  493. this.bookPos = 0;
  494. }
  495. doEnd() {
  496. if (this.parsed.para.length) {
  497. let i = this.parsed.para.length - 1;
  498. let lastPos = this.parsed.para[i].offset + this.parsed.para[i].length - 1;
  499. const lines = this.parsed.getLines(lastPos, -this.pageLineCount);
  500. i = this.pageLineCount - 1;
  501. i = (i > lines.length - 1 ? lines.length - 1 : i);
  502. this.bookPos = lines[i].begin;
  503. }
  504. }
  505. doToolBarToggle() {
  506. this.$emit('tool-bar-toggle');
  507. }
  508. keyHook(event) {
  509. //console.log(event.code);
  510. if (event.type == 'keydown') {
  511. switch (event.code) {
  512. case 'ArrowDown':
  513. this.doDown();
  514. break;
  515. case 'ArrowUp':
  516. this.doUp();
  517. break;
  518. case 'PageDown':
  519. case 'ArrowRight':
  520. case 'Space':
  521. this.doPageDown();
  522. break;
  523. case 'PageUp':
  524. case 'ArrowLeft':
  525. case 'Backspace':
  526. this.doPageUp();
  527. break;
  528. case 'Home':
  529. this.doHome();
  530. break;
  531. case 'End':
  532. this.doEnd();
  533. break;
  534. case 'Enter':
  535. case 'Backquote'://`
  536. case 'KeyF':
  537. if (this.fullScreenToggle)
  538. this.fullScreenToggle();
  539. break;
  540. case 'Tab':
  541. this.doToolBarToggle();
  542. event.preventDefault();
  543. event.stopPropagation();
  544. break;
  545. }
  546. }
  547. }
  548. async startClickRepeat(pointX, pointY) {
  549. this.repX = pointX;
  550. this.repY = pointY;
  551. if (!this.repInit && this.repDoing) {
  552. this.repInit = true;
  553. let delay = 400;
  554. while (this.repDoing) {
  555. this.handleClick(pointX, pointY);
  556. await sleep(delay);
  557. if (delay > 15)
  558. delay *= 0.8;
  559. }
  560. this.repInit = false;
  561. }
  562. }
  563. endClickRepeat() {
  564. this.repDoing = false;
  565. }
  566. onTouchStart(event) {
  567. if (!this.mobile)
  568. return;
  569. this.endClickRepeat();
  570. if (event.touches.length == 1) {
  571. const touch = event.touches[0];
  572. const rect = event.target.getBoundingClientRect();
  573. const x = touch.pageX - rect.left;
  574. const y = touch.pageY - rect.top;
  575. if (this.handleClick(x, y)) {
  576. this.repDoing = true;
  577. this.debouncedStartClickRepeat(x, y);
  578. }
  579. }
  580. }
  581. onTouchEnd() {
  582. if (!this.mobile)
  583. return;
  584. this.endClickRepeat();
  585. }
  586. onTouchCancel() {
  587. if (!this.mobile)
  588. return;
  589. this.endClickRepeat();
  590. }
  591. onMouseDown(event) {
  592. if (this.mobile)
  593. return;
  594. this.endClickRepeat();
  595. if (event.button == 0) {
  596. if (this.handleClick(event.offsetX, event.offsetY)) {
  597. this.repDoing = true;
  598. this.debouncedStartClickRepeat(event.offsetX, event.offsetY);
  599. }
  600. } else if (event.button == 2) {
  601. this.doToolBarToggle();
  602. }
  603. }
  604. onMouseUp() {
  605. if (this.mobile)
  606. return;
  607. this.endClickRepeat();
  608. }
  609. onMouseWheel(event) {
  610. if (this.mobile)
  611. return;
  612. if (event.deltaY > 0) {
  613. this.doDown();
  614. } else if (event.deltaY < 0) {
  615. this.doUp();
  616. }
  617. }
  618. onStatusBarClick() {
  619. window.open(this.meta.url, '_blank');
  620. }
  621. handleClick(pointX, pointY) {
  622. const mouseLegend = {
  623. 40: {30: 'PgUp', 100: 'PgDown'},
  624. 60: {40: 'Up', 60: 'Menu', 100: 'Down'},
  625. 100: {30: 'PgUp', 100: 'PgDown'}
  626. };
  627. const w = pointX/this.realWidth*100;
  628. const h = pointY/this.realHeight*100;
  629. let action = '';
  630. loops: {
  631. for (const x in mouseLegend) {
  632. for (const y in mouseLegend[x]) {
  633. if (w < x && h < y) {
  634. action = mouseLegend[x][y];
  635. break loops;
  636. }
  637. }
  638. }
  639. }
  640. switch (action) {
  641. case 'Down' ://Down
  642. this.doDown();
  643. break;
  644. case 'Up' ://Up
  645. this.doUp();
  646. break;
  647. case 'PgDown' ://PgDown
  648. this.doPageDown();
  649. break;
  650. case 'PgUp' ://PgUp
  651. this.doPageUp();
  652. break;
  653. case 'Menu' :
  654. this.doToolBarToggle();
  655. break;
  656. default :
  657. // Nothing
  658. }
  659. return (action && action != 'Menu');
  660. }
  661. }
  662. //-----------------------------------------------------------------------------
  663. </script>
  664. <style scoped>
  665. .main {
  666. flex: 1;
  667. margin: 0;
  668. padding: 0;
  669. overflow: hidden;
  670. position: relative;
  671. min-width: 200px;
  672. }
  673. .layout {
  674. margin: 0;
  675. padding: 0;
  676. position: absolute;
  677. z-index: 10;
  678. }
  679. .events {
  680. z-index: 20;
  681. background-color: rgba(0,0,0,0);
  682. }
  683. </style>