Skip to content

Commit

Permalink
Add settings, downgrade pdfjs
Browse files Browse the repository at this point in the history
  • Loading branch information
v1ack committed May 22, 2021
1 parent 16ced58 commit d522e4a
Show file tree
Hide file tree
Showing 11 changed files with 299 additions and 27 deletions.
17 changes: 11 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@rollup/plugin-node-resolve": "^11.2.1",
"core-js": "^3.11.0",
"fs-extra": "^9.1.0",
"pdfjs-dist": "^2.7.570",
"pdfjs-dist": "2.5.207",
"prettier": "^2.2.1",
"prettier-plugin-svelte": "^2.2.0",
"remarkable": "^2.0.1",
Expand Down
8 changes: 4 additions & 4 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {copySync} from "fs-extra"
import path from "path"
import babel from "@rollup/plugin-babel"

const pdfJsWorker = path.resolve(__dirname, "node_modules/pdfjs-dist/es5/build/pdf.worker.min.js")
const pdfJs = path.resolve(__dirname, "node_modules/pdfjs-dist/es5/build/pdf.min.js")
const pdfJsWorker = path.resolve(__dirname, "node_modules/pdfjs-dist/es5/build/pdf.worker.js")
// const pdfJs = path.resolve(__dirname, "node_modules/pdfjs-dist/es5/build/pdf.js")
// const pdfJsWorker = path.resolve(__dirname, "node_modules/pdfjs-dist/build/pdf.worker.min.js")
// const pdfJs = path.resolve(__dirname, "node_modules/pdfjs-dist/build/pdf.min.js")

Expand Down Expand Up @@ -90,15 +90,15 @@ const copyToDist = () => ({
})

