TextPage.vue 46 KB

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