TextPage.vue 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366
  1. <template>
  2. <div ref="main" class="main">
  3. <div class="layout back" @wheel.prevent.stop="onMouseWheel">
  4. <div class="absolute" v-html="background"></div>
  5. <div class="absolute" v-html="pageDivider"></div>
  6. </div>
  7. <div ref="scrollBox1" class="scroll-box layout over-hidden" @wheel.prevent.stop="onMouseWheel">
  8. <div ref="scrollingPage1" class="layout over-hidden" @transitionend="onPage1TransitionEnd" @animationend="onPage1AnimationEnd">
  9. <div @copy.prevent="copyText" v-html="page1"></div>
  10. </div>
  11. </div>
  12. <div ref="scrollBox2" class="scroll-box layout over-hidden" @wheel.prevent.stop="onMouseWheel">
  13. <div ref="scrollingPage2" class="layout over-hidden" @transitionend="onPage2TransitionEnd" @animationend="onPage2AnimationEnd">
  14. <div @copy.prevent="copyText" v-html="page2"></div>
  15. </div>
  16. </div>
  17. <div v-show="showStatusBar" ref="statusBar" class="layout" :class="{'no-events': clickControl}">
  18. <div v-html="statusBar"></div>
  19. </div>
  20. <div
  21. v-show="clickControl" ref="layoutEvents" class="layout events"
  22. oncontextmenu="return false;"
  23. @mousedown.prevent.stop="onMouseDown" @mouseup.prevent.stop="onMouseUp"
  24. @mouseover.prevent.stop="onMouseEvent" @mouseout.prevent.stop="onMouseEvent" @mousemove.prevent.stop="onMouseEvent"
  25. @wheel.prevent.stop="onMouseWheel"
  26. @touchstart.stop="onTouchStart" @touchend.stop="onTouchEnd" @touchmove.stop="onTouchMove" @touchcancel.prevent.stop="onTouchCancel"
  27. >
  28. </div>
  29. <div
  30. v-show="showStatusBar && statusBarClickOpen" class="layout"
  31. @mousedown.prevent.stop @touchstart.stop
  32. @click.prevent.stop="onStatusBarClick"
  33. v-html="statusBarClickable"
  34. >
  35. </div>
  36. <!-- невидимым делать нельзя (display: none), вовремя не подгружаютя шрифты -->
  37. <canvas ref="offscreenCanvas" class="layout" style="visibility: hidden"></canvas>
  38. <div ref="measureWidth" style="position: absolute; visibility: hidden"></div>
  39. <!-- Примечание -->
  40. <Dialog ref="dialog1" v-model="noteDialogVisible">
  41. <template #header>
  42. {{ noteTitle }}
  43. </template>
  44. <div class="column col" style="line-height: 20px; max-width: 400px; max-height: 200px; overflow-x: hidden; overflow-y: auto">
  45. <div v-html="noteHtml"></div>
  46. </div>
  47. <template #footer>
  48. <div class="row col">
  49. <q-btn class="q-px-md q-mr-md" color="btn2" text-color="app" dense no-caps @click="goToNotes">
  50. В примечания
  51. </q-btn>
  52. </div>
  53. <q-btn class="q-px-md" color="btn2" text-color="app" dense no-caps @click="noteDialogVisible = false">
  54. OK
  55. </q-btn>
  56. </template>
  57. </Dialog>
  58. </div>
  59. </template>
  60. <script>
  61. //-----------------------------------------------------------------------------
  62. import vueComponent from '../../vueComponent.js';
  63. import {loadCSS} from 'fg-loadcss';
  64. import _ from 'lodash';
  65. import he from 'he';
  66. import Dialog from '../../share/Dialog.vue';
  67. import './TextPage.css';
  68. import * as utils from '../../../share/utils';
  69. import bookManager from '../share/bookManager';
  70. import DrawHelper from './DrawHelper';
  71. import rstore from '../../../store/modules/reader';
  72. import {clickMap} from '../share/clickMap';
  73. const minLayoutWidth = 100;
  74. //обработчик кликов по примечаниям, см. DrawHelper
  75. //коряво, но иначе придется сильно усложнять рендеринг страниц (через Vue)
  76. window.onNoteClickLiberama = (noteId, orig) => {
  77. const textPage = window.textPageLiberama;
  78. if (textPage) {
  79. textPage.showNote(noteId, orig);
  80. }
  81. }
  82. const componentOptions = {
  83. components: {
  84. Dialog
  85. },
  86. watch: {
  87. bookPos: function() {
  88. this.$emit('book-pos-changed', {bookPos: this.bookPos, bookPosSeen: this.bookPosSeen});
  89. this.draw();
  90. if (this.userBookPosChange) {
  91. this.$emit('hide-tool-bar', {show: (this.bookPos == 0 || this.bookPos < this.prevBookPos)});
  92. this.prevBookPos = this.bookPos;
  93. this.userBookPosChange = false;
  94. }
  95. },
  96. bookPosSeen: function() {
  97. this.$emit('book-pos-changed', {bookPos: this.bookPos, bookPosSeen: this.bookPosSeen});
  98. },
  99. settings: function() {
  100. this.debouncedLoadSettings();
  101. },
  102. inAnimation: function() {
  103. this.updateLayout();
  104. },
  105. },
  106. };
  107. class TextPage {
  108. _options = componentOptions;
  109. showStatusBar = false;
  110. statusBarClickOpen = false;
  111. clickControl = true;
  112. background = null;
  113. pageDivider = null;
  114. page1 = null;
  115. page2 = null;
  116. statusBar = null;
  117. statusBarClickable = null;
  118. lastBook = null;
  119. bookPos = 0;
  120. bookPosSeen = null;
  121. prevBookPos = 0;
  122. userBookPosChange = false;
  123. fontStyle = null;
  124. fontSize = null;
  125. fontName = null;
  126. fontWeight = null;
  127. inAnimation = false;
  128. meta = null;
  129. noteDialogVisible = false;
  130. noteId = '';
  131. noteTitle = '';
  132. noteHtml = '';
  133. created() {
  134. this.drawHelper = new DrawHelper();
  135. this.commit = this.$store.commit;
  136. this.dispatch = this.$store.dispatch;
  137. this.config = this.$store.state.config;
  138. this.reader = this.$store.state.reader;
  139. this.debouncedStartClickRepeat = _.debounce((x, y) => {
  140. this.startClickRepeat(x, y);
  141. }, 800);
  142. this.debouncedDrawStatusBar = _.throttle(() => {
  143. this.drawStatusBar();
  144. }, 60);
  145. this.debouncedDrawPageDividerAndOrnament = _.throttle(() => {
  146. this.drawPageDividerAndOrnament();
  147. }, 65);
  148. this.debouncedLoadSettings = _.debounce(() => {
  149. this.loadSettings();
  150. }, 50);
  151. this.debouncedUpdatePage = _.debounce(async(lines) => {
  152. if (this.pageChangeAnimation) {
  153. this.page2 = this.page1;
  154. }
  155. this.page1 = this.drawHelper.drawPage(lines);
  156. await this.doPageAnimation();
  157. }, 10);
  158. this.$root.addEventHook('resize', async() => {
  159. this.$nextTick(this.onResize);
  160. await utils.sleep(200);
  161. this.$nextTick(this.onResize);
  162. });
  163. window.textPageLiberama = this;
  164. }
  165. mounted() {
  166. this.context = this.$refs.offscreenCanvas.getContext('2d');
  167. }
  168. hex2rgba(hex, alpha = 1) {
  169. let [r, g, b] = [0, 0, 0];
  170. if (hex.length <= 4) {
  171. [r, g, b] = hex.match(/\w/g).map(x => parseInt(x + x, 16));
  172. } else {
  173. [r, g, b] = hex.match(/\w\w/g).map(x => parseInt(x, 16));
  174. }
  175. return `rgba(${r},${g},${b},${alpha})`;
  176. }
  177. calcDrawProps() {
  178. const wideLetter = 'Щ';
  179. //preloaded fonts
  180. this.fontList = [`12px '${this.fontName}'`];
  181. //widths
  182. this.realWidth = this.$refs.main.clientWidth;
  183. this.realHeight = this.$refs.main.clientHeight;
  184. this.$refs.layoutEvents.style.width = this.realWidth + 'px';
  185. this.$refs.layoutEvents.style.height = this.realHeight + 'px';
  186. const dual = (this.dualPageMode ? 2 : 1);
  187. this.boxW = this.realWidth - 2*this.indentLR;
  188. this.w = this.boxW/dual - (this.dualPageMode ? 2*this.dualIndentLR : 0);
  189. this.scrollHeight = this.realHeight - (this.showStatusBar ? this.statusBarHeight : 0);
  190. this.h = this.scrollHeight - 2*this.indentTB;
  191. this.lineHeight = this.fontSize + this.lineInterval;
  192. this.pageRowsCount = 1 + Math.floor((this.h - this.lineHeight + this.lineInterval/2)/this.lineHeight);
  193. this.pageLineCount = (this.dualPageMode ? this.pageRowsCount*2 : this.pageRowsCount)
  194. //stuff
  195. this.currentAnimation = '';
  196. this.pageChangeDirectionDown = true;
  197. this.fontShift = this.fontVertShift/100;
  198. this.textShift = this.textVertShift/100 + this.fontShift;
  199. //statusBar
  200. this.$refs.statusBar.style.left = '0px';
  201. this.$refs.statusBar.style.top = (this.statusBarTop ? 1 : this.realHeight - this.statusBarHeight) + 'px';
  202. const sbColor = (this.statusBarColorAsText ? this.textColor : this.statusBarColor);
  203. this.statusBarRgbaColor = this.hex2rgba(sbColor || '#000000', this.statusBarColorAlpha);
  204. const ddColor = (this.dualDivColorAsText ? this.textColor : this.dualDivColor);
  205. this.dualDivRgbaColor = this.hex2rgba(ddColor || '#000000', this.dualDivColorAlpha);
  206. //drawHelper
  207. this.drawHelper.realWidth = this.realWidth;
  208. this.drawHelper.realHeight = this.realHeight;
  209. this.drawHelper.lastBook = this.lastBook;
  210. this.drawHelper.book = this.book;
  211. this.drawHelper.parsed = this.parsed;
  212. this.drawHelper.pageRowsCount = this.pageRowsCount;
  213. this.drawHelper.pageLineCount = this.pageLineCount;
  214. this.drawHelper.dualPageMode = this.dualPageMode;
  215. this.drawHelper.dualIndentLR = this.dualIndentLR;
  216. /*this.drawHelper.dualDivWidth = this.dualDivWidth;
  217. this.drawHelper.dualDivHeight = this.dualDivHeight;
  218. this.drawHelper.dualDivRgbaColor = this.dualDivRgbaColor;
  219. this.drawHelper.dualDivStrokeFill = this.dualDivStrokeFill;
  220. this.drawHelper.dualDivStrokeGap = this.dualDivStrokeGap;
  221. this.drawHelper.dualDivShadowWidth = this.dualDivShadowWidth;*/
  222. this.drawHelper.backgroundColor = this.backgroundColor;
  223. this.drawHelper.statusBarRgbaColor = this.statusBarRgbaColor;
  224. this.drawHelper.fontStyle = this.fontStyle;
  225. this.drawHelper.fontWeight = this.fontWeight;
  226. this.drawHelper.fontSize = this.fontSize;
  227. this.drawHelper.fontName = this.fontName;
  228. this.drawHelper.fontShift = this.fontShift;
  229. this.drawHelper.textColor = this.textColor;
  230. this.drawHelper.textShift = this.textShift;
  231. this.drawHelper.p = this.p;
  232. this.drawHelper.boxW = this.boxW;
  233. this.drawHelper.w = this.w;
  234. this.drawHelper.h = this.h;
  235. this.drawHelper.indentLR = this.indentLR;
  236. this.drawHelper.textAlignJustify = this.textAlignJustify;
  237. this.drawHelper.lineHeight = this.lineHeight;
  238. this.drawHelper.context = this.context;
  239. //альтернатива context.measureText
  240. if (!this.context.measureText(wideLetter).width) {
  241. const ctx = this.$refs.measureWidth;
  242. this.drawHelper.measureText = function(text, style) {
  243. ctx.innerText = text;
  244. ctx.style.font = this.fontByStyle(style);
  245. return ctx.clientWidth;
  246. };
  247. this.drawHelper.measureTextFont = function(text, font) {
  248. ctx.innerText = text;
  249. ctx.style.font = font;
  250. return ctx.clientWidth;
  251. }
  252. }
  253. //statusBar
  254. this.statusBarClickable = this.drawHelper.statusBarClickable(this.statusBarTop, this.statusBarHeight);
  255. //parsed
  256. if (this.parsed) {
  257. let wideLine = wideLetter;
  258. if (!this.drawHelper.measureText(wideLine, {}))
  259. throw new Error('Ошибка measureText');
  260. while (this.drawHelper.measureText(wideLine, {}) < this.w) wideLine += wideLetter;
  261. this.parsed.setSettings({
  262. p: this.p,
  263. w: this.w,
  264. font: this.font,
  265. fontSize: this.fontSize,
  266. wordWrap: this.wordWrap,
  267. cutEmptyParagraphs: this.cutEmptyParagraphs,
  268. addEmptyParagraphs: this.addEmptyParagraphs,
  269. maxWordLength: wideLine.length - 1,
  270. lineHeight: this.lineHeight,
  271. showImages: this.showImages,
  272. showInlineImagesInCenter: this.showInlineImagesInCenter,
  273. imageHeightLines: this.imageHeightLines,
  274. imageFitWidth: this.imageFitWidth,
  275. compactTextPerc: this.compactTextPerc,
  276. testWidth: 0,
  277. measureText: this.drawHelper.measureText.bind(this.drawHelper),
  278. });
  279. }
  280. //scrolling page
  281. const pageSpace = this.scrollHeight - this.pageRowsCount*this.lineHeight;
  282. let top = pageSpace/2;
  283. if (this.showStatusBar)
  284. top += this.statusBarHeight*(this.statusBarTop ? 1 : 0);
  285. let page1 = this.$refs.scrollBox1.style;
  286. let page2 = this.$refs.scrollBox2.style;
  287. page1.pointerEvents = page2.pointerEvents = (this.clickControl ? 'none' : 'auto');
  288. page1.perspective = page2.perspective = '3072px';
  289. page1.width = page2.width = this.boxW + this.indentLR + 'px';
  290. page1.height = page2.height = this.scrollHeight - (pageSpace > 0 ? pageSpace : 0) + 'px';
  291. page1.top = page2.top = top + 'px';
  292. page1.left = page2.left = this.indentLR + 'px';
  293. page1 = this.$refs.scrollingPage1.style;
  294. page2 = this.$refs.scrollingPage2.style;
  295. page1.width = page2.width = this.boxW + this.indentLR + 'px';
  296. page1.height = page2.height = this.scrollHeight + this.lineHeight + 'px';
  297. }
  298. async checkLoadedFonts() {
  299. let loaded = await Promise.all(this.fontList.map(font => document.fonts.check(font)));
  300. if (loaded.some(r => !r)) {
  301. await Promise.all(this.fontList.map(font => document.fonts.load(font)));
  302. }
  303. }
  304. async loadFonts() {
  305. this.fontsLoading = true;
  306. let close = null;
  307. (async() => {
  308. await utils.sleep(500);
  309. if (this.fontsLoading)
  310. close = this.$root.notify.info('Загрузка шрифта &nbsp;<i class="la la-snowflake icon-rotate" style="font-size: 150%"></i>');
  311. })();
  312. if (!this.fontsLoaded)
  313. this.fontsLoaded = {};
  314. //загрузка дин.шрифта
  315. const loaded = this.fontsLoaded[this.fontCssUrl];
  316. if (this.fontCssUrl && !loaded) {
  317. loadCSS(this.fontCssUrl);
  318. this.fontsLoaded[this.fontCssUrl] = 1;
  319. }
  320. try {
  321. await this.checkLoadedFonts();
  322. } catch (e) {
  323. this.$root.notify.error('Некоторые шрифты не удалось загрузить', 'Ошибка загрузки');
  324. }
  325. this.fontsLoading = false;
  326. if (close)
  327. close();
  328. }
  329. getSettings() {
  330. const settings = this.settings;
  331. for (let prop in rstore.settingDefaults) {
  332. this[prop] = settings[prop];
  333. }
  334. const wf = this.webFontName;
  335. const i = _.findIndex(rstore.webFonts, ['name', wf]);
  336. if (wf && i >= 0) {
  337. this.fontName = wf;
  338. this.fontCssUrl = rstore.webFonts[i].css;
  339. this.fontVertShift = settings.fontShifts[wf] || 0;
  340. }
  341. }
  342. async calcPropsAndLoadFonts(omitLoadFonts) {
  343. this.calcDrawProps();
  344. this.setBackground();
  345. if (!omitLoadFonts)
  346. await this.loadFonts();
  347. if (omitLoadFonts) {
  348. this.draw();
  349. } else {
  350. // ширина шрифта некоторое время выдается неверно,
  351. // не удалось событийно отловить этот момент, поэтому костыль
  352. while (this.checkingFont) {
  353. this.stopCheckingFont = true;
  354. await utils.sleep(100);
  355. }
  356. this.checkingFont = true;
  357. this.stopCheckingFont = false;
  358. try {
  359. const parsed = this.parsed;
  360. let i = 0;
  361. const t = 'Это тестовый текст. Его ширина выдается системой неправильно некоторое время.';
  362. let twprev = 0;
  363. //5 секунд проверяем изменения шрифта
  364. while (!this.stopCheckingFont && i++ < 50 && this.parsed === parsed) {
  365. const tw = this.drawHelper.measureText(t, {});
  366. if (tw !== twprev) {
  367. this.parsed.setSettings({testWidth: tw});
  368. this.draw();
  369. twprev = tw;
  370. }
  371. await utils.sleep(100);
  372. }
  373. } finally {
  374. this.checkingFont = false;
  375. }
  376. }
  377. }
  378. loadSettings() {
  379. (async() => {
  380. let fontName = this.fontName;
  381. this.getSettings();
  382. await this.calcPropsAndLoadFonts(fontName == this.fontName);
  383. })();
  384. }
  385. showBook() {
  386. this.$refs.main.focus();
  387. this.updateLayout();
  388. this.book = null;
  389. this.meta = null;
  390. this.parsed = null;
  391. this.linesUp = null;
  392. this.linesDown = null;
  393. this.statusBarMessage = '';
  394. this.getSettings();
  395. this.calcDrawProps();
  396. this.draw();// пока не загрузили, очистим канвас
  397. if (this.lastBook) {
  398. (async() => {
  399. try {
  400. const isParsed = await bookManager.hasBookParsed(this.lastBook);
  401. if (!isParsed) {
  402. return;
  403. }
  404. this.book = await bookManager.getBook(this.lastBook);
  405. this.meta = bookManager.metaOnly(this.book);
  406. const bt = utils.getBookTitle(this.meta.fb2);
  407. this.title = bt.fullTitle;
  408. this.$root.setAppTitle(this.title);
  409. this.parsed = this.book.parsed;
  410. this.page1 = null;
  411. this.page2 = null;
  412. this.statusBar = null;
  413. await this.stopTextScrolling();
  414. await this.calcPropsAndLoadFonts();
  415. this.refreshTime();
  416. } catch (e) {
  417. this.$root.stdDialog.alert(e.message, 'Ошибка', {color: 'negative'});
  418. }
  419. })();
  420. }
  421. }
  422. updateLayout() {
  423. if (this.inAnimation) {
  424. this.$refs.scrollBox1.style.visibility = 'visible';
  425. this.$refs.scrollBox2.style.visibility = 'visible';
  426. } else {
  427. this.$refs.scrollBox1.style.visibility = 'visible';
  428. this.$refs.scrollBox2.style.visibility = 'hidden';
  429. }
  430. }
  431. setBackground() {
  432. if (this.wallpaperIgnoreStatusBar) {
  433. this.background = `<div class="layout" style="width: ${this.realWidth}px; height: ${this.realHeight}px;` +
  434. ` background-color: ${this.backgroundColor}">` +
  435. `<div class="layout ${this.wallpaper}" style="width: ${this.realWidth}px; height: ${this.scrollHeight}px; ` +
  436. `top: ${(this.showStatusBar && this.statusBarTop ? this.statusBarHeight + 1 : 0)}px; position: relative;">` +
  437. `</div>` +
  438. `</div>`;
  439. } else {
  440. this.background = `<div class="layout ${this.wallpaper}" style="width: ${this.realWidth}px; height: ${this.realHeight}px;` +
  441. ` background-color: ${this.backgroundColor}"></div>`;
  442. }
  443. }
  444. async onResize() {
  445. if (this.resizing)
  446. return;
  447. this.resizing = true;
  448. try {
  449. const scrolled = this.doingScrolling;
  450. if (scrolled)
  451. await this.stopTextScrolling();
  452. this.calcDrawProps();
  453. this.setBackground();
  454. this.draw();
  455. if (scrolled)
  456. this.startTextScrolling();
  457. } catch (e) {
  458. //
  459. } finally {
  460. this.resizing = false;
  461. }
  462. }
  463. get settings() {
  464. return this.$store.state.reader.settings;
  465. }
  466. get font() {
  467. return `${this.fontStyle} ${this.fontWeight} ${this.fontSize}px '${this.fontName}'`;
  468. }
  469. onPage1TransitionEnd() {
  470. if (this.resolveTransition1Finish)
  471. this.resolveTransition1Finish();
  472. }
  473. onPage2TransitionEnd() {
  474. if (this.resolveTransition2Finish)
  475. this.resolveTransition2Finish();
  476. }
  477. startSearch(needle) {
  478. this.drawHelper.needle = needle;
  479. this.drawHelper.searching = true;
  480. this.draw();
  481. }
  482. stopSearch() {
  483. this.drawHelper.searching = false;
  484. this.draw();
  485. }
  486. generateWaitingFunc(waitingHandlerName, stopPropertyName) {
  487. const func = (timeout) => {
  488. return new Promise((resolve, reject) => { (async() => {
  489. this[waitingHandlerName] = resolve;
  490. let wait = (timeout + 201)/100;
  491. while (wait > 0 && !this[stopPropertyName]) {
  492. wait--;
  493. await utils.sleep(100);
  494. }
  495. resolve();
  496. })().catch(reject); });
  497. };
  498. return func;
  499. }
  500. async startTextScrolling() {
  501. if (this.doingScrolling || !this.book || !this.parsed.textLength || !this.linesDown || this.pageLineCount < 1 ||
  502. this.linesDown.length <= this.pageLineCount || this.dualPageMode) {
  503. this.doStopScrolling();
  504. return;
  505. }
  506. //ждем анимацию
  507. while (this.inAnimation) await utils.sleep(10);
  508. this.stopScrolling = false;
  509. this.doingScrolling = true;
  510. const transitionFinish = this.generateWaitingFunc('resolveTransition1Finish', 'stopScrolling');
  511. this.cachedPos = -1;
  512. this.draw();
  513. const page = this.$refs.scrollingPage1;
  514. let i = 0;
  515. while (!this.stopScrolling) {
  516. if (i > 0) {
  517. this.doDown();
  518. await utils.sleep(1);
  519. await this.$nextTick();
  520. if (this.linesDown.length <= this.pageLineCount + 1) {
  521. this.stopScrolling = true;
  522. }
  523. }
  524. page.style.transition = `${this.scrollingDelay}ms ${this.scrollingType}`;
  525. page.style.transform = `translateY(-${this.lineHeight}px)`;
  526. await transitionFinish(this.scrollingDelay);
  527. page.style.transition = '';
  528. page.style.transform = 'none';
  529. page.offsetHeight;
  530. i++;
  531. }
  532. this.resolveTransition1Finish = null;
  533. this.doingScrolling = false;
  534. this.doStopScrolling();
  535. this.draw();
  536. }
  537. async stopTextScrolling() {
  538. this.stopScrolling = true;
  539. const page = this.$refs.scrollingPage1;
  540. page.style.transition = '';
  541. page.style.transform = 'none';
  542. page.offsetHeight;
  543. while (this.doingScrolling) await utils.sleep(10);
  544. }
  545. draw() {
  546. //scrolling
  547. if (this.doingScrolling) {
  548. this.currentAnimation = '';
  549. if (this.cachedPos == this.bookPos) {
  550. this.linesDown = this.linesCached.linesDown;
  551. this.linesUp = this.linesCached.linesUp;
  552. this.page1 = this.pageCached;
  553. } else {
  554. const lines = this.getLines(this.bookPos);
  555. this.linesDown = lines.linesDown;
  556. this.linesUp = lines.linesUp;
  557. this.page1 = this.drawHelper.drawPage(lines.linesDown, true);
  558. }
  559. //caching next
  560. if (this.cachedPageTimer)
  561. clearTimeout(this.cachedPageTimer);
  562. this.cachedPageTimer = setTimeout(() => {
  563. if (this.linesDown && this.linesDown.length > this.pageLineCount && this.pageLineCount > 0) {
  564. this.cachedPos = this.linesDown[1].begin;
  565. this.linesCached = this.getLines(this.cachedPos);
  566. this.pageCached = this.drawHelper.drawPage(this.linesCached.linesDown, true);
  567. }
  568. this.cachedPageTimer = null;
  569. }, 20);
  570. this.debouncedDrawStatusBar();
  571. return;
  572. }
  573. //check
  574. if (this.w < minLayoutWidth) {
  575. this.page1 = null;
  576. this.page2 = null;
  577. this.statusBar = null;
  578. return;
  579. }
  580. if (this.book && this.bookPos > 0 && this.bookPos >= this.parsed.textLength) {
  581. this.doEnd(true, false);
  582. return;
  583. }
  584. const lines = this.getLines(this.bookPos);
  585. this.linesDown = lines.linesDown;
  586. this.linesUp = lines.linesUp;
  587. this.debouncedUpdatePage(lines.linesDown);
  588. this.debouncedDrawStatusBar();
  589. this.debouncedDrawPageDividerAndOrnament();
  590. if (this.book && this.linesDown && this.linesDown.length < this.pageLineCount) {
  591. this.doEnd(true, false);
  592. return;
  593. }
  594. }
  595. onPage1AnimationEnd() {
  596. if (this.resolveAnimation1Finish)
  597. this.resolveAnimation1Finish();
  598. }
  599. onPage2AnimationEnd() {
  600. if (this.resolveAnimation2Finish)
  601. this.resolveAnimation2Finish();
  602. }
  603. async doPageAnimation() {
  604. if (this.currentAnimation && !this.inAnimation) {
  605. this.inAnimation = true;
  606. const animation1Finish = this.generateWaitingFunc('resolveAnimation1Finish', 'stopAnimation');
  607. const animation2Finish = this.generateWaitingFunc('resolveAnimation2Finish', 'stopAnimation');
  608. const transition1Finish = this.generateWaitingFunc('resolveTransition1Finish', 'stopAnimation');
  609. const transition2Finish = this.generateWaitingFunc('resolveTransition2Finish', 'stopAnimation');
  610. const duration = Math.round(3000*(1 - this.pageChangeAnimationSpeed/100));
  611. let page1 = this.$refs.scrollingPage1;
  612. let page2 = this.$refs.scrollingPage2;
  613. switch (this.currentAnimation) {
  614. case 'thaw':
  615. await this.drawHelper.doPageAnimationThaw(page1, page2,
  616. duration, this.pageChangeDirectionDown, animation1Finish);
  617. break;
  618. case 'blink':
  619. await this.drawHelper.doPageAnimationBlink(page1, page2,
  620. duration, this.pageChangeDirectionDown, animation1Finish, animation2Finish);
  621. break;
  622. case 'rightShift':
  623. await this.drawHelper.doPageAnimationRightShift(page1, page2,
  624. duration, this.pageChangeDirectionDown, transition1Finish);
  625. break;
  626. case 'downShift':
  627. page1.style.height = this.scrollHeight + 'px';
  628. page2.style.height = this.scrollHeight + 'px';
  629. await this.drawHelper.doPageAnimationDownShift(page1, page2,
  630. duration, this.pageChangeDirectionDown, transition1Finish);
  631. page1.style.height = this.scrollHeight + this.lineHeight + 'px';
  632. page2.style.height = this.scrollHeight + this.lineHeight + 'px';
  633. break;
  634. case 'rotate':
  635. await this.drawHelper.doPageAnimationRotate(page1, page2,
  636. duration, this.pageChangeDirectionDown, transition1Finish, transition2Finish);
  637. break;
  638. case 'flip':
  639. await this.drawHelper.doPageAnimationFlip(page1, page2,
  640. duration, this.pageChangeDirectionDown, transition1Finish, transition2Finish, this.backgroundColor);
  641. break;
  642. }
  643. this.resolveAnimation1Finish = null;
  644. this.resolveAnimation2Finish = null;
  645. this.resolveTransition1Finish = null;
  646. this.resolveTransition2Finish = null;
  647. page1.style.animation = '';
  648. page2.style.animation = '';
  649. page1.style.transition = '';
  650. page1.style.transform = 'none';
  651. page1.offsetHeight;
  652. page2.style.transition = '';
  653. page2.style.transform = 'none';
  654. page2.offsetHeight;
  655. this.currentAnimation = '';
  656. this.pageChangeDirectionDown = false;//true только если PgDown
  657. this.inAnimation = false;
  658. this.stopAnimation = false;
  659. }
  660. }
  661. getLines(bookPos) {
  662. if (!this.parsed || this.pageLineCount < 1)
  663. return {};
  664. return {
  665. linesDown: this.parsed.getLines(bookPos, 2*this.pageLineCount),
  666. linesUp: this.parsed.getLines(bookPos, -2*this.pageLineCount)
  667. };
  668. }
  669. drawStatusBar(message) {
  670. if (this.w < minLayoutWidth) {
  671. this.statusBar = null;
  672. return;
  673. }
  674. if (this.showStatusBar && this.linesDown && this.pageLineCount > 0) {
  675. const lines = this.linesDown;
  676. let i = this.pageLineCount;
  677. if (this.keepLastToFirst)
  678. i--;
  679. i = (i > lines.length - 1 ? lines.length - 1 : i);
  680. if (i >= 0) {
  681. if (!message)
  682. message = this.statusBarMessage;
  683. if (!message)
  684. message = this.title;
  685. //check image num
  686. let imageNum = 0;
  687. const len = (lines.length > 2 ? 2 : lines.length);
  688. loop:
  689. for (let j = 0; j < len; j++) {
  690. const line = lines[j];
  691. for (const part of line.parts) {
  692. if (part.image) {
  693. imageNum = part.image.num;
  694. break loop;
  695. }
  696. }
  697. }
  698. //drawing
  699. this.statusBar = this.drawHelper.drawStatusBar(this.statusBarTop, this.statusBarHeight,
  700. lines[i].end, this.parsed.textLength, message, imageNum, this.parsed.images.length);
  701. this.bookPosSeen = lines[i].end;
  702. }
  703. } else {
  704. this.statusBar = '';
  705. }
  706. }
  707. drawPageDividerAndOrnament() {
  708. if (this.dualPageMode) {
  709. this.pageDivider = `<div class="layout" style="width: ${this.realWidth}px; height: ${this.scrollHeight}px; ` +
  710. `top: ${(this.showStatusBar && this.statusBarTop ? this.statusBarHeight + 1 : 0)}px; position: relative;">` +
  711. `<div class="fit row justify-center items-center no-wrap">` +
  712. `<div style="height: ${Math.round(this.scrollHeight*this.dualDivHeight/100)}px; width: ${this.dualDivWidth}px; ` +
  713. `box-shadow: 0 0 ${this.dualDivShadowWidth}px ${this.dualDivRgbaColor}; ` +
  714. `background-image: url(&quot;data:image/svg+xml;utf8,<svg width='100%' height='100%' xmlns='http://www.w3.org/2000/svg'>` +
  715. `<line x1='${this.dualDivWidth/2}' y1='0' x2='${this.dualDivWidth/2}' y2='100%' stroke='${this.dualDivRgbaColor}' ` +
  716. `stroke-width='${this.dualDivWidth}' stroke-dasharray='${this.dualDivStrokeFill} ${this.dualDivStrokeGap}'/>` +
  717. `</svg>&quot;);">` +
  718. `</div>` +
  719. `</div>` +
  720. `</div>`;
  721. } else {
  722. this.pageDivider = null;
  723. }
  724. }
  725. blinkCachedLoadMessage(state) {
  726. if (state === 'finish') {
  727. this.statusBarMessage = '';
  728. } else if (state) {
  729. this.statusBarMessage = 'Книга загружена из кэша';
  730. } else {
  731. this.statusBarMessage = ' ';
  732. }
  733. this.drawStatusBar();
  734. }
  735. async refreshTime() {
  736. if (!this.timeRefreshing) {
  737. this.timeRefreshing = true;
  738. await utils.sleep(60*1000);
  739. if (this.book && this.parsed.textLength) {
  740. this.debouncedDrawStatusBar();
  741. }
  742. this.timeRefreshing = false;
  743. this.refreshTime();
  744. }
  745. }
  746. doDown() {
  747. if (this.linesDown && this.linesDown.length > this.pageLineCount && this.pageLineCount > 0) {
  748. this.userBookPosChange = true;
  749. this.bookPos = this.linesDown[1].begin;
  750. }
  751. }
  752. doUp() {
  753. if (this.linesUp && this.linesUp.length > 1 && this.pageLineCount > 0) {
  754. this.userBookPosChange = true;
  755. this.bookPos = this.linesUp[1].begin;
  756. }
  757. }
  758. doPageDown() {
  759. if (this.linesDown && this.pageLineCount > 0) {
  760. let i = this.pageLineCount;
  761. if (this.keepLastToFirst)
  762. i--;
  763. if (i >= 0 && this.linesDown.length >= 2*i + (this.keepLastToFirst ? 1 : 0)) {
  764. this.currentAnimation = this.pageChangeAnimation;
  765. this.pageChangeDirectionDown = true;
  766. this.userBookPosChange = true;
  767. this.bookPos = this.linesDown[i].begin;
  768. } else
  769. this.doEnd();
  770. }
  771. }
  772. doPageUp() {
  773. if (this.linesUp && this.pageLineCount > 0) {
  774. let i = this.pageLineCount;
  775. if (this.keepLastToFirst)
  776. i--;
  777. i = (i > this.linesUp.length - 1 ? this.linesUp.length - 1 : i);
  778. if (i >= 0 && this.linesUp.length > i) {
  779. this.currentAnimation = this.pageChangeAnimation;
  780. this.pageChangeDirectionDown = false;
  781. this.userBookPosChange = true;
  782. this.bookPos = this.linesUp[i].begin;
  783. }
  784. }
  785. }
  786. doHome() {
  787. this.currentAnimation = this.pageChangeAnimation;
  788. this.pageChangeDirectionDown = false;
  789. this.userBookPosChange = true;
  790. this.bookPos = 0;
  791. }
  792. doEnd(noAni, isUser = true) {
  793. if (this.parsed.para.length && this.pageLineCount > 0) {
  794. let i = this.parsed.para.length - 1;
  795. let lastPos = this.parsed.para[i].offset + this.parsed.para[i].length - 1;
  796. const lines = this.parsed.getLines(lastPos, -this.pageLineCount);
  797. if (lines) {
  798. i = this.pageLineCount - 1;
  799. i = (i > lines.length - 1 ? lines.length - 1 : i);
  800. if (!noAni)
  801. this.currentAnimation = this.pageChangeAnimation;
  802. this.pageChangeDirectionDown = true;
  803. this.userBookPosChange = isUser;
  804. this.bookPos = lines[i].begin;
  805. }
  806. }
  807. }
  808. doPara(paraIndex) {
  809. const para = this.parsed.para[paraIndex];
  810. if (para && this.pageLineCount > 0) {
  811. const lines = this.parsed.getLines(para.offset, this.pageLineCount);
  812. if (lines.length >= this.pageLineCount) {
  813. this.currentAnimation = this.pageChangeAnimation;
  814. this.pageChangeDirectionDown = true;
  815. this.userBookPosChange = true;
  816. this.bookPos = lines[0].begin;
  817. } else
  818. this.doEnd();
  819. }
  820. }
  821. doToolBarToggle(event) {
  822. this.$emit('do-action', {action: 'switchToolbar', event});
  823. }
  824. doScrollingToggle() {
  825. this.$emit('do-action', {action: 'scrolling', event});
  826. }
  827. doFullScreenToggle() {
  828. this.$emit('do-action', {action: 'fullScreen', event});
  829. }
  830. doStopScrolling() {
  831. this.$emit('do-action', {action: 'stopScrolling', event});
  832. }
  833. async doFontSizeInc() {
  834. if (!this.settingsChanging) {
  835. this.settingsChanging = true;
  836. const newSize = (this.settings.fontSize + 1 < 200 ? this.settings.fontSize + 1 : 100);
  837. this.commit('reader/setSettings', {fontSize: newSize});
  838. await utils.sleep(50);
  839. this.settingsChanging = false;
  840. }
  841. }
  842. async doFontSizeDec() {
  843. if (!this.settingsChanging) {
  844. this.settingsChanging = true;
  845. const newSize = (this.settings.fontSize - 1 > 5 ? this.settings.fontSize - 1 : 5);
  846. this.commit('reader/setSettings', {fontSize: newSize});
  847. await utils.sleep(50);
  848. this.settingsChanging = false;
  849. }
  850. }
  851. async doScrollingSpeedUp() {
  852. if (!this.settingsChanging) {
  853. this.settingsChanging = true;
  854. const newDelay = (this.settings.scrollingDelay - 50 > 1 ? this.settings.scrollingDelay - 50 : 1);
  855. this.commit('reader/setSettings', {scrollingDelay: newDelay});
  856. await utils.sleep(50);
  857. this.settingsChanging = false;
  858. }
  859. }
  860. async doScrollingSpeedDown() {
  861. if (!this.settingsChanging) {
  862. this.settingsChanging = true;
  863. const newDelay = (this.settings.scrollingDelay + 50 < 10000 ? this.settings.scrollingDelay + 50 : 10000);
  864. this.commit('reader/setSettings', {scrollingDelay: newDelay});
  865. await utils.sleep(50);
  866. this.settingsChanging = false;
  867. }
  868. }
  869. async startClickRepeat(pointX, pointY) {
  870. this.repX = pointX;
  871. this.repY = pointY;
  872. if (!this.repInit && this.repDoing) {
  873. this.repInit = true;
  874. let delay = 400;
  875. while (this.repDoing) {
  876. this.handleClick(pointX, pointY);
  877. await utils.sleep(delay);
  878. if (delay > 15)
  879. delay *= 0.8;
  880. }
  881. this.repInit = false;
  882. }
  883. }
  884. endClickRepeat() {
  885. this.repDoing = false;
  886. }
  887. onTouchStart(event) {
  888. if (!this.$root.isMobileDevice)
  889. return;
  890. this.endClickRepeat();
  891. if (event.touches.length == 1) {
  892. const touch = event.touches[0];
  893. const rect = event.target.getBoundingClientRect();
  894. const x = touch.pageX - rect.left;
  895. const y = touch.pageY - rect.top;
  896. const hc = this.handleClick(x, y, new Set(['Menu']));
  897. if (hc) {
  898. if (hc != 'Menu') {
  899. this.repDoing = true;
  900. this.debouncedStartClickRepeat(x, y);
  901. } else {
  902. this.startTouch = {x, y};
  903. }
  904. }
  905. }
  906. }
  907. onTouchMove(event) {
  908. if (this.startTouch) {
  909. event.preventDefault();
  910. }
  911. this.endClickRepeat();
  912. }
  913. onTouchEnd(event) {
  914. if (!this.$root.isMobileDevice)
  915. return;
  916. this.endClickRepeat();
  917. if (event.changedTouches.length == 1) {
  918. const touch = event.changedTouches[0];
  919. const rect = event.target.getBoundingClientRect();
  920. const x = touch.pageX - rect.left;
  921. const y = touch.pageY - rect.top;
  922. if (this.startTouch) {
  923. const dy = this.startTouch.y - y;
  924. const dx = this.startTouch.x - x;
  925. this.startTouch = null;
  926. const moveDelta = 30;
  927. const touchDelta = 15;
  928. if (dy > 0 && Math.abs(dy) >= moveDelta && Math.abs(dy) > Math.abs(dx)) {
  929. //движение вверх
  930. this.doFullScreenToggle();
  931. } else if (dy < 0 && Math.abs(dy) >= moveDelta && Math.abs(dy) > Math.abs(dx)) {
  932. //движение вниз
  933. this.doScrollingToggle();
  934. } else if (dx > 0 && Math.abs(dx) >= moveDelta && Math.abs(dy) < Math.abs(dx)) {
  935. //движение влево
  936. this.doScrollingSpeedDown();
  937. } else if (dx < 0 && Math.abs(dx) >= moveDelta && Math.abs(dy) < Math.abs(dx)) {
  938. //движение вправо
  939. this.doScrollingSpeedUp();
  940. } else if (Math.abs(dy) < touchDelta && Math.abs(dx) < touchDelta) {
  941. if (this.touchMode) {
  942. this.touchMode = 2;
  943. return;
  944. }
  945. (async() => {
  946. this.touchMode = 1;
  947. let i = 20;
  948. while (i-- > 0 && this.touchMode === 1)
  949. await utils.sleep(10);
  950. if (this.touchMode === 1)
  951. this.doToolBarToggle();
  952. else
  953. this.doFullScreenToggle();
  954. this.touchMode = 0;
  955. })();
  956. }
  957. }
  958. }
  959. }
  960. onTouchCancel() {
  961. if (!this.$root.isMobileDevice)
  962. return;
  963. this.endClickRepeat();
  964. }
  965. onMouseDown(event) {
  966. if (this.$root.isMobileDevice)
  967. return;
  968. this.endClickRepeat();
  969. if (event.button == 0) {
  970. const hc = this.handleClick(event.offsetX, event.offsetY);
  971. if (hc && hc != 'Menu') {
  972. this.repDoing = true;
  973. this.debouncedStartClickRepeat(event.offsetX, event.offsetY);
  974. }
  975. } else if (event.button == 1) {
  976. this.doScrollingToggle();
  977. } else if (event.button == 2) {
  978. this.doToolBarToggle(event);
  979. }
  980. }
  981. onMouseUp() {
  982. if (this.$root.isMobileDevice)
  983. return;
  984. this.endClickRepeat();
  985. }
  986. onMouseWheel(event) {
  987. if (this.$root.isMobileDevice)
  988. return;
  989. this.endClickRepeat();
  990. if (event.deltaY > 0) {
  991. this.doDown();
  992. } else if (event.deltaY < 0) {
  993. this.doUp();
  994. }
  995. }
  996. onMouseEvent() {
  997. if (this.$root.isMobileDevice)
  998. return;
  999. this.endClickRepeat();
  1000. }
  1001. onStatusBarClick() {
  1002. const url = this.meta.url;
  1003. if (url && url.indexOf('disk://') != 0) {
  1004. window.open(url, '_blank');
  1005. } else {
  1006. this.$root.stdDialog.alert('Оригинал недоступен, т.к. файл книги был загружен с локального диска.', ' ', {color: 'info'});
  1007. }
  1008. }
  1009. getClickAction(pointX, pointY) {
  1010. const w = pointX/this.realWidth*100;
  1011. const h = pointY/this.realHeight*100;
  1012. let action = '';
  1013. loops: {
  1014. for (const x in clickMap) {
  1015. for (const y in clickMap[x]) {
  1016. if (w < x && h < y) {
  1017. action = clickMap[x][y];
  1018. break loops;
  1019. }
  1020. }
  1021. }
  1022. }
  1023. return action;
  1024. }
  1025. handleClick(pointX, pointY, exclude) {
  1026. const action = this.getClickAction(pointX, pointY);
  1027. if (!exclude || !exclude.has(action)) {
  1028. switch (action) {
  1029. case 'Down' ://Down
  1030. this.doDown();
  1031. break;
  1032. case 'Up' ://Up
  1033. this.doUp();
  1034. break;
  1035. case 'PgDown' ://PgDown
  1036. this.doPageDown();
  1037. break;
  1038. case 'PgUp' ://PgUp
  1039. this.doPageUp();
  1040. break;
  1041. case 'Menu' :
  1042. this.doToolBarToggle();
  1043. break;
  1044. default :
  1045. // Nothing
  1046. }
  1047. }
  1048. return action;
  1049. }
  1050. copyText(event) {
  1051. //все это для того, чтобы правильно расставить переносы \n при копировании текста
  1052. //прямо с текущей страницы
  1053. //подготовка, вытаскиваем весь текст страницы
  1054. const lines = this.getLines(this.bookPos);
  1055. const decodedLines = [];
  1056. for (const line of lines.linesDown) {
  1057. let lineText = '';
  1058. for (const part of line.parts) {
  1059. lineText += part.text;
  1060. }
  1061. decodedLines.push({text: he.decode(lineText), first: line.first});
  1062. }
  1063. let i = 0;
  1064. const findDecoded = (line) => {
  1065. for (let j = i; j < decodedLines.length; j++) {
  1066. const decoded = decodedLines[j];
  1067. if (decoded.text.indexOf(line) >= 0) {
  1068. i = j;
  1069. return decoded;
  1070. }
  1071. }
  1072. return;
  1073. }
  1074. const selection = document.getSelection();
  1075. const splitted = selection.toString().split(/[\n\r]/);
  1076. let filtered = '';
  1077. //формируем filtered, учитывая переносы из decodedLines
  1078. for (const line of splitted) {
  1079. const found = findDecoded(line);
  1080. if (found && found.first) {
  1081. filtered += (filtered ? '\n' : '') + line;
  1082. } else {
  1083. filtered += (filtered ? '\r ' : '') + line;
  1084. }
  1085. }
  1086. //маленькие хитрости, убираем переносы по слогам
  1087. filtered = filtered.replace(/-\r /g, '').replace(/\r /g, ' ');
  1088. event.clipboardData.setData('text/plain', filtered);
  1089. }
  1090. showNote(noteId, orig) {
  1091. const note = this.parsed.notes[noteId];
  1092. if (note) {
  1093. if (orig) {//show dialog
  1094. this.noteId = noteId;
  1095. this.noteTitle = `[${note.title?.trim()}]`;
  1096. this.noteHtml = note.xml
  1097. .replace(/<p>/g, '<p class="note-para">')
  1098. .replace(/<stanza>/g, '<br>').replace(/<\/stanza>/g, '')
  1099. .replace(/<v>/g, '<p style="margin: 0">').replace(/<\/v>/g, '</p>')
  1100. .replace(/<emphasis>/g, '<em>').replace(/<\/emphasis>/g, '</em>')
  1101. .replace(/<text-author>/g, '<br>').replace(/<\/text-author>/g, '')
  1102. ;
  1103. this.noteDialogVisible = true;
  1104. } else {//go to orig
  1105. this.goToOrigNote(noteId);
  1106. }
  1107. }
  1108. }
  1109. goToNotes() {
  1110. const note = this.parsed.notes[this.noteId];
  1111. if (note && note.noteParaIndex >= 0) {
  1112. this.doPara(note.noteParaIndex);
  1113. this.noteDialogVisible = false;
  1114. }
  1115. }
  1116. goToOrigNote(noteId) {
  1117. const note = this.parsed.notes[noteId];
  1118. if (note && note.linkParaIndex >= 0) {
  1119. this.doPara(note.linkParaIndex);
  1120. this.noteDialogVisible = false;
  1121. }
  1122. }
  1123. }
  1124. export default vueComponent(TextPage);
  1125. //-----------------------------------------------------------------------------
  1126. </script>
  1127. <style scoped>
  1128. .main {
  1129. flex: 1;
  1130. margin: 0;
  1131. padding: 0;
  1132. overflow: hidden;
  1133. position: relative;
  1134. min-width: 200px;
  1135. }
  1136. .layout {
  1137. margin: 0;
  1138. padding: 0;
  1139. position: absolute;
  1140. z-index: 10;
  1141. }
  1142. .over-hidden {
  1143. overflow: hidden;
  1144. }
  1145. .on-top {
  1146. z-index: 100;
  1147. }
  1148. .back {
  1149. z-index: 5;
  1150. }
  1151. .events {
  1152. z-index: 9;
  1153. background-color: rgba(0,0,0,0);
  1154. }
  1155. .no-events {
  1156. pointer-events: none;
  1157. }
  1158. </style>
  1159. <style>
  1160. .note-para {
  1161. margin: 0;
  1162. padding: 0;
  1163. margin-bottom: 10px;
  1164. }
  1165. </style>