Merge branch 'release/0.10.0'
@@ -13,8 +13,7 @@ class Misc {
|
|||||||
]};
|
]};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await wsc.open();
|
const config = await wsc.message(await wsc.send(Object.assign({action: 'get-config'}, query)));
|
||||||
const config = await wsc.message(wsc.send(Object.assign({action: 'get-config'}, query)));
|
|
||||||
if (config.error)
|
if (config.error)
|
||||||
throw new Error(config.error);
|
throw new Error(config.error);
|
||||||
return config;
|
return config;
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ class Reader {
|
|||||||
|
|
||||||
let response = {};
|
let response = {};
|
||||||
try {
|
try {
|
||||||
await wsc.open();
|
const requestId = await wsc.send({action: 'worker-get-state-finish', workerId});
|
||||||
const requestId = wsc.send({action: 'worker-get-state-finish', workerId});
|
|
||||||
|
|
||||||
let prevResponse = false;
|
let prevResponse = false;
|
||||||
while (1) {// eslint-disable-line no-constant-condition
|
while (1) {// eslint-disable-line no-constant-condition
|
||||||
@@ -124,8 +123,7 @@ class Reader {
|
|||||||
let response = null
|
let response = null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await wsc.open();
|
response = await wsc.message(await wsc.send({action: 'reader-restore-cached-file', path: url}));
|
||||||
response = await wsc.message(wsc.send({action: 'reader-restore-cached-file', path: url}));
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
//если с WebSocket проблема, работаем по http
|
//если с WebSocket проблема, работаем по http
|
||||||
@@ -210,8 +208,7 @@ class Reader {
|
|||||||
async storage(request) {
|
async storage(request) {
|
||||||
let response = null;
|
let response = null;
|
||||||
try {
|
try {
|
||||||
await wsc.open();
|
response = await wsc.message(await wsc.send({action: 'reader-storage', body: request}));
|
||||||
response = await wsc.message(wsc.send({action: 'reader-storage', body: request}));
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
//если с WebSocket проблема, работаем по http
|
//если с WebSocket проблема, работаем по http
|
||||||
|
|||||||
@@ -1,185 +1,3 @@
|
|||||||
import * as utils from '../share/utils';
|
import WebSocketConnection from '../../server/core/WebSocketConnection';
|
||||||
|
|
||||||
const cleanPeriod = 60*1000;//1 минута
|
|
||||||
|
|
||||||
class WebSocketConnection {
|
|
||||||
//messageLifeTime в минутах (cleanPeriod)
|
|
||||||
constructor(messageLifeTime = 5) {
|
|
||||||
this.ws = null;
|
|
||||||
this.timer = null;
|
|
||||||
this.listeners = [];
|
|
||||||
this.messageQueue = [];
|
|
||||||
this.messageLifeTime = messageLifeTime;
|
|
||||||
this.requestId = 0;
|
|
||||||
|
|
||||||
this.connecting = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
addListener(listener) {
|
|
||||||
if (this.listeners.indexOf(listener) < 0)
|
|
||||||
this.listeners.push(Object.assign({regTime: Date.now()}, listener));
|
|
||||||
}
|
|
||||||
|
|
||||||
//рассылаем сообщение и удаляем те обработчики, которые его получили
|
|
||||||
emit(mes, isError) {
|
|
||||||
const len = this.listeners.length;
|
|
||||||
if (len > 0) {
|
|
||||||
let newListeners = [];
|
|
||||||
for (const listener of this.listeners) {
|
|
||||||
let emitted = false;
|
|
||||||
if (isError) {
|
|
||||||
if (listener.onError)
|
|
||||||
listener.onError(mes);
|
|
||||||
emitted = true;
|
|
||||||
} else {
|
|
||||||
if (listener.onMessage) {
|
|
||||||
if (listener.requestId) {
|
|
||||||
if (listener.requestId === mes.requestId) {
|
|
||||||
listener.onMessage(mes);
|
|
||||||
emitted = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
listener.onMessage(mes);
|
|
||||||
emitted = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
emitted = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!emitted)
|
|
||||||
newListeners.push(listener);
|
|
||||||
}
|
|
||||||
this.listeners = newListeners;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.listeners.length != len;
|
|
||||||
}
|
|
||||||
|
|
||||||
open(url) {
|
|
||||||
return new Promise((resolve, reject) => { (async() => {
|
|
||||||
//Ожидаем окончания процесса подключения, если open уже был вызван
|
|
||||||
let i = 0;
|
|
||||||
while (this.connecting && i < 200) {//10 сек
|
|
||||||
await utils.sleep(50);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
if (i >= 200)
|
|
||||||
this.connecting = false;
|
|
||||||
|
|
||||||
//проверим подключение, и если нет, то подключимся заново
|
|
||||||
if (this.ws && this.ws.readyState == WebSocket.OPEN) {
|
|
||||||
resolve(this.ws);
|
|
||||||
} else {
|
|
||||||
this.connecting = true;
|
|
||||||
const protocol = (window.location.protocol == 'https:' ? 'wss:' : 'ws:');
|
|
||||||
|
|
||||||
url = url || `${protocol}//${window.location.host}/ws`;
|
|
||||||
|
|
||||||
this.ws = new WebSocket(url);
|
|
||||||
|
|
||||||
if (this.timer) {
|
|
||||||
clearTimeout(this.timer);
|
|
||||||
}
|
|
||||||
this.timer = setTimeout(() => { this.periodicClean(); }, cleanPeriod);
|
|
||||||
|
|
||||||
this.ws.onopen = (e) => {
|
|
||||||
this.connecting = false;
|
|
||||||
resolve(e);
|
|
||||||
};
|
|
||||||
|
|
||||||
this.ws.onmessage = (e) => {
|
|
||||||
try {
|
|
||||||
const mes = JSON.parse(e.data);
|
|
||||||
this.messageQueue.push({regTime: Date.now(), mes});
|
|
||||||
|
|
||||||
let newMessageQueue = [];
|
|
||||||
for (const message of this.messageQueue) {
|
|
||||||
if (!this.emit(message.mes)) {
|
|
||||||
newMessageQueue.push(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.messageQueue = newMessageQueue;
|
|
||||||
} catch (e) {
|
|
||||||
this.emit(e.message, true);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.ws.onerror = (e) => {
|
|
||||||
this.emit(e.message, true);
|
|
||||||
if (this.connecting) {
|
|
||||||
this.connecting = false;
|
|
||||||
reject(e);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
})() });
|
|
||||||
}
|
|
||||||
|
|
||||||
//timeout в минутах (cleanPeriod)
|
|
||||||
message(requestId, timeout = 2) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
this.addListener({
|
|
||||||
requestId,
|
|
||||||
timeout,
|
|
||||||
onMessage: (mes) => {
|
|
||||||
resolve(mes);
|
|
||||||
},
|
|
||||||
onError: (e) => {
|
|
||||||
reject(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
send(req) {
|
|
||||||
if (this.ws && this.ws.readyState == WebSocket.OPEN) {
|
|
||||||
const requestId = ++this.requestId;
|
|
||||||
this.ws.send(JSON.stringify(Object.assign({requestId}, req)));
|
|
||||||
return requestId;
|
|
||||||
} else {
|
|
||||||
throw new Error('WebSocket connection is not ready');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
close() {
|
|
||||||
if (this.ws && this.ws.readyState == WebSocket.OPEN) {
|
|
||||||
this.ws.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
periodicClean() {
|
|
||||||
try {
|
|
||||||
this.timer = null;
|
|
||||||
|
|
||||||
const now = Date.now();
|
|
||||||
//чистка listeners
|
|
||||||
let newListeners = [];
|
|
||||||
for (const listener of this.listeners) {
|
|
||||||
if (now - listener.regTime < listener.timeout*cleanPeriod - 50) {
|
|
||||||
newListeners.push(listener);
|
|
||||||
} else {
|
|
||||||
if (listener.onError)
|
|
||||||
listener.onError('Время ожидания ответа истекло');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.listeners = newListeners;
|
|
||||||
|
|
||||||
//чистка messageQueue
|
|
||||||
let newMessageQueue = [];
|
|
||||||
for (const message of this.messageQueue) {
|
|
||||||
if (now - message.regTime < this.messageLifeTime*cleanPeriod - 50) {
|
|
||||||
newMessageQueue.push(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.messageQueue = newMessageQueue;
|
|
||||||
} finally {
|
|
||||||
if (this.ws.readyState == WebSocket.OPEN) {
|
|
||||||
this.timer = setTimeout(() => { this.periodicClean(); }, cleanPeriod);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default new WebSocketConnection();
|
export default new WebSocketConnection();
|
||||||
@@ -270,6 +270,14 @@ body, html, #app {
|
|||||||
animation: rotating 2s linear infinite;
|
animation: rotating 2s linear infinite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@keyframes rotating {
|
||||||
|
from {
|
||||||
|
transform: rotate(0deg);
|
||||||
|
} to {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.notify-button-icon {
|
.notify-button-icon {
|
||||||
font-size: 16px !important;
|
font-size: 16px !important;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,10 @@
|
|||||||
<div class="box">
|
<div class="box">
|
||||||
<p class="p">Вы можете пожертвовать на развитие проекта любую сумму:</p>
|
<p class="p">Вы можете пожертвовать на развитие проекта любую сумму:</p>
|
||||||
<div class="address">
|
<div class="address">
|
||||||
<img class="logo" src="./assets/yandex.png">
|
<img class="logo" src="./assets/yoomoney.png">
|
||||||
<q-btn class="q-ml-sm q-px-sm" dense no-caps @click="donateYandexMoney">Пожертвовать</q-btn><br>
|
<q-btn class="q-ml-sm q-px-sm" dense no-caps @click="donateYooMoney">Пожертвовать</q-btn><br>
|
||||||
<div class="para">{{ yandexAddress }}
|
<div class="para">{{ yooAddress }}
|
||||||
<q-icon class="copy-icon" name="la la-copy" @click="copyAddress(yandexAddress, 'Яндекс кошелек')">
|
<q-icon class="copy-icon" name="la la-copy" @click="copyAddress(yooAddress, 'Кошелёк ЮMoney')">
|
||||||
<q-tooltip :delay="1000" anchor="top middle" self="center middle" content-style="font-size: 80%">Скопировать</q-tooltip>
|
<q-tooltip :delay="1000" anchor="top middle" self="center middle" content-style="font-size: 80%">Скопировать</q-tooltip>
|
||||||
</q-icon>
|
</q-icon>
|
||||||
</div>
|
</div>
|
||||||
@@ -60,7 +60,7 @@ import {copyTextToClipboard} from '../../../../share/utils';
|
|||||||
export default @Component({
|
export default @Component({
|
||||||
})
|
})
|
||||||
class DonateHelpPage extends Vue {
|
class DonateHelpPage extends Vue {
|
||||||
yandexAddress = '410018702323056';
|
yooAddress = '410018702323056';
|
||||||
paypalAddress = 'bookpauk@gmail.com';
|
paypalAddress = 'bookpauk@gmail.com';
|
||||||
bitcoinAddress = '3EbgZ7MK1UVaN38Gty5DCBtS4PknM4Ut85';
|
bitcoinAddress = '3EbgZ7MK1UVaN38Gty5DCBtS4PknM4Ut85';
|
||||||
litecoinAddress = 'MP39Riec4oSNB3XMjiquKoLWxbufRYNXxZ';
|
litecoinAddress = 'MP39Riec4oSNB3XMjiquKoLWxbufRYNXxZ';
|
||||||
@@ -69,8 +69,8 @@ class DonateHelpPage extends Vue {
|
|||||||
created() {
|
created() {
|
||||||
}
|
}
|
||||||
|
|
||||||
donateYandexMoney() {
|
donateYooMoney() {
|
||||||
window.open(`https://money.yandex.ru/to/${this.yandexAddress}`, '_blank');
|
window.open(`https://yoomoney.ru/to/${this.yooAddress}`, '_blank');
|
||||||
}
|
}
|
||||||
|
|
||||||
async copyAddress(address, prefix) {
|
async copyAddress(address, prefix) {
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 7.4 KiB |
|
After Width: | Height: | Size: 8.8 KiB |
@@ -68,7 +68,7 @@ class PasteTextPage extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadBuffer() {
|
loadBuffer() {
|
||||||
this.$emit('load-buffer', {buffer: `<buffer><cut-title>${utils.escapeXml(this.bookTitle)}</cut-title>${this.$refs.textArea.value}</buffer>`});
|
this.$emit('load-buffer', {buffer: `<buffer><fb2-title>${utils.escapeXml(this.bookTitle)}</fb2-title>${utils.escapeXml(this.$refs.textArea.value)}</buffer>`});
|
||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -194,6 +194,10 @@ export default @Component({
|
|||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
},
|
},
|
||||||
|
dualPageMode(newValue) {
|
||||||
|
if (newValue)
|
||||||
|
this.stopScrolling();
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
class Reader extends Vue {
|
class Reader extends Vue {
|
||||||
@@ -227,6 +231,7 @@ class Reader extends Vue {
|
|||||||
whatsNewVisible = false;
|
whatsNewVisible = false;
|
||||||
whatsNewContent = '';
|
whatsNewContent = '';
|
||||||
donationVisible = false;
|
donationVisible = false;
|
||||||
|
dualPageMode = false;
|
||||||
|
|
||||||
created() {
|
created() {
|
||||||
this.rstore = rstore;
|
this.rstore = rstore;
|
||||||
@@ -321,6 +326,7 @@ class Reader extends Vue {
|
|||||||
this.djvuQuality = settings.djvuQuality;
|
this.djvuQuality = settings.djvuQuality;
|
||||||
this.pdfAsText = settings.pdfAsText;
|
this.pdfAsText = settings.pdfAsText;
|
||||||
this.pdfQuality = settings.pdfQuality;
|
this.pdfQuality = settings.pdfQuality;
|
||||||
|
this.dualPageMode = settings.dualPageMode;
|
||||||
|
|
||||||
this.readerActionByKeyCode = utils.userHotKeysObjectSwap(settings.userHotKeys);
|
this.readerActionByKeyCode = utils.userHotKeysObjectSwap(settings.userHotKeys);
|
||||||
this.$root.readerActionByKeyEvent = (event) => {
|
this.$root.readerActionByKeyEvent = (event) => {
|
||||||
@@ -778,7 +784,6 @@ class Reader extends Vue {
|
|||||||
case 'loader':
|
case 'loader':
|
||||||
case 'fullScreen':
|
case 'fullScreen':
|
||||||
case 'setPosition':
|
case 'setPosition':
|
||||||
case 'scrolling':
|
|
||||||
case 'search':
|
case 'search':
|
||||||
case 'copyText':
|
case 'copyText':
|
||||||
case 'convOptions':
|
case 'convOptions':
|
||||||
@@ -794,6 +799,13 @@ class Reader extends Vue {
|
|||||||
classResult = classActive;
|
classResult = classActive;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'scrolling':
|
||||||
|
if (this.progressActive || this.dualPageMode) {
|
||||||
|
classResult = classDisabled;
|
||||||
|
} else if (this[`${action}Active`]) {
|
||||||
|
classResult = classActive;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'undoAction':
|
case 'undoAction':
|
||||||
if (this.actionCur <= 0)
|
if (this.actionCur <= 0)
|
||||||
classResult = classDisabled;
|
classResult = classDisabled;
|
||||||
|
|||||||
@@ -27,8 +27,11 @@
|
|||||||
placeholder="Найти"
|
placeholder="Найти"
|
||||||
v-model="search"
|
v-model="search"
|
||||||
@click.stop
|
@click.stop
|
||||||
/>
|
>
|
||||||
|
<template v-slot:append>
|
||||||
|
<q-icon v-if="search !== ''" name="la la-times" class="cursor-pointer" @click.stop="resetSearch"/>
|
||||||
|
</template>
|
||||||
|
</q-input>
|
||||||
<span v-html="props.cols[2].label"></span>
|
<span v-html="props.cols[2].label"></span>
|
||||||
</q-th>
|
</q-th>
|
||||||
</q-tr>
|
</q-tr>
|
||||||
@@ -53,6 +56,7 @@
|
|||||||
<div class="break-word" style="width: 332px; font-size: 90%">
|
<div class="break-word" style="width: 332px; font-size: 90%">
|
||||||
<div style="color: green">{{ props.row.desc.author }}</div>
|
<div style="color: green">{{ props.row.desc.author }}</div>
|
||||||
<div>{{ props.row.desc.title }}</div>
|
<div>{{ props.row.desc.title }}</div>
|
||||||
|
<div class="read-bar" :style="`width: ${332*props.row.readPart}px`"></div>
|
||||||
</div>
|
</div>
|
||||||
</q-td>
|
</q-td>
|
||||||
|
|
||||||
@@ -106,7 +110,7 @@ export default @Component({
|
|||||||
})
|
})
|
||||||
class RecentBooksPage extends Vue {
|
class RecentBooksPage extends Vue {
|
||||||
loading = false;
|
loading = false;
|
||||||
search = null;
|
search = '';
|
||||||
tableData = [];
|
tableData = [];
|
||||||
columns = [];
|
columns = [];
|
||||||
pagination = {};
|
pagination = {};
|
||||||
@@ -200,11 +204,13 @@ class RecentBooksPage extends Vue {
|
|||||||
d.setTime(book.touchTime);
|
d.setTime(book.touchTime);
|
||||||
const t = utils.formatDate(d).split(' ');
|
const t = utils.formatDate(d).split(' ');
|
||||||
|
|
||||||
|
let readPart = 0;
|
||||||
let perc = '';
|
let perc = '';
|
||||||
let textLen = '';
|
let textLen = '';
|
||||||
const p = (book.bookPosSeen ? book.bookPosSeen : (book.bookPos ? book.bookPos : 0));
|
const p = (book.bookPosSeen ? book.bookPosSeen : (book.bookPos ? book.bookPos : 0));
|
||||||
if (book.textLength) {
|
if (book.textLength) {
|
||||||
perc = ` [${((p/book.textLength)*100).toFixed(2)}%]`;
|
readPart = p/book.textLength;
|
||||||
|
perc = ` [${(readPart*100).toFixed(2)}%]`;
|
||||||
textLen = ` ${Math.round(book.textLength/1000)}k`;
|
textLen = ` ${Math.round(book.textLength/1000)}k`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,6 +229,7 @@ class RecentBooksPage extends Vue {
|
|||||||
author,
|
author,
|
||||||
title: `${title}${perc}${textLen}`,
|
title: `${title}${perc}${textLen}`,
|
||||||
},
|
},
|
||||||
|
readPart,
|
||||||
descString: `${author}${title}${perc}${textLen}`,//для сортировки
|
descString: `${author}${title}${perc}${textLen}`,//для сортировки
|
||||||
url: book.url,
|
url: book.url,
|
||||||
path: book.path,
|
path: book.path,
|
||||||
@@ -244,6 +251,11 @@ class RecentBooksPage extends Vue {
|
|||||||
this.updating = false;
|
this.updating = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resetSearch() {
|
||||||
|
this.search = '';
|
||||||
|
this.$refs.input.focus();
|
||||||
|
}
|
||||||
|
|
||||||
wordEnding(num) {
|
wordEnding(num) {
|
||||||
const endings = ['', 'а', 'и', 'и', 'и', '', '', '', '', ''];
|
const endings = ['', 'а', 'и', 'и', 'и', '', '', '', '', ''];
|
||||||
const deci = num % 100;
|
const deci = num % 100;
|
||||||
@@ -346,6 +358,10 @@ class RecentBooksPage extends Vue {
|
|||||||
white-space: normal;
|
white-space: normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.read-bar {
|
||||||
|
height: 3px;
|
||||||
|
background-color: #aaaaaa;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ import * as utils from '../../../share/utils';
|
|||||||
import Window from '../../share/Window.vue';
|
import Window from '../../share/Window.vue';
|
||||||
import NumInput from '../../share/NumInput.vue';
|
import NumInput from '../../share/NumInput.vue';
|
||||||
import UserHotKeys from './UserHotKeys/UserHotKeys.vue';
|
import UserHotKeys from './UserHotKeys/UserHotKeys.vue';
|
||||||
|
import wallpaperStorage from '../share/wallpaperStorage';
|
||||||
|
|
||||||
import rstore from '../../../store/modules/reader';
|
import rstore from '../../../store/modules/reader';
|
||||||
import defPalette from './defPalette';
|
import defPalette from './defPalette';
|
||||||
@@ -113,7 +114,7 @@ export default @Component({
|
|||||||
},
|
},
|
||||||
vertShift: function(newValue) {
|
vertShift: function(newValue) {
|
||||||
const font = (this.webFontName ? this.webFontName : this.fontName);
|
const font = (this.webFontName ? this.webFontName : this.fontName);
|
||||||
if (this.fontShifts[font] != newValue) {
|
if (this.fontShifts[font] != newValue || this.fontVertShift != newValue) {
|
||||||
this.fontShifts = Object.assign({}, this.fontShifts, {[font]: newValue});
|
this.fontShifts = Object.assign({}, this.fontShifts, {[font]: newValue});
|
||||||
this.fontVertShift = newValue;
|
this.fontVertShift = newValue;
|
||||||
}
|
}
|
||||||
@@ -130,6 +131,10 @@ export default @Component({
|
|||||||
if (newValue != '' && this.pageChangeAnimation == 'flip')
|
if (newValue != '' && this.pageChangeAnimation == 'flip')
|
||||||
this.pageChangeAnimation = '';
|
this.pageChangeAnimation = '';
|
||||||
},
|
},
|
||||||
|
dualPageMode(newValue) {
|
||||||
|
if (newValue && this.pageChangeAnimation == 'flip' || this.pageChangeAnimation == 'rightShift')
|
||||||
|
this.pageChangeAnimation = '';
|
||||||
|
},
|
||||||
textColor: function(newValue) {
|
textColor: function(newValue) {
|
||||||
this.textColorFiltered = newValue;
|
this.textColorFiltered = newValue;
|
||||||
},
|
},
|
||||||
@@ -144,11 +149,25 @@ export default @Component({
|
|||||||
if (hex.test(newValue))
|
if (hex.test(newValue))
|
||||||
this.backgroundColor = newValue;
|
this.backgroundColor = newValue;
|
||||||
},
|
},
|
||||||
|
dualDivColor(newValue) {
|
||||||
|
this.dualDivColorFiltered = newValue;
|
||||||
|
},
|
||||||
|
dualDivColorFiltered(newValue) {
|
||||||
|
if (hex.test(newValue))
|
||||||
|
this.dualDivColor = newValue;
|
||||||
|
},
|
||||||
|
statusBarColor(newValue) {
|
||||||
|
this.statusBarColorFiltered = newValue;
|
||||||
|
},
|
||||||
|
statusBarColorFiltered(newValue) {
|
||||||
|
if (hex.test(newValue))
|
||||||
|
this.statusBarColor = newValue;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
class SettingsPage extends Vue {
|
class SettingsPage extends Vue {
|
||||||
selectedTab = 'profiles';
|
selectedTab = 'profiles';
|
||||||
selectedViewTab = 'color';
|
selectedViewTab = 'mode';
|
||||||
selectedKeysTab = 'mouse';
|
selectedKeysTab = 'mouse';
|
||||||
form = {};
|
form = {};
|
||||||
fontBold = false;
|
fontBold = false;
|
||||||
@@ -157,6 +176,7 @@ class SettingsPage extends Vue {
|
|||||||
tabsScrollable = false;
|
tabsScrollable = false;
|
||||||
textColorFiltered = '';
|
textColorFiltered = '';
|
||||||
bgColorFiltered = '';
|
bgColorFiltered = '';
|
||||||
|
dualDivColorFiltered = '';
|
||||||
|
|
||||||
webFonts = [];
|
webFonts = [];
|
||||||
fonts = [];
|
fonts = [];
|
||||||
@@ -217,6 +237,8 @@ class SettingsPage extends Vue {
|
|||||||
this.vertShift = this.fontShifts[font] || 0;
|
this.vertShift = this.fontShifts[font] || 0;
|
||||||
this.textColorFiltered = this.textColor;
|
this.textColorFiltered = this.textColor;
|
||||||
this.bgColorFiltered = this.backgroundColor;
|
this.bgColorFiltered = this.backgroundColor;
|
||||||
|
this.dualDivColorFiltered = this.dualDivColor;
|
||||||
|
this.statusBarColorFiltered = this.statusBarColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
get mode() {
|
get mode() {
|
||||||
@@ -256,9 +278,15 @@ class SettingsPage extends Vue {
|
|||||||
|
|
||||||
get wallpaperOptions() {
|
get wallpaperOptions() {
|
||||||
let result = [{label: 'Нет', value: ''}];
|
let result = [{label: 'Нет', value: ''}];
|
||||||
for (let i = 1; i < 10; i++) {
|
|
||||||
|
for (const wp of this.userWallpapers) {
|
||||||
|
result.push({label: wp.label, value: wp.cssClass});
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 1; i <= 17; i++) {
|
||||||
result.push({label: i, value: `paper${i}`});
|
result.push({label: i, value: `paper${i}`});
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,13 +310,15 @@ class SettingsPage extends Vue {
|
|||||||
let result = [
|
let result = [
|
||||||
{label: 'Нет', value: ''},
|
{label: 'Нет', value: ''},
|
||||||
{label: 'Вверх-вниз', value: 'downShift'},
|
{label: 'Вверх-вниз', value: 'downShift'},
|
||||||
{label: 'Вправо-влево', value: 'rightShift'},
|
(!this.dualPageMode ? {label: 'Вправо-влево', value: 'rightShift'} : null),
|
||||||
{label: 'Протаивание', value: 'thaw'},
|
{label: 'Протаивание', value: 'thaw'},
|
||||||
{label: 'Мерцание', value: 'blink'},
|
{label: 'Мерцание', value: 'blink'},
|
||||||
{label: 'Вращение', value: 'rotate'},
|
{label: 'Вращение', value: 'rotate'},
|
||||||
];
|
(this.wallpaper == '' && !this.dualPageMode ? {label: 'Листание', value: 'flip'} : null),
|
||||||
if (this.wallpaper == '')
|
];
|
||||||
result.push({label: 'Листание', value: 'flip'});
|
|
||||||
|
result = result.filter(v => v);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -351,6 +381,12 @@ class SettingsPage extends Vue {
|
|||||||
case 'bg':
|
case 'bg':
|
||||||
result += `background-color: ${this.backgroundColor};`
|
result += `background-color: ${this.backgroundColor};`
|
||||||
break;
|
break;
|
||||||
|
case 'div':
|
||||||
|
result += `background-color: ${this.dualDivColor};`
|
||||||
|
break;
|
||||||
|
case 'statusbar':
|
||||||
|
result += `background-color: ${this.statusBarColor};`
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -517,6 +553,71 @@ class SettingsPage extends Vue {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadWallpaperFileClick() {
|
||||||
|
this.$refs.file.click();
|
||||||
|
}
|
||||||
|
|
||||||
|
loadWallpaperFile() {
|
||||||
|
const file = this.$refs.file.files[0];
|
||||||
|
if (file.size > 10*1024*1024) {
|
||||||
|
this.$root.stdDialog.alert('Файл обоев не должен превышать в размере 10Mb', 'Ошибка');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file.type != 'image/png' && file.type != 'image/jpeg') {
|
||||||
|
this.$root.stdDialog.alert('Файл обоев должен иметь тип PNG или JPEG', 'Ошибка');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.userWallpapers.length >= 100) {
|
||||||
|
this.$root.stdDialog.alert('Превышено максимальное количество пользовательских обоев.', 'Ошибка');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.$refs.file.value = '';
|
||||||
|
if (file) {
|
||||||
|
const reader = new FileReader();
|
||||||
|
|
||||||
|
reader.onload = (e) => {
|
||||||
|
const newUserWallpapers = _.cloneDeep(this.userWallpapers);
|
||||||
|
let n = 0;
|
||||||
|
for (const wp of newUserWallpapers) {
|
||||||
|
const newN = parseInt(wp.label.replace(/\D/g, ''), 10);
|
||||||
|
if (newN > n)
|
||||||
|
n = newN;
|
||||||
|
}
|
||||||
|
n++;
|
||||||
|
|
||||||
|
const cssClass = `user-paper${n}`;
|
||||||
|
newUserWallpapers.push({label: `#${n}`, cssClass});
|
||||||
|
(async() => {
|
||||||
|
await wallpaperStorage.setData(cssClass, e.target.result);
|
||||||
|
|
||||||
|
this.userWallpapers = newUserWallpapers;
|
||||||
|
this.wallpaper = cssClass;
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async delWallpaper() {
|
||||||
|
if (this.wallpaper.indexOf('user-paper') == 0) {
|
||||||
|
const newUserWallpapers = [];
|
||||||
|
for (const wp of this.userWallpapers) {
|
||||||
|
if (wp.cssClass != this.wallpaper) {
|
||||||
|
newUserWallpapers.push(wp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await wallpaperStorage.removeData(this.wallpaper);
|
||||||
|
|
||||||
|
this.userWallpapers = newUserWallpapers;
|
||||||
|
this.wallpaper = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
keyHook(event) {
|
keyHook(event) {
|
||||||
if (!this.$root.stdDialog.active && event.type == 'keydown' && event.key == 'Escape') {
|
if (!this.$root.stdDialog.active && event.type == 'keydown' && event.key == 'Escape') {
|
||||||
this.close();
|
this.close();
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
no-caps
|
no-caps
|
||||||
class="no-mp bg-grey-4 text-grey-7"
|
class="no-mp bg-grey-4 text-grey-7"
|
||||||
>
|
>
|
||||||
|
<q-tab name="mode" label="Режим" />
|
||||||
<q-tab name="color" label="Цвет" />
|
<q-tab name="color" label="Цвет" />
|
||||||
<q-tab name="font" label="Шрифт" />
|
<q-tab name="font" label="Шрифт" />
|
||||||
<q-tab name="text" label="Текст" />
|
<q-tab name="text" label="Текст" />
|
||||||
@@ -16,6 +17,10 @@
|
|||||||
<div class="q-mb-sm"/>
|
<div class="q-mb-sm"/>
|
||||||
|
|
||||||
<div class="col tab-panel">
|
<div class="col tab-panel">
|
||||||
|
<div v-if="selectedViewTab == 'mode'">
|
||||||
|
@@include('./ViewTab/Mode.inc');
|
||||||
|
</div>
|
||||||
|
|
||||||
<div v-if="selectedViewTab == 'color'">
|
<div v-if="selectedViewTab == 'color'">
|
||||||
@@include('./ViewTab/Color.inc');
|
@@include('./ViewTab/Color.inc');
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -22,8 +22,6 @@
|
|||||||
</q-icon>
|
</q-icon>
|
||||||
</template>
|
</template>
|
||||||
</q-input>
|
</q-input>
|
||||||
|
|
||||||
<span class="col" style="position: relative; top: 35px; left: 15px;">Обои:</span>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -36,7 +34,6 @@
|
|||||||
v-model="bgColorFiltered"
|
v-model="bgColorFiltered"
|
||||||
:rules="['hexColor']"
|
:rules="['hexColor']"
|
||||||
style="max-width: 150px"
|
style="max-width: 150px"
|
||||||
:disable="wallpaper != ''"
|
|
||||||
>
|
>
|
||||||
<template v-slot:prepend>
|
<template v-slot:prepend>
|
||||||
<q-icon name="la la-angle-down la-xs" class="cursor-pointer text-white" :style="colorPanStyle('bg')">
|
<q-icon name="la la-angle-down la-xs" class="cursor-pointer text-white" :style="colorPanStyle('bg')">
|
||||||
@@ -48,11 +45,51 @@
|
|||||||
</q-icon>
|
</q-icon>
|
||||||
</template>
|
</template>
|
||||||
</q-input>
|
</q-input>
|
||||||
|
|
||||||
<div class="q-px-sm"/>
|
|
||||||
<q-select class="col" v-model="wallpaper" :options="wallpaperOptions"
|
|
||||||
dropdown-icon="la la-angle-down la-sm"
|
|
||||||
outlined dense emit-value map-options
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="q-mt-md"/>
|
||||||
|
<div class="item row">
|
||||||
|
<div class="label-2">Обои</div>
|
||||||
|
<div class="col row items-center">
|
||||||
|
<q-select class="col-left no-mp" v-model="wallpaper" :options="wallpaperOptions"
|
||||||
|
dropdown-icon="la la-angle-down la-sm"
|
||||||
|
outlined dense emit-value map-options
|
||||||
|
>
|
||||||
|
<template v-slot:selected-item="scope">
|
||||||
|
<div >{{ scope.opt.label }}</div>
|
||||||
|
<div v-show="scope.opt.value" class="q-ml-sm" :class="scope.opt.value" style="width: 50px; height: 30px;"></div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template v-slot:option="scope">
|
||||||
|
<q-item
|
||||||
|
v-bind="scope.itemProps"
|
||||||
|
v-on="scope.itemEvents"
|
||||||
|
>
|
||||||
|
<q-item-section>
|
||||||
|
<q-item-label v-html="scope.opt.label" />
|
||||||
|
</q-item-section>
|
||||||
|
<q-item-section v-show="scope.opt.value" :class="scope.opt.value" style="min-width: 70px; min-height: 50px"/>
|
||||||
|
</q-item>
|
||||||
|
</template>
|
||||||
|
</q-select>
|
||||||
|
|
||||||
|
<div class="q-px-xs"/>
|
||||||
|
<q-btn class="q-ml-sm" round dense color="blue" icon="la la-plus" @click.stop="loadWallpaperFileClick">
|
||||||
|
<q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">Добавить файл обоев</q-tooltip>
|
||||||
|
</q-btn>
|
||||||
|
<q-btn class="q-ml-sm" round dense color="blue" icon="la la-minus" @click.stop="delWallpaper" :disable="wallpaper.indexOf('user-paper') != 0">
|
||||||
|
<q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">Удалить выбранные обои</q-tooltip>
|
||||||
|
</q-btn>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="q-mt-sm"/>
|
||||||
|
<div class="item row">
|
||||||
|
<div class="label-2"></div>
|
||||||
|
<div class="col row items-center">
|
||||||
|
<q-checkbox v-model="wallpaperIgnoreStatusBar" size="xs" label="Не включать строку статуса в обои" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<input type="file" ref="file" @change="loadWallpaperFile" style='display: none;'/>
|
||||||
|
|||||||
124
client/components/Reader/SettingsPage/include/ViewTab/Mode.inc
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
<!---------------------------------------------->
|
||||||
|
<div class="hidden part-header">Режим</div>
|
||||||
|
|
||||||
|
<div class="item row">
|
||||||
|
<div class="label-2"></div>
|
||||||
|
<div class="col row">
|
||||||
|
<q-checkbox v-model="dualPageMode" size="xs" label="Двухстраничный режим" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="part-header">Страницы</div>
|
||||||
|
<div class="item row">
|
||||||
|
<div class="label-2">Отступ границ</div>
|
||||||
|
<div class="col row">
|
||||||
|
<NumInput class="col-left" v-model="indentLR" :min="0" :max="2000">
|
||||||
|
<q-tooltip :delay="1000" anchor="top middle" self="bottom middle" content-style="font-size: 80%">
|
||||||
|
Слева/справа от края экрана
|
||||||
|
</q-tooltip>
|
||||||
|
</NumInput>
|
||||||
|
<div class="q-px-sm"/>
|
||||||
|
<NumInput class="col" v-model="indentTB" :min="0" :max="2000">
|
||||||
|
<q-tooltip :delay="1000" anchor="top middle" self="bottom middle" content-style="font-size: 80%">
|
||||||
|
Сверху/снизу от края экрана
|
||||||
|
</q-tooltip>
|
||||||
|
</NumInput>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-show="dualPageMode" class="item row">
|
||||||
|
<div class="label-2">Отступ внутри</div>
|
||||||
|
<div class="col row">
|
||||||
|
<NumInput class="col-left" v-model="dualIndentLR" :min="0" :max="2000">
|
||||||
|
<q-tooltip :delay="1000" anchor="top middle" self="bottom middle" content-style="font-size: 80%">
|
||||||
|
Слева/справа внутри страницы
|
||||||
|
</q-tooltip>
|
||||||
|
</NumInput>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-show="dualPageMode">
|
||||||
|
<div class="part-header">Разделитель</div>
|
||||||
|
|
||||||
|
<div class="item row no-wrap">
|
||||||
|
<div class="label-2">Цвет</div>
|
||||||
|
<div class="col-left row">
|
||||||
|
<q-input class="col-left no-mp"
|
||||||
|
outlined dense
|
||||||
|
v-model="dualDivColorFiltered"
|
||||||
|
:rules="['hexColor']"
|
||||||
|
style="max-width: 150px"
|
||||||
|
:disable="dualDivColorAsText"
|
||||||
|
>
|
||||||
|
<template v-slot:prepend>
|
||||||
|
<q-icon name="la la-angle-down la-xs" class="cursor-pointer text-white" :style="colorPanStyle('div')">
|
||||||
|
<q-popup-proxy anchor="bottom middle" self="top middle">
|
||||||
|
<div>
|
||||||
|
<q-color v-model="dualDivColor"
|
||||||
|
no-header default-view="palette" :palette="predefineTextColors"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</q-popup-proxy>
|
||||||
|
</q-icon>
|
||||||
|
</template>
|
||||||
|
</q-input>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="q-px-xs"/>
|
||||||
|
<q-checkbox v-model="dualDivColorAsText" size="xs" label="Как у текста" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="item row">
|
||||||
|
<div class="label-2">Прозрачность</div>
|
||||||
|
<div class="col row">
|
||||||
|
<NumInput class="col-left" v-model="dualDivColorAlpha" :min="0" :max="1" :digits="2" :step="0.1"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="item row">
|
||||||
|
<div class="label-2">Ширина (px)</div>
|
||||||
|
<div class="col row">
|
||||||
|
<NumInput class="col-left" v-model="dualDivWidth" :min="0" :max="100">
|
||||||
|
<q-tooltip :delay="1000" anchor="top middle" self="bottom middle" content-style="font-size: 80%">
|
||||||
|
Ширина разделителя
|
||||||
|
</q-tooltip>
|
||||||
|
</NumInput>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="item row">
|
||||||
|
<div class="label-2">Высота (%)</div>
|
||||||
|
<div class="col row">
|
||||||
|
<NumInput class="col-left" v-model="dualDivHeight" :min="0" :max="100">
|
||||||
|
<q-tooltip :delay="1000" anchor="top middle" self="bottom middle" content-style="font-size: 80%">
|
||||||
|
Высота разделителя
|
||||||
|
</q-tooltip>
|
||||||
|
</NumInput>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="item row">
|
||||||
|
<div class="label-2">Пунктир</div>
|
||||||
|
<div class="col row">
|
||||||
|
<NumInput class="col-left" v-model="dualDivStrokeFill" :min="0" :max="2000">
|
||||||
|
<q-tooltip :delay="1000" anchor="top middle" self="bottom middle" content-style="font-size: 80%">
|
||||||
|
Заполнение пунктира
|
||||||
|
</q-tooltip>
|
||||||
|
</NumInput>
|
||||||
|
<div class="q-px-sm"/>
|
||||||
|
<NumInput class="col" v-model="dualDivStrokeGap" :min="0" :max="2000">
|
||||||
|
<q-tooltip :delay="1000" anchor="top middle" self="bottom middle" content-style="font-size: 80%">
|
||||||
|
Промежуток пунктира
|
||||||
|
</q-tooltip>
|
||||||
|
</NumInput>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="item row">
|
||||||
|
<div class="label-2">Ширина тени</div>
|
||||||
|
<div class="col row">
|
||||||
|
<NumInput class="col-left" v-model="dualDivShadowWidth" :min="0" :max="100"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
@@ -5,25 +5,53 @@
|
|||||||
<div class="label-2">Статус</div>
|
<div class="label-2">Статус</div>
|
||||||
<div class="col row">
|
<div class="col row">
|
||||||
<q-checkbox v-model="showStatusBar" size="xs" label="Показывать" />
|
<q-checkbox v-model="showStatusBar" size="xs" label="Показывать" />
|
||||||
<q-checkbox class="q-ml-sm" v-model="statusBarTop" size="xs" :disable="!showStatusBar" label="Вверху/внизу" />
|
<q-checkbox v-show="showStatusBar" class="q-ml-sm" v-model="statusBarTop" size="xs" label="Вверху/внизу" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="item row">
|
<div v-show="showStatusBar" class="item row no-wrap">
|
||||||
<div class="label-2">Высота</div>
|
<div class="label-2">Цвет</div>
|
||||||
<div class="col row">
|
<div class="col-left row">
|
||||||
<NumInput class="col-left" v-model="statusBarHeight" :min="5" :max="100" :disable="!showStatusBar"/>
|
<q-input class="col-left no-mp"
|
||||||
|
outlined dense
|
||||||
|
v-model="statusBarColorFiltered"
|
||||||
|
:rules="['hexColor']"
|
||||||
|
style="max-width: 150px"
|
||||||
|
:disable="statusBarColorAsText"
|
||||||
|
>
|
||||||
|
<template v-slot:prepend>
|
||||||
|
<q-icon name="la la-angle-down la-xs" class="cursor-pointer text-white" :style="colorPanStyle('statusbar')">
|
||||||
|
<q-popup-proxy anchor="bottom middle" self="top middle">
|
||||||
|
<div>
|
||||||
|
<q-color v-model="statusBarColor"
|
||||||
|
no-header default-view="palette" :palette="predefineTextColors"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</q-popup-proxy>
|
||||||
|
</q-icon>
|
||||||
|
</template>
|
||||||
|
</q-input>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="q-px-xs"/>
|
||||||
|
<q-checkbox v-model="statusBarColorAsText" size="xs" label="Как у текста"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="item row">
|
<div v-show="showStatusBar" class="item row">
|
||||||
<div class="label-2">Прозрачность</div>
|
<div class="label-2">Прозрачность</div>
|
||||||
<div class="col row">
|
<div class="col row">
|
||||||
<NumInput class="col-left" v-model="statusBarColorAlpha" :min="0" :max="1" :digits="2" :step="0.1" :disable="!showStatusBar"/>
|
<NumInput class="col-left" v-model="statusBarColorAlpha" :min="0" :max="1" :digits="2" :step="0.1"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="item row">
|
<div v-show="showStatusBar" class="item row">
|
||||||
|
<div class="label-2">Высота</div>
|
||||||
|
<div class="col row">
|
||||||
|
<NumInput class="col-left" v-model="statusBarHeight" :min="5" :max="100"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-show="showStatusBar" class="item row">
|
||||||
<div class="label-2"></div>
|
<div class="label-2"></div>
|
||||||
<div class="col row">
|
<div class="col row">
|
||||||
<q-checkbox v-model="statusBarClickOpen" size="xs" label="Открывать оригинал по клику">
|
<q-checkbox v-model="statusBarClickOpen" size="xs" label="Открывать оригинал по клику">
|
||||||
|
|||||||
@@ -15,23 +15,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="item row">
|
|
||||||
<div class="label-2">Отступ</div>
|
|
||||||
<div class="col row">
|
|
||||||
<NumInput class="col-left" v-model="indentLR" :min="0" :max="2000">
|
|
||||||
<q-tooltip :delay="1000" anchor="top middle" self="bottom middle" content-style="font-size: 80%">
|
|
||||||
Слева/справа
|
|
||||||
</q-tooltip>
|
|
||||||
</NumInput>
|
|
||||||
<div class="q-px-sm"/>
|
|
||||||
<NumInput class="col" v-model="indentTB" :min="0" :max="2000">
|
|
||||||
<q-tooltip :delay="1000" anchor="top middle" self="bottom middle" content-style="font-size: 80%">
|
|
||||||
Сверху/снизу
|
|
||||||
</q-tooltip>
|
|
||||||
</NumInput>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="item row">
|
<div class="item row">
|
||||||
<div class="label-2">Сдвиг</div>
|
<div class="label-2">Сдвиг</div>
|
||||||
<div class="col row">
|
<div class="col row">
|
||||||
@@ -123,7 +106,7 @@
|
|||||||
<div class="item row">
|
<div class="item row">
|
||||||
<div class="label-2"></div>
|
<div class="label-2"></div>
|
||||||
<div class="col row">
|
<div class="col row">
|
||||||
<q-checkbox v-model="imageFitWidth" :disable="!showImages" size="xs" label="Ширина не более размера экрана" />
|
<q-checkbox v-model="imageFitWidth" size="xs" label="Ширина не более размера страницы" :disable="!showImages || dualPageMode"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,109 @@ export default class DrawHelper {
|
|||||||
return this.context.measureText(text).width;
|
return this.context.measureText(text).width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
drawLine(line, lineIndex, baseLineIndex, sel, imageDrawn) {
|
||||||
|
/* line:
|
||||||
|
{
|
||||||
|
begin: Number,
|
||||||
|
end: Number,
|
||||||
|
first: Boolean,
|
||||||
|
last: Boolean,
|
||||||
|
parts: array of {
|
||||||
|
style: {bold: Boolean, italic: Boolean, center: Boolean},
|
||||||
|
image: {local: Boolean, inline: Boolean, id: String, imageLine: Number, lineCount: Number, paraIndex: Number},
|
||||||
|
text: String,
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
let out = '<div>';
|
||||||
|
|
||||||
|
let lineText = '';
|
||||||
|
let center = false;
|
||||||
|
let space = 0;
|
||||||
|
let j = 0;
|
||||||
|
//формируем строку
|
||||||
|
for (const part of line.parts) {
|
||||||
|
let tOpen = '';
|
||||||
|
tOpen += (part.style.bold ? '<b>' : '');
|
||||||
|
tOpen += (part.style.italic ? '<i>' : '');
|
||||||
|
tOpen += (part.style.sup ? '<span style="vertical-align: baseline; position: relative; line-height: 0; top: -0.3em">' : '');
|
||||||
|
tOpen += (part.style.sub ? '<span style="vertical-align: baseline; position: relative; line-height: 0; top: 0.3em">' : '');
|
||||||
|
let tClose = '';
|
||||||
|
tClose += (part.style.sub ? '</span>' : '');
|
||||||
|
tClose += (part.style.sup ? '</span>' : '');
|
||||||
|
tClose += (part.style.italic ? '</i>' : '');
|
||||||
|
tClose += (part.style.bold ? '</b>' : '');
|
||||||
|
|
||||||
|
let text = '';
|
||||||
|
if (lineIndex == 0 && this.searching) {
|
||||||
|
for (let k = 0; k < part.text.length; k++) {
|
||||||
|
text += (sel.has(j) ? `<ins>${part.text[k]}</ins>` : part.text[k]);
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
text = part.text;
|
||||||
|
|
||||||
|
if (text && text.trim() == '')
|
||||||
|
text = `<span style="white-space: pre">${text}</span>`;
|
||||||
|
|
||||||
|
lineText += `${tOpen}${text}${tClose}`;
|
||||||
|
|
||||||
|
center = center || part.style.center;
|
||||||
|
space = (part.style.space > space ? part.style.space : space);
|
||||||
|
|
||||||
|
//избражения
|
||||||
|
//image: {local: Boolean, inline: Boolean, id: String, imageLine: Number, lineCount: Number, paraIndex: Number, w: Number, h: Number},
|
||||||
|
const img = part.image;
|
||||||
|
if (img && img.id && !img.inline && !imageDrawn.has(img.paraIndex)) {
|
||||||
|
const bin = this.parsed.binary[img.id];
|
||||||
|
if (bin) {
|
||||||
|
let resize = '';
|
||||||
|
if (bin.h > img.h) {
|
||||||
|
resize = `height: ${img.h}px`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const left = (this.w - img.w)/2;
|
||||||
|
const top = ((img.lineCount*this.lineHeight - img.h)/2) + (lineIndex - baseLineIndex - img.imageLine)*this.lineHeight;
|
||||||
|
if (img.local) {
|
||||||
|
lineText += `<img src="data:${bin.type};base64,${bin.data}" style="position: absolute; left: ${left}px; top: ${top}px; ${resize}"/>`;
|
||||||
|
} else {
|
||||||
|
lineText += `<img src="${img.id}" style="position: absolute; left: ${left}px; top: ${top}px; ${resize}"/>`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
imageDrawn.add(img.paraIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (img && img.id && img.inline) {
|
||||||
|
if (img.local) {
|
||||||
|
const bin = this.parsed.binary[img.id];
|
||||||
|
if (bin) {
|
||||||
|
let resize = '';
|
||||||
|
if (bin.h > this.fontSize) {
|
||||||
|
resize = `height: ${this.fontSize - 3}px`;
|
||||||
|
}
|
||||||
|
lineText += `<img src="data:${bin.type};base64,${bin.data}" style="${resize}"/>`;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const centerStyle = (center ? `text-align: center; text-align-last: center; width: ${this.w}px` : '')
|
||||||
|
if ((line.first || space) && !center) {
|
||||||
|
let p = (line.first ? this.p : 0);
|
||||||
|
p = (space ? p + this.p*space : p);
|
||||||
|
lineText = `<span style="display: inline-block; margin-left: ${p}px"></span>${lineText}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (line.last || center)
|
||||||
|
lineText = `<span style="display: inline-block; ${centerStyle}">${lineText}</span>`;
|
||||||
|
|
||||||
|
out += lineText + '</div>';
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
drawPage(lines, isScrolling) {
|
drawPage(lines, isScrolling) {
|
||||||
if (!this.lastBook || this.pageLineCount < 1 || !this.book || !lines || !this.parsed.textLength)
|
if (!this.lastBook || this.pageLineCount < 1 || !this.book || !lines || !this.parsed.textLength)
|
||||||
return '';
|
return '';
|
||||||
@@ -26,134 +129,65 @@ export default class DrawHelper {
|
|||||||
const font = this.fontByStyle({});
|
const font = this.fontByStyle({});
|
||||||
const justify = (this.textAlignJustify ? 'text-align: justify; text-align-last: justify;' : '');
|
const justify = (this.textAlignJustify ? 'text-align: justify; text-align-last: justify;' : '');
|
||||||
|
|
||||||
let out = `<div style="width: ${this.w}px; height: ${this.h + (isScrolling ? this.lineHeight : 0)}px;` +
|
const boxH = this.h + (isScrolling ? this.lineHeight : 0);
|
||||||
|
let out = `<div class="row no-wrap" style="width: ${this.boxW}px; height: ${boxH}px;` +
|
||||||
` position: absolute; top: ${this.fontSize*this.textShift}px; color: ${this.textColor}; font: ${font}; ${justify}` +
|
` position: absolute; top: ${this.fontSize*this.textShift}px; color: ${this.textColor}; font: ${font}; ${justify}` +
|
||||||
` line-height: ${this.lineHeight}px; white-space: nowrap;">`;
|
` line-height: ${this.lineHeight}px; white-space: nowrap;">`;
|
||||||
|
|
||||||
let imageDrawn = new Set();
|
let imageDrawn1 = new Set();
|
||||||
|
let imageDrawn2 = new Set();
|
||||||
let len = lines.length;
|
let len = lines.length;
|
||||||
const lineCount = this.pageLineCount + (isScrolling ? 1 : 0);
|
const lineCount = this.pageLineCount + (isScrolling ? 1 : 0);
|
||||||
len = (len > lineCount ? lineCount : len);
|
len = (len > lineCount ? lineCount : len);
|
||||||
|
|
||||||
for (let i = 0; i < len; i++) {
|
//поиск
|
||||||
const line = lines[i];
|
let sel = new Set();
|
||||||
/* line:
|
if (len > 0 && this.searching) {
|
||||||
{
|
const line = lines[0];
|
||||||
begin: Number,
|
let pureText = '';
|
||||||
end: Number,
|
for (const part of line.parts) {
|
||||||
first: Boolean,
|
pureText += part.text;
|
||||||
last: Boolean,
|
|
||||||
parts: array of {
|
|
||||||
style: {bold: Boolean, italic: Boolean, center: Boolean},
|
|
||||||
image: {local: Boolean, inline: Boolean, id: String, imageLine: Number, lineCount: Number, paraIndex: Number},
|
|
||||||
text: String,
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
let sel = new Set();
|
|
||||||
//поиск
|
|
||||||
if (i == 0 && this.searching) {
|
|
||||||
let pureText = '';
|
|
||||||
for (const part of line.parts) {
|
|
||||||
pureText += part.text;
|
|
||||||
}
|
|
||||||
|
|
||||||
pureText = pureText.toLowerCase();
|
|
||||||
let j = 0;
|
|
||||||
while (1) {// eslint-disable-line no-constant-condition
|
|
||||||
j = pureText.indexOf(this.needle, j);
|
|
||||||
if (j >= 0) {
|
|
||||||
for (let k = 0; k < this.needle.length; k++) {
|
|
||||||
sel.add(j + k);
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
break;
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let lineText = '';
|
pureText = pureText.toLowerCase();
|
||||||
let center = false;
|
|
||||||
let space = 0;
|
|
||||||
let j = 0;
|
let j = 0;
|
||||||
//формируем строку
|
while (1) {// eslint-disable-line no-constant-condition
|
||||||
for (const part of line.parts) {
|
j = pureText.indexOf(this.needle, j);
|
||||||
let tOpen = '';
|
if (j >= 0) {
|
||||||
tOpen += (part.style.bold ? '<b>' : '');
|
for (let k = 0; k < this.needle.length; k++) {
|
||||||
tOpen += (part.style.italic ? '<i>' : '');
|
sel.add(j + k);
|
||||||
tOpen += (part.style.sup ? '<span style="vertical-align: baseline; position: relative; line-height: 0; top: -0.3em">' : '');
|
|
||||||
tOpen += (part.style.sub ? '<span style="vertical-align: baseline; position: relative; line-height: 0; top: 0.3em">' : '');
|
|
||||||
let tClose = '';
|
|
||||||
tClose += (part.style.sub ? '</span>' : '');
|
|
||||||
tClose += (part.style.sup ? '</span>' : '');
|
|
||||||
tClose += (part.style.italic ? '</i>' : '');
|
|
||||||
tClose += (part.style.bold ? '</b>' : '');
|
|
||||||
|
|
||||||
let text = '';
|
|
||||||
if (i == 0 && this.searching) {
|
|
||||||
for (let k = 0; k < part.text.length; k++) {
|
|
||||||
text += (sel.has(j) ? `<ins>${part.text[k]}</ins>` : part.text[k]);
|
|
||||||
j++;
|
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
text = part.text;
|
break;
|
||||||
|
j++;
|
||||||
if (text && text.trim() == '')
|
|
||||||
text = `<span style="white-space: pre">${text}</span>`;
|
|
||||||
|
|
||||||
lineText += `${tOpen}${text}${tClose}`;
|
|
||||||
|
|
||||||
center = center || part.style.center;
|
|
||||||
space = (part.style.space > space ? part.style.space : space);
|
|
||||||
|
|
||||||
//избражения
|
|
||||||
//image: {local: Boolean, inline: Boolean, id: String, imageLine: Number, lineCount: Number, paraIndex: Number, w: Number, h: Number},
|
|
||||||
const img = part.image;
|
|
||||||
if (img && img.id && !img.inline && !imageDrawn.has(img.paraIndex)) {
|
|
||||||
const bin = this.parsed.binary[img.id];
|
|
||||||
if (bin) {
|
|
||||||
let resize = '';
|
|
||||||
if (bin.h > img.h) {
|
|
||||||
resize = `height: ${img.h}px`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const left = (this.w - img.w)/2;
|
|
||||||
const top = ((img.lineCount*this.lineHeight - img.h)/2) + (i - img.imageLine)*this.lineHeight;
|
|
||||||
if (img.local) {
|
|
||||||
lineText += `<img src="data:${bin.type};base64,${bin.data}" style="position: absolute; left: ${left}px; top: ${top}px; ${resize}"/>`;
|
|
||||||
} else {
|
|
||||||
lineText += `<img src="${img.id}" style="position: absolute; left: ${left}px; top: ${top}px; ${resize}"/>`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
imageDrawn.add(img.paraIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (img && img.id && img.inline) {
|
|
||||||
if (img.local) {
|
|
||||||
const bin = this.parsed.binary[img.id];
|
|
||||||
if (bin) {
|
|
||||||
let resize = '';
|
|
||||||
if (bin.h > this.fontSize) {
|
|
||||||
resize = `height: ${this.fontSize - 3}px`;
|
|
||||||
}
|
|
||||||
lineText += `<img src="data:${bin.type};base64,${bin.data}" style="${resize}"/>`;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const centerStyle = (center ? `text-align: center; text-align-last: center; width: ${this.w}px` : '')
|
//отрисовка строк
|
||||||
if ((line.first || space) && !center) {
|
if (!this.dualPageMode) {
|
||||||
let p = (line.first ? this.p : 0);
|
out += `<div class="fit">`;
|
||||||
p = (space ? p + this.p*space : p);
|
for (let i = 0; i < len; i++) {
|
||||||
lineText = `<span style="display: inline-block; margin-left: ${p}px"></span>${lineText}`;
|
out += this.drawLine(lines[i], i, 0, sel, imageDrawn1);
|
||||||
}
|
}
|
||||||
|
out += `</div>`;
|
||||||
|
} else {
|
||||||
|
//левая страница
|
||||||
|
out += `<div style="width: ${this.w}px; margin-left: ${this.dualIndentLR}px; position: relative;">`;
|
||||||
|
const l2 = (this.pageRowsCount > len ? len : this.pageRowsCount);
|
||||||
|
for (let i = 0; i < l2; i++) {
|
||||||
|
out += this.drawLine(lines[i], i, 0, sel, imageDrawn1);
|
||||||
|
}
|
||||||
|
out += '</div>';
|
||||||
|
|
||||||
if (line.last || center)
|
//разделитель
|
||||||
lineText = `<span style="display: inline-block; ${centerStyle}">${lineText}</span>`;
|
out += `<div style="width: ${this.dualIndentLR*2}px;"></div>`;
|
||||||
|
|
||||||
out += (i > 0 ? '<br>' : '') + lineText;
|
//правая страница
|
||||||
|
out += `<div style="width: ${this.w}px; margin-right: ${this.dualIndentLR}px; position: relative;">`;
|
||||||
|
for (let i = l2; i < len; i++) {
|
||||||
|
out += this.drawLine(lines[i], i, l2, sel, imageDrawn2);
|
||||||
|
}
|
||||||
|
out += '</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
out += '</div>';
|
out += '</div>';
|
||||||
@@ -179,8 +213,8 @@ export default class DrawHelper {
|
|||||||
|
|
||||||
if (w1 + w2 + w3 <= w && w3 > (10 + fh2)) {
|
if (w1 + w2 + w3 <= w && w3 > (10 + fh2)) {
|
||||||
const barWidth = w - w1 - w2 - fh2;
|
const barWidth = w - w1 - w2 - fh2;
|
||||||
out += this.strokeRect(x + w1, y + pad, barWidth, fh - 2, this.statusBarColor);
|
out += this.strokeRect(x + w1, y + pad, barWidth, fh - 2, this.statusBarRgbaColor);
|
||||||
out += this.fillRect(x + w1 + 2, y + pad + 2, (barWidth - 4)*read, fh - 6, this.statusBarColor);
|
out += this.fillRect(x + w1 + 2, y + pad + 2, (barWidth - 4)*read, fh - 6, this.statusBarRgbaColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (w1 <= w)
|
if (w1 <= w)
|
||||||
@@ -193,12 +227,12 @@ export default class DrawHelper {
|
|||||||
|
|
||||||
let out = `<div class="layout" style="` +
|
let out = `<div class="layout" style="` +
|
||||||
`width: ${this.realWidth}px; height: ${statusBarHeight}px; ` +
|
`width: ${this.realWidth}px; height: ${statusBarHeight}px; ` +
|
||||||
`color: ${this.statusBarColor}">`;
|
`color: ${this.statusBarRgbaColor}">`;
|
||||||
|
|
||||||
const fontSize = statusBarHeight*0.75;
|
const fontSize = statusBarHeight*0.75;
|
||||||
const font = 'bold ' + this.fontBySize(fontSize);
|
const font = 'bold ' + this.fontBySize(fontSize);
|
||||||
|
|
||||||
out += this.fillRect(0, (statusBarTop ? statusBarHeight : 0), this.realWidth, 1, this.statusBarColor);
|
out += this.fillRect(0, (statusBarTop ? statusBarHeight : 0), this.realWidth, 1, this.statusBarRgbaColor);
|
||||||
|
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
const time = `${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}`;
|
const time = `${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}`;
|
||||||
@@ -207,7 +241,7 @@ export default class DrawHelper {
|
|||||||
|
|
||||||
out += this.fillTextShift(this.fittingString(title, this.realWidth/2 - fontSize - 3, font), fontSize, 2, font, fontSize);
|
out += this.fillTextShift(this.fittingString(title, this.realWidth/2 - fontSize - 3, font), fontSize, 2, font, fontSize);
|
||||||
|
|
||||||
out += this.drawPercentBar(this.realWidth/2, 2, this.realWidth/2 - timeW - 2*fontSize, statusBarHeight, font, fontSize, bookPos, textLength, imageNum, imageLength);
|
out += this.drawPercentBar(this.realWidth/2 + fontSize, 2, this.realWidth/2 - timeW - 3*fontSize, statusBarHeight, font, fontSize, bookPos, textLength, imageNum, imageLength);
|
||||||
|
|
||||||
out += '</div>';
|
out += '</div>';
|
||||||
return out;
|
return out;
|
||||||
@@ -274,7 +308,7 @@ export default class DrawHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async doPageAnimationRightShift(page1, page2, duration, isDown, animation1Finish) {
|
async doPageAnimationRightShift(page1, page2, duration, isDown, animation1Finish) {
|
||||||
const s = this.w + this.fontSize;
|
const s = this.boxW + this.fontSize;
|
||||||
|
|
||||||
if (isDown) {
|
if (isDown) {
|
||||||
page1.style.transform = `translateX(${s}px)`;
|
page1.style.transform = `translateX(${s}px)`;
|
||||||
|
|||||||
93
client/components/Reader/TextPage/TextPage.css
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
@keyframes page1-animation-thaw {
|
||||||
|
0% { opacity: 0; }
|
||||||
|
100% { opacity: 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes page2-animation-thaw {
|
||||||
|
0% { opacity: 1; }
|
||||||
|
100% { opacity: 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.paper1 {
|
||||||
|
background: url("images/paper1.jpg") center;
|
||||||
|
background-size: 100% 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.paper2 {
|
||||||
|
background: url("images/paper2.jpg") center;
|
||||||
|
background-size: 100% 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.paper3 {
|
||||||
|
background: url("images/paper3.jpg") center;
|
||||||
|
background-size: 100% 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.paper4 {
|
||||||
|
background: url("images/paper4.jpg") center;
|
||||||
|
background-size: 100% 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.paper5 {
|
||||||
|
background: url("images/paper5.jpg") center;
|
||||||
|
background-size: 100% 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.paper6 {
|
||||||
|
background: url("images/paper6.jpg") center;
|
||||||
|
background-size: 100% 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.paper7 {
|
||||||
|
background: url("images/paper7.jpg") center;
|
||||||
|
background-size: 100% 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.paper8 {
|
||||||
|
background: url("images/paper8.jpg") center;
|
||||||
|
background-size: 100% 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.paper9 {
|
||||||
|
background: url("images/paper9.jpg");
|
||||||
|
}
|
||||||
|
|
||||||
|
.paper10 {
|
||||||
|
background: url("images/paper10.png") center;
|
||||||
|
background-size: 100% 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.paper11 {
|
||||||
|
background: url("images/paper11.png") center;
|
||||||
|
background-size: 100% 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.paper12 {
|
||||||
|
background: url("images/paper12.png") center;
|
||||||
|
background-size: 100% 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.paper13 {
|
||||||
|
background: url("images/paper13.png") center;
|
||||||
|
background-size: 100% 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.paper14 {
|
||||||
|
background: url("images/paper14.png") center;
|
||||||
|
background-size: 100% 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.paper15 {
|
||||||
|
background: url("images/paper15.png") center;
|
||||||
|
background-size: 100% 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.paper16 {
|
||||||
|
background: url("images/paper16.png") center;
|
||||||
|
background-size: 100% 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.paper17 {
|
||||||
|
background: url("images/paper17.png") center;
|
||||||
|
background-size: 100% 100%;
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<div ref="main" class="main">
|
<div ref="main" class="main">
|
||||||
<div class="layout back" @wheel.prevent.stop="onMouseWheel">
|
<div class="layout back" @wheel.prevent.stop="onMouseWheel">
|
||||||
<div v-html="background"></div>
|
<div class="absolute" v-html="background"></div>
|
||||||
<!-- img -->
|
<div class="absolute" v-html="pageDivider"></div>
|
||||||
</div>
|
</div>
|
||||||
<div ref="scrollBox1" class="layout over-hidden" @wheel.prevent.stop="onMouseWheel">
|
<div ref="scrollBox1" class="layout over-hidden" @wheel.prevent.stop="onMouseWheel">
|
||||||
<div ref="scrollingPage1" class="layout over-hidden" @transitionend="onPage1TransitionEnd" @animationend="onPage1AnimationEnd">
|
<div ref="scrollingPage1" class="layout over-hidden" @transitionend="onPage1TransitionEnd" @animationend="onPage1AnimationEnd">
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
<div v-show="!clickControl && showStatusBar && statusBarClickOpen" class="layout" v-html="statusBarClickable" @mousedown.prevent.stop @touchstart.stop
|
<div v-show="!clickControl && showStatusBar && statusBarClickOpen" class="layout" v-html="statusBarClickable" @mousedown.prevent.stop @touchstart.stop
|
||||||
@click.prevent.stop="onStatusBarClick">
|
@click.prevent.stop="onStatusBarClick">
|
||||||
</div>
|
</div>
|
||||||
<!-- невидимым делать нельзя, вовремя не подгружаютя шрифты -->
|
<!-- невидимым делать нельзя (display: none), вовремя не подгружаютя шрифты -->
|
||||||
<canvas ref="offscreenCanvas" class="layout" style="visibility: hidden"></canvas>
|
<canvas ref="offscreenCanvas" class="layout" style="visibility: hidden"></canvas>
|
||||||
<div ref="measureWidth" style="position: absolute; visibility: hidden"></div>
|
<div ref="measureWidth" style="position: absolute; visibility: hidden"></div>
|
||||||
</div>
|
</div>
|
||||||
@@ -40,8 +40,13 @@ import Component from 'vue-class-component';
|
|||||||
import {loadCSS} from 'fg-loadcss';
|
import {loadCSS} from 'fg-loadcss';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
import './TextPage.css';
|
||||||
|
|
||||||
import * as utils from '../../../share/utils';
|
import * as utils from '../../../share/utils';
|
||||||
|
import dynamicCss from '../../../share/dynamicCss';
|
||||||
|
|
||||||
import bookManager from '../share/bookManager';
|
import bookManager from '../share/bookManager';
|
||||||
|
import wallpaperStorage from '../share/wallpaperStorage';
|
||||||
import DrawHelper from './DrawHelper';
|
import DrawHelper from './DrawHelper';
|
||||||
import rstore from '../../../store/modules/reader';
|
import rstore from '../../../store/modules/reader';
|
||||||
import {clickMap} from '../share/clickMap';
|
import {clickMap} from '../share/clickMap';
|
||||||
@@ -74,6 +79,7 @@ class TextPage extends Vue {
|
|||||||
clickControl = true;
|
clickControl = true;
|
||||||
|
|
||||||
background = null;
|
background = null;
|
||||||
|
pageDivider = null;
|
||||||
page1 = null;
|
page1 = null;
|
||||||
page2 = null;
|
page2 = null;
|
||||||
statusBar = null;
|
statusBar = null;
|
||||||
@@ -110,7 +116,11 @@ class TextPage extends Vue {
|
|||||||
|
|
||||||
this.debouncedDrawStatusBar = _.throttle(() => {
|
this.debouncedDrawStatusBar = _.throttle(() => {
|
||||||
this.drawStatusBar();
|
this.drawStatusBar();
|
||||||
}, 60);
|
}, 60);
|
||||||
|
|
||||||
|
this.debouncedDrawPageDividerAndOrnament = _.throttle(() => {
|
||||||
|
this.drawPageDividerAndOrnament();
|
||||||
|
}, 65);
|
||||||
|
|
||||||
this.debouncedLoadSettings = _.debounce(() => {
|
this.debouncedLoadSettings = _.debounce(() => {
|
||||||
this.loadSettings();
|
this.loadSettings();
|
||||||
@@ -161,14 +171,16 @@ class TextPage extends Vue {
|
|||||||
this.$refs.layoutEvents.style.width = this.realWidth + 'px';
|
this.$refs.layoutEvents.style.width = this.realWidth + 'px';
|
||||||
this.$refs.layoutEvents.style.height = this.realHeight + 'px';
|
this.$refs.layoutEvents.style.height = this.realHeight + 'px';
|
||||||
|
|
||||||
this.w = this.realWidth - 2*this.indentLR;
|
const dual = (this.dualPageMode ? 2 : 1);
|
||||||
|
this.boxW = this.realWidth - 2*this.indentLR;
|
||||||
|
this.w = this.boxW/dual - (this.dualPageMode ? 2*this.dualIndentLR : 0);
|
||||||
|
|
||||||
this.scrollHeight = this.realHeight - (this.showStatusBar ? this.statusBarHeight : 0);
|
this.scrollHeight = this.realHeight - (this.showStatusBar ? this.statusBarHeight : 0);
|
||||||
this.h = this.scrollHeight - 2*this.indentTB;
|
this.h = this.scrollHeight - 2*this.indentTB;
|
||||||
this.lineHeight = this.fontSize + this.lineInterval;
|
|
||||||
this.pageLineCount = 1 + Math.floor((this.h - this.lineHeight + this.lineInterval/2)/this.lineHeight);
|
|
||||||
|
|
||||||
this.$refs.scrollingPage1.style.width = this.w + 'px';
|
this.lineHeight = this.fontSize + this.lineInterval;
|
||||||
this.$refs.scrollingPage2.style.width = this.w + 'px';
|
this.pageRowsCount = 1 + Math.floor((this.h - this.lineHeight + this.lineInterval/2)/this.lineHeight);
|
||||||
|
this.pageLineCount = (this.dualPageMode ? this.pageRowsCount*2 : this.pageRowsCount)
|
||||||
|
|
||||||
//stuff
|
//stuff
|
||||||
this.currentAnimation = '';
|
this.currentAnimation = '';
|
||||||
@@ -180,7 +192,10 @@ class TextPage extends Vue {
|
|||||||
this.$refs.statusBar.style.left = '0px';
|
this.$refs.statusBar.style.left = '0px';
|
||||||
this.$refs.statusBar.style.top = (this.statusBarTop ? 1 : this.realHeight - this.statusBarHeight) + 'px';
|
this.$refs.statusBar.style.top = (this.statusBarTop ? 1 : this.realHeight - this.statusBarHeight) + 'px';
|
||||||
|
|
||||||
this.statusBarColor = this.hex2rgba(this.textColor || '#000000', this.statusBarColorAlpha);
|
const sbColor = (this.statusBarColorAsText ? this.textColor : this.statusBarColor);
|
||||||
|
this.statusBarRgbaColor = this.hex2rgba(sbColor || '#000000', this.statusBarColorAlpha);
|
||||||
|
const ddColor = (this.dualDivColorAsText ? this.textColor : this.dualDivColor);
|
||||||
|
this.dualDivRgbaColor = this.hex2rgba(ddColor || '#000000', this.dualDivColorAlpha);
|
||||||
|
|
||||||
//drawHelper
|
//drawHelper
|
||||||
this.drawHelper.realWidth = this.realWidth;
|
this.drawHelper.realWidth = this.realWidth;
|
||||||
@@ -188,10 +203,20 @@ class TextPage extends Vue {
|
|||||||
this.drawHelper.lastBook = this.lastBook;
|
this.drawHelper.lastBook = this.lastBook;
|
||||||
this.drawHelper.book = this.book;
|
this.drawHelper.book = this.book;
|
||||||
this.drawHelper.parsed = this.parsed;
|
this.drawHelper.parsed = this.parsed;
|
||||||
|
this.drawHelper.pageRowsCount = this.pageRowsCount;
|
||||||
this.drawHelper.pageLineCount = this.pageLineCount;
|
this.drawHelper.pageLineCount = this.pageLineCount;
|
||||||
|
|
||||||
|
this.drawHelper.dualPageMode = this.dualPageMode;
|
||||||
|
this.drawHelper.dualIndentLR = this.dualIndentLR;
|
||||||
|
/*this.drawHelper.dualDivWidth = this.dualDivWidth;
|
||||||
|
this.drawHelper.dualDivHeight = this.dualDivHeight;
|
||||||
|
this.drawHelper.dualDivRgbaColor = this.dualDivRgbaColor;
|
||||||
|
this.drawHelper.dualDivStrokeFill = this.dualDivStrokeFill;
|
||||||
|
this.drawHelper.dualDivStrokeGap = this.dualDivStrokeGap;
|
||||||
|
this.drawHelper.dualDivShadowWidth = this.dualDivShadowWidth;*/
|
||||||
|
|
||||||
this.drawHelper.backgroundColor = this.backgroundColor;
|
this.drawHelper.backgroundColor = this.backgroundColor;
|
||||||
this.drawHelper.statusBarColor = this.statusBarColor;
|
this.drawHelper.statusBarRgbaColor = this.statusBarRgbaColor;
|
||||||
this.drawHelper.fontStyle = this.fontStyle;
|
this.drawHelper.fontStyle = this.fontStyle;
|
||||||
this.drawHelper.fontWeight = this.fontWeight;
|
this.drawHelper.fontWeight = this.fontWeight;
|
||||||
this.drawHelper.fontSize = this.fontSize;
|
this.drawHelper.fontSize = this.fontSize;
|
||||||
@@ -200,6 +225,7 @@ class TextPage extends Vue {
|
|||||||
this.drawHelper.textColor = this.textColor;
|
this.drawHelper.textColor = this.textColor;
|
||||||
this.drawHelper.textShift = this.textShift;
|
this.drawHelper.textShift = this.textShift;
|
||||||
this.drawHelper.p = this.p;
|
this.drawHelper.p = this.p;
|
||||||
|
this.drawHelper.boxW = this.boxW;
|
||||||
this.drawHelper.w = this.w;
|
this.drawHelper.w = this.w;
|
||||||
this.drawHelper.h = this.h;
|
this.drawHelper.h = this.h;
|
||||||
this.drawHelper.indentLR = this.indentLR;
|
this.drawHelper.indentLR = this.indentLR;
|
||||||
@@ -226,34 +252,57 @@ class TextPage extends Vue {
|
|||||||
//statusBar
|
//statusBar
|
||||||
this.statusBarClickable = this.drawHelper.statusBarClickable(this.statusBarTop, this.statusBarHeight);
|
this.statusBarClickable = this.drawHelper.statusBarClickable(this.statusBarTop, this.statusBarHeight);
|
||||||
|
|
||||||
|
//wallpaper css, асинхронно
|
||||||
|
(async() => {
|
||||||
|
const wallpaperDataLength = await wallpaperStorage.getLength();
|
||||||
|
if (wallpaperDataLength !== this.wallpaperDataLength) {//оптимизация
|
||||||
|
this.wallpaperDataLength = wallpaperDataLength;
|
||||||
|
|
||||||
|
let newCss = '';
|
||||||
|
for (const wp of this.userWallpapers) {
|
||||||
|
const data = await wallpaperStorage.getData(wp.cssClass);
|
||||||
|
|
||||||
|
if (!data) {
|
||||||
|
//здесь будем восстанавливать данные с сервера
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data) {
|
||||||
|
newCss += `.${wp.cssClass} {background: url(${data}) center; background-size: 100% 100%;}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dynamicCss.replace('wallpapers', newCss);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
//parsed
|
//parsed
|
||||||
if (this.parsed) {
|
if (this.parsed) {
|
||||||
this.parsed.p = this.p;
|
let wideLine = wideLetter;
|
||||||
this.parsed.w = this.w;// px, ширина текста
|
if (!this.drawHelper.measureText(wideLine, {}))
|
||||||
this.parsed.font = this.font;
|
|
||||||
this.parsed.fontSize = this.fontSize;
|
|
||||||
this.parsed.wordWrap = this.wordWrap;
|
|
||||||
this.parsed.cutEmptyParagraphs = this.cutEmptyParagraphs;
|
|
||||||
this.parsed.addEmptyParagraphs = this.addEmptyParagraphs;
|
|
||||||
let t = wideLetter;
|
|
||||||
if (!this.drawHelper.measureText(t, {}))
|
|
||||||
throw new Error('Ошибка measureText');
|
throw new Error('Ошибка measureText');
|
||||||
while (this.drawHelper.measureText(t, {}) < this.w) t += wideLetter;
|
while (this.drawHelper.measureText(wideLine, {}) < this.w) wideLine += wideLetter;
|
||||||
this.parsed.maxWordLength = t.length - 1;
|
|
||||||
this.parsed.measureText = this.drawHelper.measureText.bind(this.drawHelper);
|
|
||||||
this.parsed.lineHeight = this.lineHeight;
|
|
||||||
this.parsed.showImages = this.showImages;
|
|
||||||
this.parsed.showInlineImagesInCenter = this.showInlineImagesInCenter;
|
|
||||||
this.parsed.imageHeightLines = this.imageHeightLines;
|
|
||||||
this.parsed.imageFitWidth = this.imageFitWidth;
|
|
||||||
this.parsed.compactTextPerc = this.compactTextPerc;
|
|
||||||
|
|
||||||
this.parsed.testText = 'Это тестовый текст. Его ширина выдается системой неверно некоторое время.';
|
this.parsed.setSettings({
|
||||||
this.parsed.testWidth = this.drawHelper.measureText(this.parsed.testText, {});
|
p: this.p,
|
||||||
|
w: this.w,
|
||||||
|
font: this.font,
|
||||||
|
fontSize: this.fontSize,
|
||||||
|
wordWrap: this.wordWrap,
|
||||||
|
cutEmptyParagraphs: this.cutEmptyParagraphs,
|
||||||
|
addEmptyParagraphs: this.addEmptyParagraphs,
|
||||||
|
maxWordLength: wideLine.length - 1,
|
||||||
|
lineHeight: this.lineHeight,
|
||||||
|
showImages: this.showImages,
|
||||||
|
showInlineImagesInCenter: this.showInlineImagesInCenter,
|
||||||
|
imageHeightLines: this.imageHeightLines,
|
||||||
|
imageFitWidth: this.imageFitWidth,
|
||||||
|
compactTextPerc: this.compactTextPerc,
|
||||||
|
testWidth: 0,
|
||||||
|
measureText: this.drawHelper.measureText.bind(this.drawHelper),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//scrolling page
|
//scrolling page
|
||||||
const pageSpace = this.scrollHeight - this.pageLineCount*this.lineHeight;
|
const pageSpace = this.scrollHeight - this.pageRowsCount*this.lineHeight;
|
||||||
let top = pageSpace/2;
|
let top = pageSpace/2;
|
||||||
if (this.showStatusBar)
|
if (this.showStatusBar)
|
||||||
top += this.statusBarHeight*(this.statusBarTop ? 1 : 0);
|
top += this.statusBarHeight*(this.statusBarTop ? 1 : 0);
|
||||||
@@ -262,14 +311,14 @@ class TextPage extends Vue {
|
|||||||
|
|
||||||
page1.perspective = page2.perspective = '3072px';
|
page1.perspective = page2.perspective = '3072px';
|
||||||
|
|
||||||
page1.width = page2.width = this.w + this.indentLR + 'px';
|
page1.width = page2.width = this.boxW + this.indentLR + 'px';
|
||||||
page1.height = page2.height = this.scrollHeight - (pageSpace > 0 ? pageSpace : 0) + 'px';
|
page1.height = page2.height = this.scrollHeight - (pageSpace > 0 ? pageSpace : 0) + 'px';
|
||||||
page1.top = page2.top = top + 'px';
|
page1.top = page2.top = top + 'px';
|
||||||
page1.left = page2.left = this.indentLR + 'px';
|
page1.left = page2.left = this.indentLR + 'px';
|
||||||
|
|
||||||
page1 = this.$refs.scrollingPage1.style;
|
page1 = this.$refs.scrollingPage1.style;
|
||||||
page2 = this.$refs.scrollingPage2.style;
|
page2 = this.$refs.scrollingPage2.style;
|
||||||
page1.width = page2.width = this.w + this.indentLR + 'px';
|
page1.width = page2.width = this.boxW + this.indentLR + 'px';
|
||||||
page1.height = page2.height = this.scrollHeight + this.lineHeight + 'px';
|
page1.height = page2.height = this.scrollHeight + this.lineHeight + 'px';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -333,20 +382,36 @@ class TextPage extends Vue {
|
|||||||
if (!omitLoadFonts)
|
if (!omitLoadFonts)
|
||||||
await this.loadFonts();
|
await this.loadFonts();
|
||||||
|
|
||||||
this.draw();
|
if (omitLoadFonts) {
|
||||||
|
this.draw();
|
||||||
// ширина шрифта некоторое время выдается неверно, поэтому
|
} else {
|
||||||
if (!omitLoadFonts) {
|
// ширина шрифта некоторое время выдается неверно,
|
||||||
const parsed = this.parsed;
|
// не удалось событийно отловить этот момент, поэтому костыль
|
||||||
|
while (this.checkingFont) {
|
||||||
let i = 0;
|
this.stopCheckingFont = true;
|
||||||
const t = this.parsed.testText;
|
|
||||||
while (i++ < 50 && this.parsed === parsed && this.drawHelper.measureText(t, {}) === this.parsed.testWidth)
|
|
||||||
await utils.sleep(100);
|
await utils.sleep(100);
|
||||||
|
}
|
||||||
|
|
||||||
if (this.parsed === parsed) {
|
this.checkingFont = true;
|
||||||
this.parsed.testWidth = this.drawHelper.measureText(t, {});
|
this.stopCheckingFont = false;
|
||||||
this.draw();
|
try {
|
||||||
|
const parsed = this.parsed;
|
||||||
|
|
||||||
|
let i = 0;
|
||||||
|
const t = 'Это тестовый текст. Его ширина выдается системой неправильно некоторое время.';
|
||||||
|
let twprev = 0;
|
||||||
|
//5 секунд проверяем изменения шрифта
|
||||||
|
while (!this.stopCheckingFont && i++ < 50 && this.parsed === parsed) {
|
||||||
|
const tw = this.drawHelper.measureText(t, {});
|
||||||
|
if (tw !== twprev) {
|
||||||
|
this.parsed.setSettings({testWidth: tw});
|
||||||
|
this.draw();
|
||||||
|
twprev = tw;
|
||||||
|
}
|
||||||
|
await utils.sleep(100);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
this.checkingFont = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -430,8 +495,18 @@ class TextPage extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setBackground() {
|
setBackground() {
|
||||||
this.background = `<div class="layout ${this.wallpaper}" style="width: ${this.realWidth}px; height: ${this.realHeight}px;` +
|
if (this.wallpaperIgnoreStatusBar) {
|
||||||
` background-color: ${this.backgroundColor}"></div>`;
|
this.background = `<div class="layout" style="width: ${this.realWidth}px; height: ${this.realHeight}px;` +
|
||||||
|
` background-color: ${this.backgroundColor}">` +
|
||||||
|
`<div class="layout ${this.wallpaper}" style="width: ${this.realWidth}px; height: ${this.scrollHeight}px; ` +
|
||||||
|
`top: ${(this.showStatusBar && this.statusBarTop ? this.statusBarHeight + 1 : 0)}px; position: relative;">` +
|
||||||
|
`</div>` +
|
||||||
|
`</div>`;
|
||||||
|
} else {
|
||||||
|
this.background = `<div class="layout ${this.wallpaper}" style="width: ${this.realWidth}px; height: ${this.realHeight}px;` +
|
||||||
|
` background-color: ${this.backgroundColor}"></div>`;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async onResize() {
|
async onResize() {
|
||||||
@@ -490,7 +565,7 @@ class TextPage extends Vue {
|
|||||||
|
|
||||||
async startTextScrolling() {
|
async startTextScrolling() {
|
||||||
if (this.doingScrolling || !this.book || !this.parsed.textLength || !this.linesDown || this.pageLineCount < 1 ||
|
if (this.doingScrolling || !this.book || !this.parsed.textLength || !this.linesDown || this.pageLineCount < 1 ||
|
||||||
this.linesDown.length <= this.pageLineCount) {
|
this.linesDown.length <= this.pageLineCount || this.dualPageMode) {
|
||||||
this.doStopScrolling();
|
this.doStopScrolling();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -608,6 +683,7 @@ class TextPage extends Vue {
|
|||||||
if (!this.pageChangeAnimation)
|
if (!this.pageChangeAnimation)
|
||||||
this.debouncedPrepareNextPage();
|
this.debouncedPrepareNextPage();
|
||||||
this.debouncedDrawStatusBar();
|
this.debouncedDrawStatusBar();
|
||||||
|
this.debouncedDrawPageDividerAndOrnament();
|
||||||
|
|
||||||
if (this.book && this.linesDown && this.linesDown.length < this.pageLineCount) {
|
if (this.book && this.linesDown && this.linesDown.length < this.pageLineCount) {
|
||||||
this.doEnd(true);
|
this.doEnd(true);
|
||||||
@@ -747,6 +823,25 @@ class TextPage extends Vue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
drawPageDividerAndOrnament() {
|
||||||
|
if (this.dualPageMode) {
|
||||||
|
this.pageDivider = `<div class="layout" style="width: ${this.realWidth}px; height: ${this.scrollHeight}px; ` +
|
||||||
|
`top: ${(this.showStatusBar && this.statusBarTop ? this.statusBarHeight + 1 : 0)}px; position: relative;">` +
|
||||||
|
`<div class="fit row justify-center items-center no-wrap">` +
|
||||||
|
`<div style="height: ${Math.round(this.scrollHeight*this.dualDivHeight/100)}px; width: ${this.dualDivWidth}px; ` +
|
||||||
|
`box-shadow: 0 0 ${this.dualDivShadowWidth}px ${this.dualDivRgbaColor}; ` +
|
||||||
|
`background-image: url("data:image/svg+xml;utf8,<svg width='100%' height='100%' xmlns='http://www.w3.org/2000/svg'>` +
|
||||||
|
`<line x1='${this.dualDivWidth/2}' y1='0' x2='${this.dualDivWidth/2}' y2='100%' stroke='${this.dualDivRgbaColor}' ` +
|
||||||
|
`stroke-width='${this.dualDivWidth}' stroke-dasharray='${this.dualDivStrokeFill} ${this.dualDivStrokeGap}'/>` +
|
||||||
|
`</svg>");">` +
|
||||||
|
`</div>` +
|
||||||
|
`</div>` +
|
||||||
|
`</div>`;
|
||||||
|
} else {
|
||||||
|
this.pageDivider = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
blinkCachedLoadMessage(state) {
|
blinkCachedLoadMessage(state) {
|
||||||
if (state === 'finish') {
|
if (state === 'finish') {
|
||||||
this.statusBarMessage = '';
|
this.statusBarMessage = '';
|
||||||
@@ -1161,60 +1256,3 @@ class TextPage extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style>
|
|
||||||
.paper1 {
|
|
||||||
background: url("images/paper1.jpg") center;
|
|
||||||
background-size: cover;
|
|
||||||
}
|
|
||||||
|
|
||||||
.paper2 {
|
|
||||||
background: url("images/paper2.jpg") center;
|
|
||||||
background-size: cover;
|
|
||||||
}
|
|
||||||
|
|
||||||
.paper3 {
|
|
||||||
background: url("images/paper3.jpg") center;
|
|
||||||
background-size: cover;
|
|
||||||
}
|
|
||||||
|
|
||||||
.paper4 {
|
|
||||||
background: url("images/paper4.jpg") center;
|
|
||||||
background-size: cover;
|
|
||||||
}
|
|
||||||
|
|
||||||
.paper5 {
|
|
||||||
background: url("images/paper5.jpg") center;
|
|
||||||
background-size: cover;
|
|
||||||
}
|
|
||||||
|
|
||||||
.paper6 {
|
|
||||||
background: url("images/paper6.jpg") center;
|
|
||||||
background-size: cover;
|
|
||||||
}
|
|
||||||
|
|
||||||
.paper7 {
|
|
||||||
background: url("images/paper7.jpg") center;
|
|
||||||
background-size: cover;
|
|
||||||
}
|
|
||||||
|
|
||||||
.paper8 {
|
|
||||||
background: url("images/paper8.jpg") center;
|
|
||||||
background-size: cover;
|
|
||||||
}
|
|
||||||
|
|
||||||
.paper9 {
|
|
||||||
background: url("images/paper9.jpg");
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes page1-animation-thaw {
|
|
||||||
0% { opacity: 0; }
|
|
||||||
100% { opacity: 1; }
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes page2-animation-thaw {
|
|
||||||
0% { opacity: 1; }
|
|
||||||
100% { opacity: 0; }
|
|
||||||
}
|
|
||||||
|
|
||||||
</style>
|
|
||||||
|
|||||||
BIN
client/components/Reader/TextPage/images/paper10.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
client/components/Reader/TextPage/images/paper11.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
client/components/Reader/TextPage/images/paper12.png
Normal file
|
After Width: | Height: | Size: 5.3 KiB |
BIN
client/components/Reader/TextPage/images/paper13.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
client/components/Reader/TextPage/images/paper14.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
client/components/Reader/TextPage/images/paper15.png
Normal file
|
After Width: | Height: | Size: 5.5 KiB |
BIN
client/components/Reader/TextPage/images/paper16.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
client/components/Reader/TextPage/images/paper17.png
Normal file
|
After Width: | Height: | Size: 5.3 KiB |
@@ -4,23 +4,55 @@ import * as utils from '../../../share/utils';
|
|||||||
|
|
||||||
const maxImageLineCount = 100;
|
const maxImageLineCount = 100;
|
||||||
|
|
||||||
|
// defaults
|
||||||
|
const defaultSettings = {
|
||||||
|
p: 30, //px, отступ параграфа
|
||||||
|
w: 500, //px, ширина страницы
|
||||||
|
|
||||||
|
font: '', //css описание шрифта
|
||||||
|
fontSize: 20, //px, размер шрифта
|
||||||
|
wordWrap: false, //перенос по слогам
|
||||||
|
cutEmptyParagraphs: false, //убирать пустые параграфы
|
||||||
|
addEmptyParagraphs: 0, //добавлять n пустых параграфов перед непустым
|
||||||
|
maxWordLength: 500, //px, максимальная длина слова без пробелов
|
||||||
|
lineHeight: 26, //px, высота строки
|
||||||
|
showImages: true, //показыввать изображения
|
||||||
|
showInlineImagesInCenter: true, //выносить изображения в центр, работает на этапе первичного парсинга (parse)
|
||||||
|
imageHeightLines: 100, //кол-во строк, максимальная высота изображения
|
||||||
|
imageFitWidth: true, //ширина изображения не более ширины страницы
|
||||||
|
dualPageMode: false, //двухстраничный режим
|
||||||
|
compactTextPerc: 0, //проценты, степень компактности текста
|
||||||
|
testWidth: 0, //ширина тестовой строки, пересчитывается извне при изменении шрифта браузером
|
||||||
|
isTesting: false, //тестовый режим
|
||||||
|
|
||||||
|
//заглушка, измеритель ширины текста
|
||||||
|
measureText: (text, style) => {// eslint-disable-line no-unused-vars
|
||||||
|
return text.length*20;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
//for splitToSlogi()
|
||||||
|
const glas = new Set(['а', 'А', 'о', 'О', 'и', 'И', 'е', 'Е', 'ё', 'Ё', 'э', 'Э', 'ы', 'Ы', 'у', 'У', 'ю', 'Ю', 'я', 'Я']);
|
||||||
|
const soglas = new Set([
|
||||||
|
'б', 'в', 'г', 'д', 'ж', 'з', 'й', 'к', 'л', 'м', 'н', 'п', 'р', 'с', 'т', 'ф', 'х', 'ц', 'ч', 'ш', 'щ',
|
||||||
|
'Б', 'В', 'Г', 'Д', 'Ж', 'З', 'Й', 'К', 'Л', 'М', 'Н', 'П', 'Р', 'С', 'Т', 'Ф', 'Х', 'Ч', 'Ц', 'Ш', 'Щ'
|
||||||
|
]);
|
||||||
|
const znak = new Set(['ь', 'Ь', 'ъ', 'Ъ', 'й', 'Й']);
|
||||||
|
const alpha = new Set([...glas, ...soglas, ...znak]);
|
||||||
|
|
||||||
export default class BookParser {
|
export default class BookParser {
|
||||||
constructor(settings) {
|
constructor(settings = {}) {
|
||||||
if (settings) {
|
this.sets = {};
|
||||||
this.showInlineImagesInCenter = settings.showInlineImagesInCenter;
|
|
||||||
}
|
|
||||||
|
|
||||||
// defaults
|
this.setSettings(defaultSettings);
|
||||||
this.p = 30;// px, отступ параграфа
|
this.setSettings(settings);
|
||||||
this.w = 300;// px, ширина страницы
|
|
||||||
this.wordWrap = false;// перенос по слогам
|
|
||||||
|
|
||||||
//заглушка
|
|
||||||
this.measureText = (text, style) => {// eslint-disable-line no-unused-vars
|
|
||||||
return text.length*20;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setSettings(settings = {}) {
|
||||||
|
this.sets = Object.assign({}, this.sets, settings);
|
||||||
|
this.measureText = this.sets.measureText;
|
||||||
|
}
|
||||||
|
|
||||||
async parse(data, callback) {
|
async parse(data, callback) {
|
||||||
if (!callback)
|
if (!callback)
|
||||||
callback = () => {};
|
callback = () => {};
|
||||||
@@ -76,6 +108,7 @@ export default class BookParser {
|
|||||||
*/
|
*/
|
||||||
const getImageDimensions = (binaryId, binaryType, data) => {
|
const getImageDimensions = (binaryId, binaryType, data) => {
|
||||||
return new Promise ((resolve, reject) => { (async() => {
|
return new Promise ((resolve, reject) => { (async() => {
|
||||||
|
data = data.replace(/[\n\r\s]/g, '');
|
||||||
const i = new Image();
|
const i = new Image();
|
||||||
let resolved = false;
|
let resolved = false;
|
||||||
i.onload = () => {
|
i.onload = () => {
|
||||||
@@ -120,14 +153,59 @@ export default class BookParser {
|
|||||||
})().catch(reject); });
|
})().catch(reject); });
|
||||||
};
|
};
|
||||||
|
|
||||||
const newParagraph = (text, len, addIndex) => {
|
const correctCurrentPara = () => {
|
||||||
|
//коррекция текущего параграфа
|
||||||
|
if (paraIndex >= 0) {
|
||||||
|
const prevParaIndex = paraIndex;
|
||||||
|
let p = para[paraIndex];
|
||||||
|
paraOffset -= p.length;
|
||||||
|
//добавление пустых (addEmptyParagraphs) параграфов перед текущим непустым
|
||||||
|
if (p.text.trim() != '') {
|
||||||
|
for (let i = 0; i < 2; i++) {
|
||||||
|
para[paraIndex] = {
|
||||||
|
index: paraIndex,
|
||||||
|
offset: paraOffset,
|
||||||
|
length: 1,
|
||||||
|
text: ' ',
|
||||||
|
addIndex: i + 1,
|
||||||
|
};
|
||||||
|
paraIndex++;
|
||||||
|
paraOffset++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (curTitle.paraIndex == prevParaIndex)
|
||||||
|
curTitle.paraIndex = paraIndex;
|
||||||
|
if (curSubtitle.paraIndex == prevParaIndex)
|
||||||
|
curSubtitle.paraIndex = paraIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
//уберем пробелы с концов параграфа, минимум 1 пробел должен быть у пустого параграфа
|
||||||
|
let newParaText = p.text.trim();
|
||||||
|
newParaText = (newParaText.length ? newParaText : ' ');
|
||||||
|
const ldiff = p.text.length - newParaText.length;
|
||||||
|
if (ldiff != 0) {
|
||||||
|
p.text = newParaText;
|
||||||
|
p.length -= ldiff;
|
||||||
|
}
|
||||||
|
|
||||||
|
p.index = paraIndex;
|
||||||
|
p.offset = paraOffset;
|
||||||
|
para[paraIndex] = p;
|
||||||
|
paraOffset += p.length;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const newParagraph = (text = '', len = 0) => {
|
||||||
|
correctCurrentPara();
|
||||||
|
|
||||||
|
//новый параграф
|
||||||
paraIndex++;
|
paraIndex++;
|
||||||
let p = {
|
let p = {
|
||||||
index: paraIndex,
|
index: paraIndex,
|
||||||
offset: paraOffset,
|
offset: paraOffset,
|
||||||
length: len,
|
length: len,
|
||||||
text: text,
|
text: text,
|
||||||
addIndex: (addIndex ? addIndex : 0),
|
addIndex: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (inSubtitle) {
|
if (inSubtitle) {
|
||||||
@@ -137,53 +215,26 @@ export default class BookParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
para[paraIndex] = p;
|
para[paraIndex] = p;
|
||||||
paraOffset += p.length;
|
paraOffset += len;
|
||||||
};
|
};
|
||||||
|
|
||||||
const growParagraph = (text, len) => {
|
const growParagraph = (text, len) => {
|
||||||
if (paraIndex < 0) {
|
if (paraIndex < 0) {
|
||||||
newParagraph(' ', 1);
|
newParagraph();
|
||||||
growParagraph(text, len);
|
growParagraph(text, len);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const prevParaIndex = paraIndex;
|
|
||||||
let p = para[paraIndex];
|
|
||||||
paraOffset -= p.length;
|
|
||||||
//добавление пустых (addEmptyParagraphs) параграфов перед текущим
|
|
||||||
if (p.length == 1 && p.text[0] == ' ' && len > 0) {
|
|
||||||
paraIndex--;
|
|
||||||
for (let i = 0; i < 2; i++) {
|
|
||||||
newParagraph(' ', 1, i + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
paraIndex++;
|
|
||||||
p.index = paraIndex;
|
|
||||||
p.offset = paraOffset;
|
|
||||||
para[paraIndex] = p;
|
|
||||||
|
|
||||||
if (curTitle.paraIndex == prevParaIndex)
|
|
||||||
curTitle.paraIndex = paraIndex;
|
|
||||||
if (curSubtitle.paraIndex == prevParaIndex)
|
|
||||||
curSubtitle.paraIndex = paraIndex;
|
|
||||||
|
|
||||||
//уберем начальный пробел
|
|
||||||
p.length = 0;
|
|
||||||
p.text = p.text.substr(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
p.length += len;
|
|
||||||
p.text += text;
|
|
||||||
|
|
||||||
|
|
||||||
if (inSubtitle) {
|
if (inSubtitle) {
|
||||||
curSubtitle.title += text;
|
curSubtitle.title += text;
|
||||||
} else if (inTitle) {
|
} else if (inTitle) {
|
||||||
curTitle.title += text;
|
curTitle.title += text;
|
||||||
}
|
}
|
||||||
|
|
||||||
para[paraIndex] = p;
|
const p = para[paraIndex];
|
||||||
paraOffset += p.length;
|
p.length += len;
|
||||||
|
p.text += text;
|
||||||
|
paraOffset += len;
|
||||||
};
|
};
|
||||||
|
|
||||||
const onStartNode = (elemName, tail) => {// eslint-disable-line no-unused-vars
|
const onStartNode = (elemName, tail) => {// eslint-disable-line no-unused-vars
|
||||||
@@ -196,8 +247,8 @@ export default class BookParser {
|
|||||||
if (tag == 'binary') {
|
if (tag == 'binary') {
|
||||||
let attrs = sax.getAttrsSync(tail);
|
let attrs = sax.getAttrsSync(tail);
|
||||||
binaryType = (attrs['content-type'] && attrs['content-type'].value ? attrs['content-type'].value : '');
|
binaryType = (attrs['content-type'] && attrs['content-type'].value ? attrs['content-type'].value : '');
|
||||||
binaryType = (binaryType == 'image/jpg' ? 'image/jpeg' : binaryType);
|
binaryType = (binaryType == 'image/jpg' || binaryType == 'application/octet-stream' ? 'image/jpeg' : binaryType);
|
||||||
if (binaryType == 'image/jpeg' || binaryType == 'image/png' || binaryType == 'application/octet-stream')
|
if (binaryType == 'image/jpeg' || binaryType == 'image/png')
|
||||||
binaryId = (attrs.id.value ? attrs.id.value : '');
|
binaryId = (attrs.id.value ? attrs.id.value : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,19 +261,23 @@ export default class BookParser {
|
|||||||
if (href[0] == '#') {//local
|
if (href[0] == '#') {//local
|
||||||
imageNum++;
|
imageNum++;
|
||||||
|
|
||||||
if (inPara && !this.showInlineImagesInCenter && !center)
|
if (inPara && !this.sets.showInlineImagesInCenter && !center)
|
||||||
growParagraph(`<image-inline href="${href}" num="${imageNum}"></image-inline>`, 0);
|
growParagraph(`<image-inline href="${href}" num="${imageNum}"></image-inline>`, 0);
|
||||||
else
|
else
|
||||||
newParagraph(`<image href="${href}" num="${imageNum}">${' '.repeat(maxImageLineCount)}</image>`, maxImageLineCount);
|
newParagraph(`<image href="${href}" num="${imageNum}">${' '.repeat(maxImageLineCount)}</image>`, maxImageLineCount);
|
||||||
|
|
||||||
this.images.push({paraIndex, num: imageNum, id, local, alt});
|
this.images.push({paraIndex, num: imageNum, id, local, alt});
|
||||||
|
|
||||||
if (inPara && this.showInlineImagesInCenter)
|
if (inPara && this.sets.showInlineImagesInCenter)
|
||||||
newParagraph(' ', 1);
|
newParagraph();
|
||||||
} else {//external
|
} else {//external
|
||||||
imageNum++;
|
imageNum++;
|
||||||
|
|
||||||
dimPromises.push(getExternalImageDimensions(href));
|
if (!this.sets.isTesting) {
|
||||||
|
dimPromises.push(getExternalImageDimensions(href));
|
||||||
|
} else {
|
||||||
|
dimPromises.push(this.sets.getExternalImageDimensions(this, href));
|
||||||
|
}
|
||||||
newParagraph(`<image href="${href}" num="${imageNum}">${' '.repeat(maxImageLineCount)}</image>`, maxImageLineCount);
|
newParagraph(`<image href="${href}" num="${imageNum}">${' '.repeat(maxImageLineCount)}</image>`, maxImageLineCount);
|
||||||
|
|
||||||
this.images.push({paraIndex, num: imageNum, id, local, alt});
|
this.images.push({paraIndex, num: imageNum, id, local, alt});
|
||||||
@@ -264,25 +319,25 @@ export default class BookParser {
|
|||||||
newParagraph(`<emphasis><space w="1">${a}</space></emphasis>`, a.length);
|
newParagraph(`<emphasis><space w="1">${a}</space></emphasis>`, a.length);
|
||||||
});
|
});
|
||||||
if (ann.length)
|
if (ann.length)
|
||||||
newParagraph(' ', 1);
|
newParagraph();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isFirstBody && fb2.sequence && fb2.sequence.length) {
|
if (isFirstBody && fb2.sequence && fb2.sequence.length) {
|
||||||
const bt = utils.getBookTitle(fb2);
|
const bt = utils.getBookTitle(fb2);
|
||||||
if (bt.sequence) {
|
if (bt.sequence) {
|
||||||
newParagraph(bt.sequence, bt.sequence.length);
|
newParagraph(bt.sequence, bt.sequence.length);
|
||||||
newParagraph(' ', 1);
|
newParagraph();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isFirstBody)
|
if (!isFirstBody)
|
||||||
newParagraph(' ', 1);
|
newParagraph();
|
||||||
isFirstBody = false;
|
isFirstBody = false;
|
||||||
bodyIndex++;
|
bodyIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag == 'title') {
|
if (tag == 'title') {
|
||||||
newParagraph(' ', 1);
|
newParagraph();
|
||||||
isFirstTitlePara = true;
|
isFirstTitlePara = true;
|
||||||
bold = true;
|
bold = true;
|
||||||
center = true;
|
center = true;
|
||||||
@@ -294,7 +349,7 @@ export default class BookParser {
|
|||||||
|
|
||||||
if (tag == 'section') {
|
if (tag == 'section') {
|
||||||
if (!isFirstSection)
|
if (!isFirstSection)
|
||||||
newParagraph(' ', 1);
|
newParagraph();
|
||||||
isFirstSection = false;
|
isFirstSection = false;
|
||||||
sectionLevel++;
|
sectionLevel++;
|
||||||
}
|
}
|
||||||
@@ -305,7 +360,7 @@ export default class BookParser {
|
|||||||
|
|
||||||
if ((tag == 'p' || tag == 'empty-line' || tag == 'v')) {
|
if ((tag == 'p' || tag == 'empty-line' || tag == 'v')) {
|
||||||
if (!(tag == 'p' && isFirstTitlePara))
|
if (!(tag == 'p' && isFirstTitlePara))
|
||||||
newParagraph(' ', 1);
|
newParagraph();
|
||||||
if (tag == 'p') {
|
if (tag == 'p') {
|
||||||
inPara = true;
|
inPara = true;
|
||||||
isFirstTitlePara = false;
|
isFirstTitlePara = false;
|
||||||
@@ -313,7 +368,7 @@ export default class BookParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (tag == 'subtitle') {
|
if (tag == 'subtitle') {
|
||||||
newParagraph(' ', 1);
|
newParagraph();
|
||||||
isFirstTitlePara = true;
|
isFirstTitlePara = true;
|
||||||
bold = true;
|
bold = true;
|
||||||
center = true;
|
center = true;
|
||||||
@@ -334,11 +389,12 @@ export default class BookParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (tag == 'poem') {
|
if (tag == 'poem') {
|
||||||
newParagraph(' ', 1);
|
newParagraph();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag == 'text-author') {
|
if (tag == 'text-author') {
|
||||||
newParagraph(' ', 1);
|
newParagraph();
|
||||||
|
bold = true;
|
||||||
space += 1;
|
space += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -380,15 +436,15 @@ export default class BookParser {
|
|||||||
if (tag == 'epigraph' || tag == 'annotation') {
|
if (tag == 'epigraph' || tag == 'annotation') {
|
||||||
italic = false;
|
italic = false;
|
||||||
space -= 1;
|
space -= 1;
|
||||||
if (tag == 'annotation')
|
newParagraph();
|
||||||
newParagraph(' ', 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag == 'stanza') {
|
if (tag == 'stanza') {
|
||||||
newParagraph(' ', 1);
|
newParagraph();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag == 'text-author') {
|
if (tag == 'text-author') {
|
||||||
|
bold = false;
|
||||||
space -= 1;
|
space -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -405,17 +461,14 @@ export default class BookParser {
|
|||||||
|
|
||||||
const onTextNode = (text) => {// eslint-disable-line no-unused-vars
|
const onTextNode = (text) => {// eslint-disable-line no-unused-vars
|
||||||
text = he.decode(text);
|
text = he.decode(text);
|
||||||
text = text.replace(/>/g, '>');
|
text = text.replace(/>/g, '>').replace(/</g, '<').replace(/[\t\n\r\xa0]/g, ' ');
|
||||||
text = text.replace(/</g, '<');
|
|
||||||
|
|
||||||
if (text && text.trim() == '')
|
if (text && text.trim() == '')
|
||||||
text = (text.indexOf(' ') >= 0 ? ' ' : '');
|
text = ' ';
|
||||||
|
|
||||||
if (!text)
|
if (!text)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
text = text.replace(/[\t\n\r\xa0]/g, ' ');
|
|
||||||
|
|
||||||
const authorLength = (fb2.author && fb2.author.length ? fb2.author.length : 0);
|
const authorLength = (fb2.author && fb2.author.length ? fb2.author.length : 0);
|
||||||
switch (path) {
|
switch (path) {
|
||||||
case '/fictionbook/description/title-info/author/first-name':
|
case '/fictionbook/description/title-info/author/first-name':
|
||||||
@@ -453,24 +506,31 @@ export default class BookParser {
|
|||||||
fb2.annotation += text;
|
fb2.annotation += text;
|
||||||
}
|
}
|
||||||
|
|
||||||
let tOpen = (center ? '<center>' : '');
|
if (binaryId) {
|
||||||
tOpen += (bold ? '<strong>' : '');
|
if (!this.sets.isTesting) {
|
||||||
tOpen += (italic ? '<emphasis>' : '');
|
dimPromises.push(getImageDimensions(binaryId, binaryType, text));
|
||||||
tOpen += (space ? `<space w="${space}">` : '');
|
} else {
|
||||||
let tClose = (space ? '</space>' : '');
|
dimPromises.push(this.sets.getImageDimensions(this, binaryId, binaryType, text));
|
||||||
tClose += (italic ? '</emphasis>' : '');
|
}
|
||||||
tClose += (bold ? '</strong>' : '');
|
}
|
||||||
tClose += (center ? '</center>' : '');
|
|
||||||
|
|
||||||
if (path.indexOf('/fictionbook/body/title') == 0 ||
|
if (path.indexOf('/fictionbook/body/title') == 0 ||
|
||||||
path.indexOf('/fictionbook/body/section') == 0 ||
|
path.indexOf('/fictionbook/body/section') == 0 ||
|
||||||
path.indexOf('/fictionbook/body/epigraph') == 0
|
path.indexOf('/fictionbook/body/epigraph') == 0
|
||||||
) {
|
) {
|
||||||
growParagraph(`${tOpen}${text}${tClose}`, text.length);
|
let tOpen = (center ? '<center>' : '');
|
||||||
}
|
tOpen += (bold ? '<strong>' : '');
|
||||||
|
tOpen += (italic ? '<emphasis>' : '');
|
||||||
|
tOpen += (space ? `<space w="${space}">` : '');
|
||||||
|
let tClose = (space ? '</space>' : '');
|
||||||
|
tClose += (italic ? '</emphasis>' : '');
|
||||||
|
tClose += (bold ? '</strong>' : '');
|
||||||
|
tClose += (center ? '</center>' : '');
|
||||||
|
|
||||||
if (binaryId) {
|
if (text != ' ')
|
||||||
dimPromises.push(getImageDimensions(binaryId, binaryType, text));
|
growParagraph(`${tOpen}${text}${tClose}`, text.length);
|
||||||
|
else
|
||||||
|
growParagraph(' ', 1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -482,6 +542,7 @@ export default class BookParser {
|
|||||||
await sax.parse(data, {
|
await sax.parse(data, {
|
||||||
onStartNode, onEndNode, onTextNode, onProgress
|
onStartNode, onEndNode, onTextNode, onProgress
|
||||||
});
|
});
|
||||||
|
correctCurrentPara();
|
||||||
|
|
||||||
if (dimPromises.length) {
|
if (dimPromises.length) {
|
||||||
try {
|
try {
|
||||||
@@ -542,9 +603,19 @@ export default class BookParser {
|
|||||||
let style = {};
|
let style = {};
|
||||||
let image = {};
|
let image = {};
|
||||||
|
|
||||||
|
//оптимизация по памяти
|
||||||
|
const copyStyle = (s) => {
|
||||||
|
const r = {};
|
||||||
|
for (const prop in s) {
|
||||||
|
if (s[prop])
|
||||||
|
r[prop] = s[prop];
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
};
|
||||||
|
|
||||||
const onTextNode = async(text) => {// eslint-disable-line no-unused-vars
|
const onTextNode = async(text) => {// eslint-disable-line no-unused-vars
|
||||||
result.push({
|
result.push({
|
||||||
style: Object.assign({}, style),
|
style: copyStyle(style),
|
||||||
image,
|
image,
|
||||||
text
|
text
|
||||||
});
|
});
|
||||||
@@ -589,7 +660,7 @@ export default class BookParser {
|
|||||||
img.inline = true;
|
img.inline = true;
|
||||||
img.num = (attrs.num && attrs.num.value ? attrs.num.value : 0);
|
img.num = (attrs.num && attrs.num.value ? attrs.num.value : 0);
|
||||||
result.push({
|
result.push({
|
||||||
style: Object.assign({}, style),
|
style: copyStyle(style),
|
||||||
image: img,
|
image: img,
|
||||||
text: ''
|
text: ''
|
||||||
});
|
});
|
||||||
@@ -632,7 +703,7 @@ export default class BookParser {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//длинные слова (или белиберду без пробелов) тоже разобьем
|
//длинные слова (или белиберду без пробелов) тоже разобьем
|
||||||
const maxWordLength = this.maxWordLength;
|
const maxWordLength = this.sets.maxWordLength;
|
||||||
const parts = result;
|
const parts = result;
|
||||||
result = [];
|
result = [];
|
||||||
for (const part of parts) {
|
for (const part of parts) {
|
||||||
@@ -645,7 +716,7 @@ export default class BookParser {
|
|||||||
spaceIndex = i;
|
spaceIndex = i;
|
||||||
|
|
||||||
if (i - spaceIndex >= maxWordLength && i < p.text.length - 1 &&
|
if (i - spaceIndex >= maxWordLength && i < p.text.length - 1 &&
|
||||||
this.measureText(p.text.substr(spaceIndex + 1, i - spaceIndex), p.style) >= this.w - this.p) {
|
this.measureText(p.text.substr(spaceIndex + 1, i - spaceIndex), p.style) >= this.sets.w - this.sets.p) {
|
||||||
result.push({style: p.style, image: p.image, text: p.text.substr(0, i + 1)});
|
result.push({style: p.style, image: p.image, text: p.text.substr(0, i + 1)});
|
||||||
p = {style: p.style, image: p.image, text: p.text.substr(i + 1)};
|
p = {style: p.style, image: p.image, text: p.text.substr(i + 1)};
|
||||||
spaceIndex = -1;
|
spaceIndex = -1;
|
||||||
@@ -663,86 +734,87 @@ export default class BookParser {
|
|||||||
splitToSlogi(word) {
|
splitToSlogi(word) {
|
||||||
let result = [];
|
let result = [];
|
||||||
|
|
||||||
const glas = new Set(['а', 'А', 'о', 'О', 'и', 'И', 'е', 'Е', 'ё', 'Ё', 'э', 'Э', 'ы', 'Ы', 'у', 'У', 'ю', 'Ю', 'я', 'Я']);
|
|
||||||
const soglas = new Set([
|
|
||||||
'б', 'в', 'г', 'д', 'ж', 'з', 'й', 'к', 'л', 'м', 'н', 'п', 'р', 'с', 'т', 'ф', 'х', 'ц', 'ч', 'ш', 'щ',
|
|
||||||
'Б', 'В', 'Г', 'Д', 'Ж', 'З', 'Й', 'К', 'Л', 'М', 'Н', 'П', 'Р', 'С', 'Т', 'Ф', 'Х', 'Ч', 'Ц', 'Ш', 'Щ'
|
|
||||||
]);
|
|
||||||
const znak = new Set(['ь', 'Ь', 'ъ', 'Ъ', 'й', 'Й']);
|
|
||||||
const alpha = new Set([...glas, ...soglas, ...znak]);
|
|
||||||
|
|
||||||
let slog = '';
|
|
||||||
let slogLen = 0;
|
|
||||||
const len = word.length;
|
const len = word.length;
|
||||||
word += ' ';
|
if (len > 3) {
|
||||||
for (let i = 0; i < len; i++) {
|
let slog = '';
|
||||||
slog += word[i];
|
let slogLen = 0;
|
||||||
if (alpha.has(word[i]))
|
word += ' ';
|
||||||
slogLen++;
|
for (let i = 0; i < len; i++) {
|
||||||
|
slog += word[i];
|
||||||
|
if (alpha.has(word[i]))
|
||||||
|
slogLen++;
|
||||||
|
|
||||||
if (slogLen > 1 && i < len - 2 && (
|
if (slogLen > 1 && i < len - 2 && (
|
||||||
//гласная, а следом не 2 согласные буквы
|
//гласная, а следом не 2 согласные буквы
|
||||||
(glas.has(word[i]) && !(soglas.has(word[i + 1]) &&
|
(glas.has(word[i]) && !( soglas.has(word[i + 1]) && soglas.has(word[i + 2]) ) &&
|
||||||
soglas.has(word[i + 2])) && alpha.has(word[i + 1]) && alpha.has(word[i + 2])
|
alpha.has(word[i + 1]) && alpha.has(word[i + 2])
|
||||||
) ||
|
) ||
|
||||||
//предыдущая не согласная буква, текущая согласная, а следом согласная и согласная|гласная буквы
|
//предыдущая не согласная буква, текущая согласная, а следом согласная и согласная|гласная буквы
|
||||||
(alpha.has(word[i - 1]) && !soglas.has(word[i - 1]) &&
|
(alpha.has(word[i - 1]) && !soglas.has(word[i - 1]) && soglas.has(word[i]) && soglas.has(word[i + 1]) &&
|
||||||
soglas.has(word[i]) && soglas.has(word[i + 1]) &&
|
( glas.has(word[i + 2]) || soglas.has(word[i + 2]) ) &&
|
||||||
(glas.has(word[i + 2]) || soglas.has(word[i + 2])) &&
|
alpha.has(word[i + 1]) && alpha.has(word[i + 2])
|
||||||
alpha.has(word[i + 1]) && alpha.has(word[i + 2])
|
) ||
|
||||||
) ||
|
//мягкий или твердый знак или Й
|
||||||
//мягкий или твердый знак или Й
|
(znak.has(word[i]) && alpha.has(word[i + 1]) && alpha.has(word[i + 2])) ||
|
||||||
(znak.has(word[i]) && alpha.has(word[i + 1]) && alpha.has(word[i + 2])) ||
|
(word[i] == '-')
|
||||||
(word[i] == '-')
|
) &&
|
||||||
) &&
|
//нельзя оставлять окончания на ь, ъ, й
|
||||||
//нельзя оставлять окончания на ь, ъ, й
|
!(znak.has(word[i + 2]) && !alpha.has(word[i + 3]))
|
||||||
!(znak.has(word[i + 2]) && !alpha.has(word[i + 3]))
|
|
||||||
|
|
||||||
) {
|
) {
|
||||||
result.push(slog);
|
result.push(slog);
|
||||||
slog = '';
|
slog = '';
|
||||||
slogLen = 0;
|
slogLen = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (slog)
|
||||||
|
result.push(slog);
|
||||||
|
} else {
|
||||||
|
result.push(word);
|
||||||
}
|
}
|
||||||
if (slog)
|
|
||||||
result.push(slog);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
parsePara(paraIndex) {
|
parsePara(paraIndex) {
|
||||||
const para = this.para[paraIndex];
|
const para = this.para[paraIndex];
|
||||||
|
const s = this.sets;
|
||||||
|
|
||||||
|
//перераспарсиваем только при изменении одного из параметров
|
||||||
if (!this.force &&
|
if (!this.force &&
|
||||||
para.parsed &&
|
para.parsed &&
|
||||||
para.parsed.testWidth === this.testWidth &&
|
para.parsed.p === s.p &&
|
||||||
para.parsed.w === this.w &&
|
para.parsed.w === s.w &&
|
||||||
para.parsed.p === this.p &&
|
para.parsed.font === s.font &&
|
||||||
para.parsed.wordWrap === this.wordWrap &&
|
para.parsed.fontSize === s.fontSize &&
|
||||||
para.parsed.maxWordLength === this.maxWordLength &&
|
para.parsed.wordWrap === s.wordWrap &&
|
||||||
para.parsed.font === this.font &&
|
para.parsed.cutEmptyParagraphs === s.cutEmptyParagraphs &&
|
||||||
para.parsed.cutEmptyParagraphs === this.cutEmptyParagraphs &&
|
para.parsed.addEmptyParagraphs === s.addEmptyParagraphs &&
|
||||||
para.parsed.addEmptyParagraphs === this.addEmptyParagraphs &&
|
para.parsed.maxWordLength === s.maxWordLength &&
|
||||||
para.parsed.showImages === this.showImages &&
|
para.parsed.lineHeight === s.lineHeight &&
|
||||||
para.parsed.imageHeightLines === this.imageHeightLines &&
|
para.parsed.showImages === s.showImages &&
|
||||||
para.parsed.imageFitWidth === this.imageFitWidth &&
|
para.parsed.imageHeightLines === s.imageHeightLines &&
|
||||||
para.parsed.compactTextPerc === this.compactTextPerc
|
para.parsed.imageFitWidth === (s.imageFitWidth || s.dualPageMode) &&
|
||||||
|
para.parsed.compactTextPerc === s.compactTextPerc &&
|
||||||
|
para.parsed.testWidth === s.testWidth
|
||||||
)
|
)
|
||||||
return para.parsed;
|
return para.parsed;
|
||||||
|
|
||||||
const parsed = {
|
const parsed = {
|
||||||
testWidth: this.testWidth,
|
p: s.p,
|
||||||
w: this.w,
|
w: s.w,
|
||||||
p: this.p,
|
font: s.font,
|
||||||
wordWrap: this.wordWrap,
|
fontSize: s.fontSize,
|
||||||
maxWordLength: this.maxWordLength,
|
wordWrap: s.wordWrap,
|
||||||
font: this.font,
|
cutEmptyParagraphs: s.cutEmptyParagraphs,
|
||||||
cutEmptyParagraphs: this.cutEmptyParagraphs,
|
addEmptyParagraphs: s.addEmptyParagraphs,
|
||||||
addEmptyParagraphs: this.addEmptyParagraphs,
|
maxWordLength: s.maxWordLength,
|
||||||
showImages: this.showImages,
|
lineHeight: s.lineHeight,
|
||||||
imageHeightLines: this.imageHeightLines,
|
showImages: s.showImages,
|
||||||
imageFitWidth: this.imageFitWidth,
|
imageHeightLines: s.imageHeightLines,
|
||||||
compactTextPerc: this.compactTextPerc,
|
imageFitWidth: (s.imageFitWidth || s.dualPageMode),
|
||||||
|
compactTextPerc: s.compactTextPerc,
|
||||||
|
testWidth: s.testWidth,
|
||||||
visible: true, //вычисляется позже
|
visible: true, //вычисляется позже
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -774,7 +846,7 @@ export default class BookParser {
|
|||||||
let ofs = 0;//смещение от начала параграфа para.offset
|
let ofs = 0;//смещение от начала параграфа para.offset
|
||||||
let imgW = 0;
|
let imgW = 0;
|
||||||
let imageInPara = false;
|
let imageInPara = false;
|
||||||
const compactWidth = this.measureText('W', {})*this.compactTextPerc/100;
|
const compactWidth = this.measureText('W', {})*parsed.compactTextPerc/100;
|
||||||
// тут начинается самый замес, перенос по слогам и стилизация, а также изображения
|
// тут начинается самый замес, перенос по слогам и стилизация, а также изображения
|
||||||
for (const part of parts) {
|
for (const part of parts) {
|
||||||
style = part.style;
|
style = part.style;
|
||||||
@@ -787,14 +859,14 @@ export default class BookParser {
|
|||||||
if (!bin)
|
if (!bin)
|
||||||
bin = {h: 1, w: 1};
|
bin = {h: 1, w: 1};
|
||||||
|
|
||||||
let lineCount = this.imageHeightLines;
|
let lineCount = parsed.imageHeightLines;
|
||||||
let c = Math.ceil(bin.h/this.lineHeight);
|
let c = Math.ceil(bin.h/parsed.lineHeight);
|
||||||
|
|
||||||
const maxH = lineCount*this.lineHeight;
|
const maxH = lineCount*parsed.lineHeight;
|
||||||
let maxH2 = maxH;
|
let maxH2 = maxH;
|
||||||
if (this.imageFitWidth && bin.w > this.w) {
|
if (parsed.imageFitWidth && bin.w > parsed.w) {
|
||||||
maxH2 = bin.h*this.w/bin.w;
|
maxH2 = bin.h*parsed.w/bin.w;
|
||||||
c = Math.ceil(maxH2/this.lineHeight);
|
c = Math.ceil(maxH2/parsed.lineHeight);
|
||||||
}
|
}
|
||||||
lineCount = (c < lineCount ? c : lineCount);
|
lineCount = (c < lineCount ? c : lineCount);
|
||||||
|
|
||||||
@@ -834,10 +906,10 @@ export default class BookParser {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (part.image.id && part.image.inline && this.showImages) {
|
if (part.image.id && part.image.inline && parsed.showImages) {
|
||||||
const bin = this.binary[part.image.id];
|
const bin = this.binary[part.image.id];
|
||||||
if (bin) {
|
if (bin) {
|
||||||
let imgH = (bin.h > this.fontSize ? this.fontSize : bin.h);
|
let imgH = (bin.h > parsed.fontSize ? parsed.fontSize : bin.h);
|
||||||
imgW += bin.w*imgH/bin.h;
|
imgW += bin.w*imgH/bin.h;
|
||||||
line.parts.push({style, text: '',
|
line.parts.push({style, text: '',
|
||||||
image: {local: part.image.local, inline: true, id: part.image.id, num: part.image.num}});
|
image: {local: part.image.local, inline: true, id: part.image.id, num: part.image.num}});
|
||||||
@@ -952,11 +1024,11 @@ export default class BookParser {
|
|||||||
|
|
||||||
//parsed.visible
|
//parsed.visible
|
||||||
if (imageInPara) {
|
if (imageInPara) {
|
||||||
parsed.visible = this.showImages;
|
parsed.visible = parsed.showImages;
|
||||||
} else {
|
} else {
|
||||||
parsed.visible = !(
|
parsed.visible = !(
|
||||||
(para.addIndex > this.addEmptyParagraphs) ||
|
(para.addIndex > parsed.addEmptyParagraphs) ||
|
||||||
(para.addIndex == 0 && this.cutEmptyParagraphs && paragraphText.trim() == '')
|
(para.addIndex == 0 && parsed.cutEmptyParagraphs && paragraphText.trim() == '')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
27
client/components/Reader/share/wallpaperStorage.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import localForage from 'localforage';
|
||||||
|
//import _ from 'lodash';
|
||||||
|
|
||||||
|
const wpStore = localForage.createInstance({
|
||||||
|
name: 'wallpaperStorage'
|
||||||
|
});
|
||||||
|
|
||||||
|
class WallpaperStorage {
|
||||||
|
|
||||||
|
async getLength() {
|
||||||
|
return await wpStore.length();
|
||||||
|
}
|
||||||
|
|
||||||
|
async setData(key, data) {
|
||||||
|
await wpStore.setItem(key, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getData(key) {
|
||||||
|
return await wpStore.getItem(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
async removeData(key) {
|
||||||
|
await wpStore.removeItem(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new WallpaperStorage();
|
||||||
@@ -1,4 +1,18 @@
|
|||||||
export const versionHistory = [
|
export const versionHistory = [
|
||||||
|
{
|
||||||
|
showUntil: '2021-02-16',
|
||||||
|
header: '0.10.0 (2021-02-09)',
|
||||||
|
content:
|
||||||
|
`
|
||||||
|
<ul>
|
||||||
|
<li>добавлен двухстраничный режим</li>
|
||||||
|
<li>в настройки добавлены все кириллические веб-шрифты от google</li>
|
||||||
|
<li>в настройки добавлена возможность загрузки пользовательских обоев (пока без синхронизации)</li>
|
||||||
|
<li>немного улучшен парсинг fb2</li>
|
||||||
|
</ul>
|
||||||
|
`
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
showUntil: '2020-12-17',
|
showUntil: '2020-12-17',
|
||||||
header: '0.9.12 (2020-12-18)',
|
header: '0.9.12 (2020-12-18)',
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ import {QSlider} from 'quasar/src/components/slider';
|
|||||||
import {QTabs, QTab} from 'quasar/src/components/tabs';
|
import {QTabs, QTab} from 'quasar/src/components/tabs';
|
||||||
//import {QTabPanels, QTabPanel} from 'quasar/src/components/tab-panels';
|
//import {QTabPanels, QTabPanel} from 'quasar/src/components/tab-panels';
|
||||||
import {QSeparator} from 'quasar/src/components/separator';
|
import {QSeparator} from 'quasar/src/components/separator';
|
||||||
//import {QList, QItem, QItemSection, QItemLabel} from 'quasar/src/components/item';
|
//import {QList} from 'quasar/src/components/item';
|
||||||
|
import {QItem, QItemSection, QItemLabel} from 'quasar/src/components/item';
|
||||||
import {QTooltip} from 'quasar/src/components/tooltip';
|
import {QTooltip} from 'quasar/src/components/tooltip';
|
||||||
import {QSpinner} from 'quasar/src/components/spinner';
|
import {QSpinner} from 'quasar/src/components/spinner';
|
||||||
import {QTable, QTh, QTr, QTd} from 'quasar/src/components/table';
|
import {QTable, QTh, QTr, QTd} from 'quasar/src/components/table';
|
||||||
@@ -49,7 +50,8 @@ const components = {
|
|||||||
QTabs, QTab,
|
QTabs, QTab,
|
||||||
//QTabPanels, QTabPanel,
|
//QTabPanels, QTabPanel,
|
||||||
QSeparator,
|
QSeparator,
|
||||||
//QList, QItem, QItemSection, QItemLabel,
|
//QList,
|
||||||
|
QItem, QItemSection, QItemLabel,
|
||||||
QTooltip,
|
QTooltip,
|
||||||
QSpinner,
|
QSpinner,
|
||||||
QTable, QTh, QTr, QTd,
|
QTable, QTh, QTr, QTd,
|
||||||
|
|||||||
22
client/share/dynamicCss.js
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
class DynamicCss {
|
||||||
|
constructor() {
|
||||||
|
this.cssNodes = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
replace(name, cssText) {
|
||||||
|
const style = document.createElement('style');
|
||||||
|
style.type = 'text/css';
|
||||||
|
style.innerHTML = cssText;
|
||||||
|
|
||||||
|
const parent = document.getElementsByTagName('head')[0];
|
||||||
|
|
||||||
|
if (this.cssNodes[name]) {
|
||||||
|
parent.removeChild(this.cssNodes[name]);
|
||||||
|
delete this.cssNodes[name];
|
||||||
|
}
|
||||||
|
|
||||||
|
this.cssNodes[name] = parent.appendChild(style);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new DynamicCss();
|
||||||
1
client/store/modules/fonts/fonts.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
["Alegreya","Alegreya SC","Alegreya Sans","Alegreya Sans SC","Alice","Amatic SC","Andika","Anonymous Pro","Arimo","Arsenal","Bad Script","Balsamiq Sans","Bellota","Bellota Text","Bitter","Caveat","Comfortaa","Commissioner","Cormorant","Cormorant Garamond","Cormorant Infant","Cormorant SC","Cormorant Unicase","Cousine","Cuprum","Didact Gothic","EB Garamond","El Messiri","Exo 2","Fira Code","Fira Mono","Fira Sans","Fira Sans Condensed","Fira Sans Extra Condensed","Forum","Gabriela","Hachi Maru Pop","IBM Plex Mono","IBM Plex Sans","IBM Plex Serif","Inter","Istok Web","JetBrains Mono","Jost","Jura","Kelly Slab","Kosugi","Kosugi Maru","Kurale","Ledger","Literata","Lobster","Lora","M PLUS 1p","M PLUS Rounded 1c","Manrope","Marck Script","Marmelad","Merriweather","Montserrat","Montserrat Alternates","Neucha","Noto Sans","Noto Serif","Nunito","Old Standard TT","Open Sans","Open Sans Condensed","Oranienbaum","Oswald","PT Mono","PT Sans","PT Sans Caption","PT Sans Narrow","PT Serif","PT Serif Caption","Pacifico","Pangolin","Pattaya","Philosopher","Piazzolla","Play","Playfair Display","Playfair Display SC","Podkova","Poiret One","Prata","Press Start 2P","Prosto One","Raleway","Roboto","Roboto Condensed","Roboto Mono","Roboto Slab","Rubik","Rubik Mono One","Ruda","Ruslan Display","Russo One","Sawarabi Gothic","Scada","Seymour One","Source Code Pro","Source Sans Pro","Source Serif Pro","Spectral","Spectral SC","Stalinist One","Tenor Sans","Tinos","Ubuntu","Ubuntu Condensed","Ubuntu Mono","Underdog","Viaoda Libre","Vollkorn","Vollkorn SC","Yanone Kaffeesatz","Yeseva One"]
|
||||||
13
client/store/modules/fonts/fonts2list.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
const fs = require('fs-extra');
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const webfonts = await fs.readFile('webfonts.json');
|
||||||
|
let fonts = JSON.parse(webfonts);
|
||||||
|
|
||||||
|
fonts = fonts.items.filter(item => item.subsets.includes('cyrillic'));
|
||||||
|
fonts = fonts.map(item => item.family);
|
||||||
|
fonts.sort();
|
||||||
|
|
||||||
|
await fs.writeFile('fonts.json', JSON.stringify(fonts));
|
||||||
|
}
|
||||||
|
main();
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import * as utils from '../../share/utils';
|
import * as utils from '../../share/utils';
|
||||||
|
import googleFonts from './fonts/fonts.json';
|
||||||
|
|
||||||
const readerActions = {
|
const readerActions = {
|
||||||
'help': 'Вызвать cправку',
|
'help': 'Вызвать cправку',
|
||||||
@@ -91,125 +92,22 @@ const fonts = [
|
|||||||
{name: 'Rubik', fontVertShift: 0},
|
{name: 'Rubik', fontVertShift: 0},
|
||||||
];
|
];
|
||||||
|
|
||||||
const webFonts = [
|
//webFonts: [{css: 'https://fonts.googleapis.com/css?family=Alegreya', name: 'Alegreya', fontVertShift: 0}, ...],
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Alegreya', name: 'Alegreya', fontVertShift: -5},
|
const webFonts = [];
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Alegreya+Sans', name: 'Alegreya Sans', fontVertShift: 5},
|
for (const family of googleFonts) {
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Alegreya+SC', name: 'Alegreya SC', fontVertShift: -5},
|
webFonts.push({
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Alice', name: 'Alice', fontVertShift: 5},
|
css: `https://fonts.googleapis.com/css?family=${family.replace(/\s/g, '+')}`,
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Amatic+SC', name: 'Amatic SC', fontVertShift: 0},
|
name: family,
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Andika', name: 'Andika', fontVertShift: -35},
|
fontVertShift: 0,
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Anonymous+Pro', name: 'Anonymous Pro', fontVertShift: 5},
|
});
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Arsenal', name: 'Arsenal', fontVertShift: 0},
|
}
|
||||||
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Bad+Script', name: 'Bad Script', fontVertShift: -30},
|
|
||||||
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Caveat', name: 'Caveat', fontVertShift: -5},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Comfortaa', name: 'Comfortaa', fontVertShift: 10},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Cormorant', name: 'Cormorant', fontVertShift: 0},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Cormorant+Garamond', name: 'Cormorant Garamond', fontVertShift: 0},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Cormorant+Infant', name: 'Cormorant Infant', fontVertShift: 5},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Cormorant+Unicase', name: 'Cormorant Unicase', fontVertShift: 0},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Cousine', name: 'Cousine', fontVertShift: 0},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Cuprum', name: 'Cuprum', fontVertShift: 5},
|
|
||||||
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Didact+Gothic', name: 'Didact Gothic', fontVertShift: -10},
|
|
||||||
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=EB+Garamond', name: 'EB Garamond', fontVertShift: -5},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=El+Messiri', name: 'El Messiri', fontVertShift: -5},
|
|
||||||
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Fira+Mono', name: 'Fira Mono', fontVertShift: 5},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Fira+Sans', name: 'Fira Sans', fontVertShift: 5},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Fira+Sans+Condensed', name: 'Fira Sans Condensed', fontVertShift: 5},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Fira+Sans+Extra+Condensed', name: 'Fira Sans Extra Condensed', fontVertShift: 5},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Forum', name: 'Forum', fontVertShift: 5},
|
|
||||||
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Gabriela', name: 'Gabriela', fontVertShift: 5},
|
|
||||||
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=IBM+Plex+Mono', name: 'IBM Plex Mono', fontVertShift: -5},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=IBM+Plex+Sans', name: 'IBM Plex Sans', fontVertShift: -5},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=IBM+Plex+Serif', name: 'IBM Plex Serif', fontVertShift: -5},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Istok+Web', name: 'Istok Web', fontVertShift: -5},
|
|
||||||
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Jura', name: 'Jura', fontVertShift: 0},
|
|
||||||
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Kelly+Slab', name: 'Kelly Slab', fontVertShift: 0},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Kosugi', name: 'Kosugi', fontVertShift: 5},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Kosugi+Maru', name: 'Kosugi Maru', fontVertShift: 10},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Kurale', name: 'Kurale', fontVertShift: -15},
|
|
||||||
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Ledger', name: 'Ledger', fontVertShift: -5},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Lobster', name: 'Lobster', fontVertShift: 0},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Lora', name: 'Lora', fontVertShift: 0},
|
|
||||||
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Marck+Script', name: 'Marck Script', fontVertShift: 0},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Marmelad', name: 'Marmelad', fontVertShift: 0},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Merriweather', name: 'Merriweather', fontVertShift: 0},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Montserrat', name: 'Montserrat', fontVertShift: 0},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Montserrat+Alternates', name: 'Montserrat Alternates', fontVertShift: 0},
|
|
||||||
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Neucha', name: 'Neucha', fontVertShift: 0},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Noto+Sans', name: 'Noto Sans', fontVertShift: -10},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Noto+Sans+SC', name: 'Noto Sans SC', fontVertShift: -15},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Noto+Serif', name: 'Noto Serif', fontVertShift: -10},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Noto+Serif+TC', name: 'Noto Serif TC', fontVertShift: -15},
|
|
||||||
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Old+Standard+TT', name: 'Old Standard TT', fontVertShift: 15},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300', name: 'Open Sans Condensed', fontVertShift: -5},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Oranienbaum', name: 'Oranienbaum', fontVertShift: 5},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Oswald', name: 'Oswald', fontVertShift: -20},
|
|
||||||
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Pacifico', name: 'Pacifico', fontVertShift: -35},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Pangolin', name: 'Pangolin', fontVertShift: 5},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Pattaya', name: 'Pattaya', fontVertShift: 0},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Philosopher', name: 'Philosopher', fontVertShift: 5},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Play', name: 'Play', fontVertShift: 5},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Playfair+Display', name: 'Playfair Display', fontVertShift: -5},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Playfair+Display+SC', name: 'Playfair Display SC', fontVertShift: -5},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Podkova', name: 'Podkova', fontVertShift: 10},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Poiret+One', name: 'Poiret One', fontVertShift: 0},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Prata', name: 'Prata', fontVertShift: 5},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Prosto+One', name: 'Prosto One', fontVertShift: 0},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=PT+Mono', name: 'PT Mono', fontVertShift: 5},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=PT+Sans', name: 'PT Sans', fontVertShift: -10},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=PT+Sans+Caption', name: 'PT Sans Caption', fontVertShift: -10},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=PT+Sans+Narrow', name: 'PT Sans Narrow', fontVertShift: -10},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=PT+Serif', name: 'PT Serif', fontVertShift: -10},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=PT+Serif+Caption', name: 'PT Serif Caption', fontVertShift: -10},
|
|
||||||
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Roboto+Condensed', name: 'Roboto Condensed', fontVertShift: 0},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Roboto+Mono', name: 'Roboto Mono', fontVertShift: -5},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Roboto+Slab', name: 'Roboto Slab', fontVertShift: 0},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Ruslan+Display', name: 'Ruslan Display', fontVertShift: 20},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Russo+One', name: 'Russo One', fontVertShift: 5},
|
|
||||||
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Sawarabi+Gothic', name: 'Sawarabi Gothic', fontVertShift: -15},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Scada', name: 'Scada', fontVertShift: 0},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Seymour+One', name: 'Seymour One', fontVertShift: 0},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Source+Sans+Pro', name: 'Source Sans Pro', fontVertShift: 0},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Spectral', name: 'Spectral', fontVertShift: -5},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Stalinist+One', name: 'Stalinist One', fontVertShift: 0},
|
|
||||||
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Tinos', name: 'Tinos', fontVertShift: 5},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Tenor+Sans', name: 'Tenor Sans', fontVertShift: 5},
|
|
||||||
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Underdog', name: 'Underdog', fontVertShift: 10},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Ubuntu+Mono', name: 'Ubuntu Mono', fontVertShift: 0},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Ubuntu+Condensed', name: 'Ubuntu Condensed', fontVertShift: -5},
|
|
||||||
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Vollkorn', name: 'Vollkorn', fontVertShift: -5},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Vollkorn+SC', name: 'Vollkorn SC', fontVertShift: 0},
|
|
||||||
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz', name: 'Yanone Kaffeesatz', fontVertShift: 20},
|
|
||||||
{css: 'https://fonts.googleapis.com/css?family=Yeseva+One', name: 'Yeseva One', fontVertShift: 10},
|
|
||||||
|
|
||||||
|
|
||||||
];
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------------
|
||||||
const settingDefaults = {
|
const settingDefaults = {
|
||||||
textColor: '#000000',
|
textColor: '#000000',
|
||||||
backgroundColor: '#EBE2C9',
|
backgroundColor: '#ebe2c9',
|
||||||
wallpaper: '',
|
wallpaper: '',
|
||||||
|
wallpaperIgnoreStatusBar: false,
|
||||||
fontStyle: '',// 'italic'
|
fontStyle: '',// 'italic'
|
||||||
fontWeight: '',// 'bold'
|
fontWeight: '',// 'bold'
|
||||||
fontSize: 20,// px
|
fontSize: 20,// px
|
||||||
@@ -226,9 +124,22 @@ const settingDefaults = {
|
|||||||
wordWrap: true,//перенос по слогам
|
wordWrap: true,//перенос по слогам
|
||||||
keepLastToFirst: false,// перенос последней строки в первую при листании
|
keepLastToFirst: false,// перенос последней строки в первую при листании
|
||||||
|
|
||||||
|
dualPageMode: false,
|
||||||
|
dualIndentLR: 10,// px, отступ слева и справа внутри страницы в двухстраничном режиме
|
||||||
|
dualDivWidth: 2,// px, ширина разделителя
|
||||||
|
dualDivHeight: 100,// процент, высота разделителя
|
||||||
|
dualDivColorAsText: true,//цвет как у текста
|
||||||
|
dualDivColor: '#000000',
|
||||||
|
dualDivColorAlpha: 0.7,// прозрачность разделителя
|
||||||
|
dualDivStrokeFill: 1,// px, заполнение пунктира
|
||||||
|
dualDivStrokeGap: 1,// px, промежуток пунктира
|
||||||
|
dualDivShadowWidth: 0,// px, ширина тени
|
||||||
|
|
||||||
showStatusBar: true,
|
showStatusBar: true,
|
||||||
statusBarTop: false,// top, bottom
|
statusBarTop: false,// top, bottom
|
||||||
statusBarHeight: 19,// px
|
statusBarHeight: 19,// px
|
||||||
|
statusBarColorAsText: true,//цвет как у текста
|
||||||
|
statusBarColor: '#000000',
|
||||||
statusBarColorAlpha: 0.4,
|
statusBarColorAlpha: 0.4,
|
||||||
statusBarClickOpen: true,
|
statusBarClickOpen: true,
|
||||||
|
|
||||||
@@ -265,6 +176,7 @@ const settingDefaults = {
|
|||||||
fontShifts: {},
|
fontShifts: {},
|
||||||
showToolButton: {},
|
showToolButton: {},
|
||||||
userHotKeys: {},
|
userHotKeys: {},
|
||||||
|
userWallpapers: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const font of fonts)
|
for (const font of fonts)
|
||||||
@@ -276,12 +188,13 @@ for (const button of toolButtons)
|
|||||||
for (const hotKey of hotKeys)
|
for (const hotKey of hotKeys)
|
||||||
settingDefaults.userHotKeys[hotKey.name] = hotKey.codes;
|
settingDefaults.userHotKeys[hotKey.name] = hotKey.codes;
|
||||||
|
|
||||||
const excludeDiffHotKeys = [];
|
const diffExclude = [];
|
||||||
for (const hotKey of hotKeys)
|
for (const hotKey of hotKeys)
|
||||||
excludeDiffHotKeys.push(`userHotKeys/${hotKey.name}`);
|
diffExclude.push(`userHotKeys/${hotKey.name}`);
|
||||||
|
diffExclude.push('userWallpapers');
|
||||||
|
|
||||||
function addDefaultsToSettings(settings) {
|
function addDefaultsToSettings(settings) {
|
||||||
const diff = utils.getObjDiff(settings, settingDefaults, {exclude: excludeDiffHotKeys});
|
const diff = utils.getObjDiff(settings, settingDefaults, {exclude: diffExclude});
|
||||||
if (!utils.isEmptyObjDiffDeep(diff, {isApplyChange: false})) {
|
if (!utils.isEmptyObjDiffDeep(diff, {isApplyChange: false})) {
|
||||||
return utils.applyObjDiff(settings, diff, {isApplyChange: false});
|
return utils.applyObjDiff(settings, diff, {isApplyChange: false});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "Liberama",
|
"name": "Liberama",
|
||||||
"version": "0.9.12",
|
"version": "0.10.0",
|
||||||
"author": "Book Pauk <bookpauk@gmail.com>",
|
"author": "Book Pauk <bookpauk@gmail.com>",
|
||||||
"license": "CC0-1.0",
|
"license": "CC0-1.0",
|
||||||
"repository": "bookpauk/liberama",
|
"repository": "bookpauk/liberama",
|
||||||
@@ -10,8 +10,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "nodemon --inspect --ignore server/public --ignore server/data --ignore client --exec 'node server'",
|
"dev": "nodemon --inspect --ignore server/public --ignore server/data --ignore client --exec 'node server'",
|
||||||
"build:client": "webpack --config build/webpack.prod.config.js",
|
"build:client": "webpack --config build/webpack.prod.config.js",
|
||||||
"build:linux": "npm run build:client && node build/linux && pkg -t latest-linux-x64 -o dist/linux/liberama .",
|
"build:linux": "npm run build:client && node build/linux && pkg -t node12-linux-x64 -o dist/linux/liberama .",
|
||||||
"build:win": "npm run build:client && node build/win && pkg -t latest-win-x64 -o dist/win/liberama .",
|
"build:win": "npm run build:client && node build/win && pkg -t node12-win-x64 -o dist/win/liberama .",
|
||||||
"lint": "eslint --ext=.js,.vue client server",
|
"lint": "eslint --ext=.js,.vue client server",
|
||||||
"build:client-dev": "webpack --config build/webpack.dev.config.js",
|
"build:client-dev": "webpack --config build/webpack.dev.config.js",
|
||||||
"postinstall": "npm run build:client-dev && node build/linux"
|
"postinstall": "npm run build:client-dev && node build/linux"
|
||||||
|
|||||||
@@ -50,8 +50,14 @@ class WebSocketController {
|
|||||||
log(`WebSocket-IN: ${message.substr(0, 4000)}`);
|
log(`WebSocket-IN: ${message.substr(0, 4000)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
ws.lastActivity = Date.now();
|
|
||||||
req = JSON.parse(message);
|
req = JSON.parse(message);
|
||||||
|
|
||||||
|
ws.lastActivity = Date.now();
|
||||||
|
|
||||||
|
//pong for WebSocketConnection
|
||||||
|
if (req._rpo === 1)
|
||||||
|
this.send({_rok: 1}, req, ws);
|
||||||
|
|
||||||
switch (req.action) {
|
switch (req.action) {
|
||||||
case 'test':
|
case 'test':
|
||||||
await this.test(req, ws); break;
|
await this.test(req, ws); break;
|
||||||
|
|||||||
237
server/core/WebSocketConnection.js
Normal file
@@ -0,0 +1,237 @@
|
|||||||
|
const isBrowser = (typeof window !== 'undefined');
|
||||||
|
|
||||||
|
const utils = {
|
||||||
|
sleep: (ms) => { return new Promise(resolve => setTimeout(resolve, ms)); }
|
||||||
|
};
|
||||||
|
|
||||||
|
const cleanPeriod = 5*1000;//5 секунд
|
||||||
|
|
||||||
|
class WebSocketConnection {
|
||||||
|
//messageLifeTime в секундах (проверка каждый cleanPeriod интервал)
|
||||||
|
constructor(url, openTimeoutSecs = 10, messageLifeTimeSecs = 30) {
|
||||||
|
this.WebSocket = (isBrowser ? WebSocket : require('ws'));
|
||||||
|
this.url = url;
|
||||||
|
this.ws = null;
|
||||||
|
this.listeners = [];
|
||||||
|
this.messageQueue = [];
|
||||||
|
this.messageLifeTime = messageLifeTimeSecs*1000;
|
||||||
|
this.openTimeout = openTimeoutSecs*1000;
|
||||||
|
this.requestId = 0;
|
||||||
|
|
||||||
|
this.wsErrored = false;
|
||||||
|
this.closed = false;
|
||||||
|
|
||||||
|
this.connecting = false;
|
||||||
|
this.periodicClean();//no await
|
||||||
|
}
|
||||||
|
|
||||||
|
//рассылаем сообщение и удаляем те обработчики, которые его получили
|
||||||
|
emit(mes, isError) {
|
||||||
|
const len = this.listeners.length;
|
||||||
|
if (len > 0) {
|
||||||
|
let newListeners = [];
|
||||||
|
for (const listener of this.listeners) {
|
||||||
|
let emitted = false;
|
||||||
|
if (isError) {
|
||||||
|
listener.onError(mes);
|
||||||
|
emitted = true;
|
||||||
|
} else {
|
||||||
|
if ( (listener.requestId && mes.requestId && listener.requestId === mes.requestId) ||
|
||||||
|
(!listener.requestId && !mes.requestId) ) {
|
||||||
|
listener.onMessage(mes);
|
||||||
|
emitted = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!emitted)
|
||||||
|
newListeners.push(listener);
|
||||||
|
}
|
||||||
|
this.listeners = newListeners;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.listeners.length != len;
|
||||||
|
}
|
||||||
|
|
||||||
|
get isOpen() {
|
||||||
|
return (this.ws && this.ws.readyState == this.WebSocket.OPEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
processMessageQueue() {
|
||||||
|
let newMessageQueue = [];
|
||||||
|
for (const message of this.messageQueue) {
|
||||||
|
if (!this.emit(message.mes)) {
|
||||||
|
newMessageQueue.push(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.messageQueue = newMessageQueue;
|
||||||
|
}
|
||||||
|
|
||||||
|
_open() {
|
||||||
|
return new Promise((resolve, reject) => { (async() => {
|
||||||
|
if (this.closed)
|
||||||
|
reject(new Error('Этот экземпляр класса уничтожен. Пожалуйста, создайте новый.'));
|
||||||
|
|
||||||
|
if (this.connecting) {
|
||||||
|
let i = this.openTimeout/100;
|
||||||
|
while (i-- > 0 && this.connecting) {
|
||||||
|
await utils.sleep(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//проверим подключение, и если нет, то подключимся заново
|
||||||
|
if (this.isOpen) {
|
||||||
|
resolve(this.ws);
|
||||||
|
} else {
|
||||||
|
this.connecting = true;
|
||||||
|
this.terminate();
|
||||||
|
|
||||||
|
if (isBrowser) {
|
||||||
|
const protocol = (window.location.protocol == 'https:' ? 'wss:' : 'ws:');
|
||||||
|
const url = this.url || `${protocol}//${window.location.host}/ws`;
|
||||||
|
this.ws = new this.WebSocket(url);
|
||||||
|
} else {
|
||||||
|
this.ws = new this.WebSocket(this.url);
|
||||||
|
}
|
||||||
|
|
||||||
|
const onopen = (e) => {
|
||||||
|
this.connecting = false;
|
||||||
|
resolve(this.ws);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onmessage = (data) => {
|
||||||
|
try {
|
||||||
|
if (isBrowser)
|
||||||
|
data = data.data;
|
||||||
|
const mes = JSON.parse(data);
|
||||||
|
this.messageQueue.push({regTime: Date.now(), mes});
|
||||||
|
|
||||||
|
this.processMessageQueue();
|
||||||
|
} catch (e) {
|
||||||
|
this.emit(e.message, true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onerror = (e) => {
|
||||||
|
this.emit(e.message, true);
|
||||||
|
reject(new Error(e.message));
|
||||||
|
};
|
||||||
|
|
||||||
|
const onclose = (e) => {
|
||||||
|
this.emit(e.message, true);
|
||||||
|
reject(new Error(e.message));
|
||||||
|
};
|
||||||
|
|
||||||
|
if (isBrowser) {
|
||||||
|
this.ws.onopen = onopen;
|
||||||
|
this.ws.onmessage = onmessage;
|
||||||
|
this.ws.onerror = onerror;
|
||||||
|
this.ws.onclose = onclose;
|
||||||
|
} else {
|
||||||
|
this.ws.on('open', onopen);
|
||||||
|
this.ws.on('message', onmessage);
|
||||||
|
this.ws.on('error', onerror);
|
||||||
|
this.ws.on('close', onclose);
|
||||||
|
}
|
||||||
|
|
||||||
|
await utils.sleep(this.openTimeout);
|
||||||
|
reject(new Error('Соединение не удалось'));
|
||||||
|
}
|
||||||
|
})() });
|
||||||
|
}
|
||||||
|
|
||||||
|
//timeout в секундах (проверка каждый cleanPeriod интервал)
|
||||||
|
message(requestId, timeoutSecs = 4) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.listeners.push({
|
||||||
|
regTime: Date.now(),
|
||||||
|
requestId,
|
||||||
|
timeout: timeoutSecs*1000,
|
||||||
|
onMessage: (mes) => {
|
||||||
|
resolve(mes);
|
||||||
|
},
|
||||||
|
onError: (mes) => {
|
||||||
|
reject(new Error(mes));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.processMessageQueue();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async send(req, timeoutSecs = 4) {
|
||||||
|
await this._open();
|
||||||
|
if (this.isOpen) {
|
||||||
|
this.requestId = (this.requestId < 1000000 ? this.requestId + 1 : 1);
|
||||||
|
const requestId = this.requestId;//реентерабельность!!!
|
||||||
|
|
||||||
|
this.ws.send(JSON.stringify(Object.assign({requestId, _rpo: 1}, req)));//_rpo: 1 - ждем в ответ _rok: 1
|
||||||
|
|
||||||
|
let resp = {};
|
||||||
|
try {
|
||||||
|
resp = await this.message(requestId, timeoutSecs);
|
||||||
|
} catch(e) {
|
||||||
|
this.terminate();
|
||||||
|
throw new Error('WebSocket не отвечает');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resp._rok) {
|
||||||
|
return requestId;
|
||||||
|
} else {
|
||||||
|
throw new Error('Запрос не принят сервером');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error('WebSocket коннект закрыт');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
terminate() {
|
||||||
|
if (this.ws) {
|
||||||
|
if (isBrowser) {
|
||||||
|
this.ws.close();
|
||||||
|
} else {
|
||||||
|
this.ws.terminate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.ws = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
close() {
|
||||||
|
this.terminate();
|
||||||
|
this.closed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
async periodicClean() {
|
||||||
|
while (!this.closed) {
|
||||||
|
try {
|
||||||
|
const now = Date.now();
|
||||||
|
//чистка listeners
|
||||||
|
let newListeners = [];
|
||||||
|
for (const listener of this.listeners) {
|
||||||
|
if (now - listener.regTime < listener.timeout) {
|
||||||
|
newListeners.push(listener);
|
||||||
|
} else {
|
||||||
|
if (listener.onError)
|
||||||
|
listener.onError('Время ожидания ответа истекло');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.listeners = newListeners;
|
||||||
|
|
||||||
|
//чистка messageQueue
|
||||||
|
let newMessageQueue = [];
|
||||||
|
for (const message of this.messageQueue) {
|
||||||
|
if (now - message.regTime < this.messageLifeTime) {
|
||||||
|
newMessageQueue.push(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.messageQueue = newMessageQueue;
|
||||||
|
} catch(e) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
await utils.sleep(cleanPeriod);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = WebSocketConnection;
|
||||||
@@ -4,8 +4,6 @@ const SqliteConnectionPool = require('./SqliteConnectionPool');
|
|||||||
const log = new (require('../core/AppLogger'))().log;//singleton
|
const log = new (require('../core/AppLogger'))().log;//singleton
|
||||||
|
|
||||||
const migrations = {
|
const migrations = {
|
||||||
'app': require('./migrations/app'),
|
|
||||||
'readerStorage': require('./migrations/readerStorage'),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let instance = null;
|
let instance = null;
|
||||||
@@ -32,11 +30,11 @@ class ConnManager {
|
|||||||
const dbFileName = this.config.dataDir + '/' + poolConfig.fileName;
|
const dbFileName = this.config.dataDir + '/' + poolConfig.fileName;
|
||||||
|
|
||||||
//бэкап
|
//бэкап
|
||||||
if (await fs.pathExists(dbFileName))
|
if (!poolConfig.noBak && await fs.pathExists(dbFileName))
|
||||||
await fs.copy(dbFileName, `${dbFileName}.bak`);
|
await fs.copy(dbFileName, `${dbFileName}.bak`);
|
||||||
|
|
||||||
const connPool = new SqliteConnectionPool();
|
const connPool = new SqliteConnectionPool();
|
||||||
await connPool.open(poolConfig.connCount, dbFileName);
|
await connPool.open(poolConfig, dbFileName);
|
||||||
|
|
||||||
log(`Opened database "${poolConfig.poolName}"`);
|
log(`Opened database "${poolConfig.poolName}"`);
|
||||||
//миграции
|
//миграции
|
||||||
|
|||||||
@@ -1,27 +1,32 @@
|
|||||||
const sqlite = require('sqlite');
|
const sqlite = require('sqlite');
|
||||||
const SQL = require('sql-template-strings');
|
const SQL = require('sql-template-strings');
|
||||||
|
|
||||||
const utils = require('../core/utils');
|
|
||||||
|
|
||||||
const waitingDelay = 100; //ms
|
|
||||||
|
|
||||||
class SqliteConnectionPool {
|
class SqliteConnectionPool {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.closed = true;
|
this.closed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async open(connCount, dbFileName) {
|
async open(poolConfig, dbFileName) {
|
||||||
if (!Number.isInteger(connCount) || connCount <= 0)
|
const connCount = poolConfig.connCount || 1;
|
||||||
return;
|
const busyTimeout = poolConfig.busyTimeout || 60*1000;
|
||||||
|
const cacheSize = poolConfig.cacheSize || 2000;
|
||||||
|
|
||||||
|
this.dbFileName = dbFileName;
|
||||||
this.connections = [];
|
this.connections = [];
|
||||||
this.freed = new Set();
|
this.freed = new Set();
|
||||||
|
this.waitingQueue = [];
|
||||||
|
|
||||||
for (let i = 0; i < connCount; i++) {
|
for (let i = 0; i < connCount; i++) {
|
||||||
let client = await sqlite.open(dbFileName);
|
let client = await sqlite.open(dbFileName);
|
||||||
client.configure('busyTimeout', 10000); //ms
|
|
||||||
|
client.configure('busyTimeout', busyTimeout); //ms
|
||||||
|
await client.exec(`PRAGMA cache_size = ${cacheSize}`);
|
||||||
|
|
||||||
client.ret = () => {
|
client.ret = () => {
|
||||||
this.freed.add(i);
|
this.freed.add(i);
|
||||||
|
if (this.waitingQueue.length) {
|
||||||
|
this.waitingQueue.shift().onFreed(i);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.freed.add(i);
|
this.freed.add(i);
|
||||||
@@ -30,30 +35,27 @@ class SqliteConnectionPool {
|
|||||||
this.closed = false;
|
this.closed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_setImmediate() {
|
get() {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
setImmediate(() => {
|
if (this.closed)
|
||||||
return resolve();
|
throw new Error('Connection pool closed');
|
||||||
|
|
||||||
|
const freeConnIndex = this.freed.values().next().value;
|
||||||
|
if (freeConnIndex !== undefined) {
|
||||||
|
this.freed.delete(freeConnIndex);
|
||||||
|
resolve(this.connections[freeConnIndex]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.waitingQueue.push({
|
||||||
|
onFreed: (connIndex) => {
|
||||||
|
this.freed.delete(connIndex);
|
||||||
|
resolve(this.connections[connIndex]);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async get() {
|
|
||||||
if (this.closed)
|
|
||||||
return;
|
|
||||||
|
|
||||||
let freeConnIndex = this.freed.values().next().value;
|
|
||||||
if (freeConnIndex == null) {
|
|
||||||
if (waitingDelay)
|
|
||||||
await utils.sleep(waitingDelay);
|
|
||||||
return await this._setImmediate().then(() => this.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
this.freed.delete(freeConnIndex);
|
|
||||||
|
|
||||||
return this.connections[freeConnIndex];
|
|
||||||
}
|
|
||||||
|
|
||||||
async run(query) {
|
async run(query) {
|
||||||
const dbh = await this.get();
|
const dbh = await this.get();
|
||||||
try {
|
try {
|
||||||
|
|||||||