TextPage.vue 46 KB

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