export default {
external: ["tizen", pdfJs, pdfJsWorker, "webapis"],
external: ["tizen", pdfJsWorker, "webapis"],
input: "src/index.js",
output: {
file: "build/bundle.js",
format: "iife",
name: "app",
globals: {
[pdfJsWorker]: "PdfjsWorker",
[pdfJs]: "Pdfjs",
// [pdfJs]: "Pdfjs",
"tizen": "tizen",
"webapis": "webapis"
}
Expand Down
159 changes: 159 additions & 0 deletions src/components/GenericList.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<script>
import {createEventDispatcher} from "svelte"
import {scrollTo} from "../utils"
export let title
export let items
export let height = 360
export let itemsShow = 3
/**
* Выбранный элемент
* @type {number}
*/
export let chosen = 0
const dispatch = createEventDispatcher()
let itemHeight = height / itemsShow
/**
* ID таймаута скролла
* @type {number}
*/
let scrollTimeout
/**
* ID таймаута выбора элемента
* @type {number}
*/
let selectTimeout
let containerNode
/**
* Предыдущий выбранный элемент. Нужен чтобы понимать произошли ли изменения
* @type {number}
*/
let lastChosen = 0
function scroll(e) {
let scrollTop = e.target.scrollTop
let new_chosen =
Math.round((scrollTop + height / 2 + itemHeight / 2) / itemHeight) - 2
if (new_chosen !== chosen) {
lastChosen = chosen
chosen = new_chosen
if (selectTimeout) clearTimeout(selectTimeout)
selectTimeout = setTimeout(() => {
dispatch("select", {index: chosen})
}, 500)
}
if (scrollTimeout) clearTimeout(scrollTimeout)
scrollTimeout = setTimeout(() => {
let scroll = itemHeight * chosen
scrollTo(containerNode, 0, scroll)
}, 300)
}
function bezelRotate(e) {
if (e.detail.direction === "CW" && chosen < items.length - 1) {
chosen = chosen + 1
scrollTo(containerNode, 0, itemHeight * chosen)
}
if (e.detail.direction === "CCW" && chosen > 0) {
chosen = chosen - 1
scrollTo(containerNode, 0, itemHeight * chosen)
}
}
</script>

<svelte:window on:rotarydetent={bezelRotate} />

<div
bind:this={containerNode}
class="cont"
on:scroll={scroll}
style="height: {height}px;"
>
<div class="item fake-item" style="height: {itemHeight}px;">
{#if title}
<div class="title" style="color: #14b6ff">{title}</div>
{/if}
</div>
<!-- TODO: добавить id -->
{#each items as item, i (item.title || item)}
<div
on:click={() => dispatch("click", item)}
class:active={chosen === i}
class="item"
style="height: {itemHeight}px;"
>
<slot {item} active={chosen === i} />
</div>
{/each}
<div class="fake-item" style="height: {itemHeight}px;" />
</div>

<style>
.item {
text-align: center;
margin: 0;
box-sizing: border-box;
border-radius: 99px;
transition: background ease-in-out 0.5s;
justify-content: center;
display: flex;
flex-direction: column;
}
.cont {
overflow-y: scroll;
scroll-behavior: smooth;
}
.active {
background: #3a3a3a;
}
.title {
font-weight: bold;
font-size: 2em;
}
.active .title {
font-size: 2.2em;
}
.subtitle {
font-size: 1.8em;
/* TODO: сделать плавающий текст */
max-height: 72px;
overflow: hidden;
word-break: break-all;
}
.title {
max-width: 100%;
margin: 0 auto;
white-space: nowrap;
overflow: hidden;
}
.title span {
display: inline-block;
}
.title :global(span.animated) {
animation: marquee 10s ease-in-out alternate infinite;
}
@keyframes marquee {
0% {
transform: translateX(20px);
}
100% {
transform: translateX(calc(-100% + 340px));
}
}
</style>
4 changes: 2 additions & 2 deletions src/components/List.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
let itemHeight = height / itemsShow
/**
* ID таймоута скролла
* ID таймаута скролла
* @type {number}
*/
let scrollTimeout
/**
* ID таймоута выбора элемента
* ID таймаута выбора элемента
* @type {number}
*/
let selectTimeout
Expand Down
14 changes: 8 additions & 6 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ export const defaultConfigValues = {
txtFontSize: "16",
txtTheme: "white",
pdfAction: bezelActions.scale,
zoomButtons: "",
supportBezel:
isDev ||
tizen.systeminfo.getCapability(
"http://tizen.org/feature/input.rotating_bezel"
)
? "true"
: "",
}

export const pages = {
Expand Down Expand Up @@ -84,9 +92,3 @@ export const bezelActionsButtons = {
}

export const isDev = is_dev

export const supportBezel =
isDev ||
tizen.systeminfo.getCapability(
"http://tizen.org/feature/input.rotating_bezel"
)
2 changes: 1 addition & 1 deletion src/pages/MainScreen.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
let pagesList = [
{title: "Open", subtitle: "Open a load file", pageId: pages.filesList},
// {title: "Settings", subtitle: "Bezel action", pageId: pages.settings},
{title: "Settings", subtitle: "Bezel action", pageId: pages.settings},
{title: "Help", subtitle: "App description", pageId: pages.help},
]
if ($configStore.lastFile) {
Expand Down
8 changes: 4 additions & 4 deletions src/pages/PdfView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {configStore, docStore} from "../store"
import {onMount} from "svelte"
import InViewSettings from "../components/InViewSettings.svelte"
import {bezelActions, bezelActionsButtons, supportBezel} from "../constants"
import {bezelActions, bezelActionsButtons} from "../constants"
import {bezelEventScroll} from "../utils"
import InViewSettingsBlock from "../components/InViewSettingsBlock.svelte"
Expand Down Expand Up @@ -91,22 +91,22 @@
<div
bind:this={containerNode}
class="container"
class:bottom-padding={!supportBezel}
class:bottom-padding={!$configStore.supportBezel}
>
<div class="buttons-block top">
<button on:click={backwards} style="text-align: right;">&lt</button>
<span>{currentPage}/{pagesCount}</span>
<button on:click={towards} style="text-align: left;">&gt</button>
</div>
<canvas bind:this={canvas} />
{#if !supportBezel}
{#if $configStore.zoomButtons}
<div class="buttons-block bottom">
<button on:click={scaleDown} style="text-align: right;">-</button>
<button on:click={scaleUp} style="text-align: left;">+</button>
</div>
{/if}
</div>
{#if supportBezel}
{#if $configStore.supportBezel}
<InViewSettings>
<InViewSettingsBlock
bind:current={pdfAction}
Expand Down
Loading

0 comments on commit d522e4a

Please sign in to comment.