TextPage.vue 46 KB

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