Compare commits

16 Commits

Author SHA1 Message Date
0dff9d869d Restructuring 2020-02-09 18:26:22 +01:00
b588693ccf Switching to parcel 2020-02-09 17:36:25 +01:00
db5a363bff Merge branch 'retheme' 2020-02-09 00:38:26 +01:00
bc6b12afa1 Blocking scroll to reload 2019-07-30 16:06:22 +00:00
b05e2d3c55 Fixing ServiceWorker Clear Cache 2019-07-02 20:02:47 +02:00
ae5257b2b3 Adding automatic theme change 2019-07-02 19:10:16 +02:00
c3f9529feb Updaing to IDB 4x 2019-07-02 18:34:41 +02:00
93b272ecb5 Updating stuff 2019-07-02 17:45:14 +02:00
22e6cacd8e Updating dependency 2019-06-19 14:20:04 +02:00
c52e08afa9 Adding clear cache button to settings 2019-06-18 23:28:07 +02:00
60b238d42e Adjusting Footer 2019-06-18 23:23:43 +02:00
14dec9ce96 Fixing some style problems 2019-06-18 23:10:58 +02:00
d67a51f83b Updating dependencies 2019-06-18 23:00:02 +02:00
bb1f98761d Updating dependencies 2019-06-18 22:56:50 +02:00
0b56f9b1a8 Moving to new theme 2019-06-18 22:55:04 +02:00
560828f4a2 Small improvments 2019-06-18 17:32:15 +02:00
38 changed files with 4765 additions and 5223 deletions

8537
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -4,53 +4,34 @@
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"build": "webpack --mode=production", "build": "parcel build src/index.html",
"watch": "webpack --mode=development --watch", "dev": "parcel src/index.html"
"start": "webpack-dev-server --mode=production",
"start:prod": "webpack-dev-server --mode=production",
"start:dev": "webpack-dev-server --mode=development"
}, },
"author": "Fabian Stamm <dev@fabianstamm.de>", "author": "Fabian Stamm <dev@fabianstamm.de>",
"license": "MIT", "license": "MIT",
"browserslist": [
"last 2 Chrome versions"
],
"dependencies": { "dependencies": {
"@hibas123/secure-file-wrapper": "^2.5.0", "@hibas123/secure-file-wrapper": "^2.5.1",
"@hibas123/utils": "^2.1.0", "@hibas123/theme": "^1.2.14",
"@hibas123/utils": "^2.2.3",
"aes-js": "^3.1.2", "aes-js": "^3.1.2",
"feather-icons": "^4.21.0", "feather-icons": "^4.26.0",
"idb": "3.0.2", "idb": "^4.0.3",
"js-sha256": "^0.9.0", "js-sha256": "^0.9.0",
"js-sha512": "^0.8.0",
"lodash.clonedeep": "^4.5.0", "lodash.clonedeep": "^4.5.0",
"secure-file-wrapper": "git+https://git.stamm.me/OpenServer/OSSecureFileWrapper.git", "parcel": "^1.12.4",
"uikit": "^3.1.5", "uuid": "^3.4.0"
"uuid": "^3.3.2",
"workbox-precaching": "^4.3.1",
"workbox-routing": "^4.3.1",
"workbox-strategies": "^4.3.1"
}, },
"devDependencies": { "devDependencies": {
"@types/lodash.clonedeep": "^4.5.6", "@types/lodash.clonedeep": "^4.5.6",
"@types/uikit": "^2.27.7", "@types/uikit": "^2.27.7",
"@types/uuid": "^3.4.4", "@types/uuid": "^3.4.7",
"@types/workbox-sw": "^4.2.0", "node-sass": "^4.13.1",
"copy-webpack-plugin": "^5.0.3", "parcel-bundler": "^1.12.4",
"css-loader": "^2.1.1", "preact": "^10.3.1",
"file-loader": "^3.0.1", "ts-loader": "^6.2.1",
"html-webpack-plugin": "^3.2.0", "typescript": "^3.7.5"
"mini-css-extract-plugin": "^0.7.0",
"node-sass": "^4.12.0",
"preact": "^8.3.1",
"preact-svg-loader": "^0.2.1",
"sass-loader": "^7.1.0",
"style-loader": "^0.23.1",
"ts-loader": "^6.0.2",
"typescript": "^3.5.1",
"webpack": "^4.32.2",
"webpack-bundle-analyzer": "^3.3.2",
"webpack-cli": "^3.3.2",
"webpack-dev-server": "^3.5.1",
"webpack-visualizer-plugin": "^0.1.11",
"workbox-webpack-plugin": "^4.3.1",
"worker-loader": "^2.0.0"
} }
} }

View File

@ -0,0 +1,37 @@
import { h } from "preact";
import { Page } from "../../page";
import Theme, { ThemeStates } from "../../theme";
import Navigation from "../../navigation";
import ArrowLeft from "feather-icons/dist/icons/arrow-left.svg";
export default class SettingsPage extends Page<{ state: any }, { vault: string }> {
componentWillMount() {
}
render() {
let active = Theme.active();
return <div>
<header class="header">
<a class="header-icon-button" onClick={() => history.back()}><img src={ArrowLeft} height={undefined} width={undefined} /></a>
<h3 style="display:inline" class="header-title" onClick={() => Navigation.setPage("/")}>Settings</h3>
<span></span>
</header>
<div class="container">
<div className="input-group">
<label>Select Theme: </label>
<select class="inp" onChange={(ev) => Theme.change(Number((ev.target as HTMLSelectElement).value))}>
{Object.keys(ThemeStates)
.filter(e => Number.isNaN(Number(e)))
.map(e => <option selected={ThemeStates[e] === active} value={ThemeStates[e]}>{e.charAt(0).toUpperCase() + e.slice(1).toLowerCase()}</option>)}
{/* <option value={ThemeStates.AUTO}>Auto</option>
<option value={ThemeStates.LIGHT}>Light</option>
<option value={ThemeStates.DARK}>Dark</option> */}
</select>
</div>
{/* <button class="btn" onClick={() => Theme.toggle()}>Toggle Dark Mode</button> */}
<button class="btn" onClick={() => window.navigator.serviceWorker.controller.postMessage("message")}>Clear cache</button>
</div>
</div >;
}
}

View File

@ -1,7 +1,7 @@
import { h } from "preact"; import { h } from "preact";
import { Page } from "../../../page"; import { Page } from "../../page";
import VaultsPage from "../vaults/Vaults"; import VaultsPage from "../Vaults/Vaults";
import Navigation from "../../../navigation"; import Navigation from "../../navigation";
export default class SharePage extends Page<{ state: any }, { vault: string }> { export default class SharePage extends Page<{ state: any }, { vault: string }> {
text: string; text: string;

View File

@ -1,12 +1,12 @@
import { h, Component } from "preact" import { h, Component } from "preact"
import { IVault, ViewNote } from "../../../notes"; import { IVault, ViewNote } from "../../notes";
import Trash from "feather-icons/dist/icons/trash-2.svg" import Trash from "feather-icons/dist/icons/trash-2.svg"
import X from "feather-icons/dist/icons/x.svg" import X from "feather-icons/dist/icons/x.svg"
import Save from "feather-icons/dist/icons/save.svg" import Save from "feather-icons/dist/icons/save.svg"
import Navigation from "../../../navigation"; import Navigation from "../../navigation";
import { YesNoModal } from "../../modals/YesNoModal"; import { YesNoModal } from "../../components/modals/YesNoModal";
import Notifications, { MessageType } from "../../../notifications"; import Notifications, { MessageType } from "../../notifications";
const minRows = 3; const minRows = 3;
export default class EntryComponent extends Component<{ vault: Promise<IVault>, id: string | undefined, note: string | undefined }, { title: string, changed: boolean }> { export default class EntryComponent extends Component<{ vault: Promise<IVault>, id: string | undefined, note: string | undefined }, { title: string, changed: boolean }> {
@ -165,17 +165,17 @@ export default class EntryComponent extends Component<{ vault: Promise<IVault>,
console.log("Rerender") console.log("Rerender")
return <div> return <div>
<header class="uk-background-primary"> <header class="header">
<a class="header-icon-button" onClick={() => this.exitHandler()}><X height={undefined} width={undefined} /></a> <a class="header-icon-button" onClick={() => this.exitHandler()}><img src={X} height={undefined} width={undefined} /></a>
{this.state.changed ? <a class="header-icon-button" style="margin-left: 0.5em;" onClick={() => save_handler()}><Save height={undefined} width={undefined} /></a> : undefined} {this.state.changed ? <a class="header-icon-button" style="margin-left: 0.5em;" onClick={() => save_handler()}><img src={Save} height={undefined} width={undefined} /></a> : undefined}
<h3 style="display:inline" class="button header-title">{this.state.title}</h3> <h3 style="display:inline" class="button header-title">{this.state.title}</h3>
<a class="header-icon-button" onClick={() => delete_handler()}><Trash height={undefined} width={undefined} /></a> <a class="header-icon-button" onClick={() => delete_handler()}><img src={Trash} height={undefined} width={undefined} /></a>
</header> </header>
<div class="uk-container"> <div class="container">
<textarea <textarea
value={this.text} value={this.text}
rows={this.rows} rows={this.rows}
class="doc uk-textarea" class="inp"
style="width:100%;" style="width:100%;"
onInput={this.textAreaChange} onInput={this.textAreaChange}
onKeyDown={this.textAreaKeyPress} onKeyDown={this.textAreaKeyPress}

View File

@ -1,11 +1,11 @@
import { h, Component } from "preact" import { h, Component, JSX } from "preact"
import Notes, { IVault, BaseNote } from "../../../notes"; import Notes, { IVault, BaseNote } from "../../notes";
import AddButton from "../../AddButton"; import AddButton from "../../components/AddButton";
import Navigation from "../../../navigation"; import Navigation from "../../navigation";
import ArrowLeft from "feather-icons/dist/icons/arrow-left.svg" import ArrowLeft from "feather-icons/dist/icons/arrow-left.svg"
import Search from "feather-icons/dist/icons/search.svg" import Search from "feather-icons/dist/icons/search.svg"
import ContextMenu from "../../context"; import ContextMenu from "../../components/context";
import Notifications from "../../../notifications"; import Notifications from "../../notifications";
import { Observable, Lock } from "@hibas123/utils"; import { Observable, Lock } from "@hibas123/utils";
@ -107,15 +107,15 @@ export default class EntryList extends Component<{ vault: Promise<IVault> }, { n
let share; let share;
if ((window.navigator as any).share) { if ((window.navigator as any).share) {
share = <button class="uk-button" onClick={shareNote}> share = <button class="btn" onClick={shareNote}>
share share
</button> </button>
} }
let context = <ContextMenu event={evt} > let context = <ContextMenu event={evt} >
{share} {share}
<button class="uk-button" onClick={deleteNote}>delete</button> <button class="btn" onClick={deleteNote}>delete</button>
<button class="uk-button" onClick={copyNote}>copy</button> <button class="btn" onClick={copyNote}>copy</button>
</ContextMenu> </ContextMenu>
this.setState({ context }); this.setState({ context });
@ -265,32 +265,30 @@ export default class EntryList extends Component<{ vault: Promise<IVault> }, { n
return <div> return <div>
{this.state.context} {this.state.context}
<header class="uk-background-primary"> <header class="header">
<a class="header-icon-button" onClick={() => history.back()}><ArrowLeft height={undefined} width={undefined} /></a> <a class="header-icon-button" onClick={() => history.back()}><img src={ArrowLeft} height={undefined} width={undefined} /></a>
<h3 style="display:inline" class="header-title" onClick={() => Navigation.setPage("/")}>{this.vault ? this.vault.name : ""}</h3> <h3 style="display:inline" class="header-title" onClick={() => Navigation.setPage("/")}>{this.vault ? this.vault.name : ""}</h3>
<span></span> <span></span>
{/* <a class="button header_icon_button"><MoreVertival height={undefined} width={undefined} /></a> */} {/* <a class="button header_icon_button"><MoreVertival height={undefined} width={undefined} /></a> */}
</header> </header>
<AddButton onClick={() => open_entry(null)} /> <AddButton onClick={() => open_entry(null)} />
<div class="uk-container"> <div class="container">
<div style="display:flex;"> <div style="display:flex;">
<input class="uk-input" type="text" onKeyUp={this.searchChanged} ref={elm => this.searchInput = elm} /> <input class="inp" type="text" style="width: 100%; height: 40px;" onKeyUp={this.searchChanged} ref={elm => this.searchInput = elm} />
<button class="uk-button uk-button-primary" style="padding: 0 10px;"> <button class="btn btn-primary" style="padding: 5px 10px; margin: 0; height: 40px; width: 40px;">
<Search /> <img src={Search} />
</button> </button>
</div> </div>
<div class="uk-child-width-1-3@m uk-grid-small uk-grid-match" style="margin-top: 1rem;" uk-grid> <div class="vault-list" style="margin-top: 1rem;">
{this.state.notes.map(note => { {this.state.notes.map(note => {
let [first, second] = note.preview.split("\n", 2); let [first, second] = note.preview.split("\n", 2);
return <div class="" onContextMenu={evt => this.onContext(evt, note)} onClick={() => { return <div class="card vault-vault" onContextMenu={evt => this.onContext(evt, note)} onClick={() => {
open_entry(note._id) open_entry(note._id)
}}> }}>
<div class="uk-card uk-card-default uk-card-body vault-vault" style="box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3)">
<div>{first}</div> <div>{first}</div>
<div>{second}</div> <div>{second}</div>
</div> </div>
</div>
})} })}
</div> </div>
</div> </div>

View File

@ -1,7 +1,7 @@
import { h } from "preact" import { h } from "preact"
import { Page } from "../../../page"; import { Page } from "../../page";
import Notes, { IVault, BaseNote } from "../../../notes"; import Notes, { IVault, BaseNote } from "../../notes";
import Navigation from "../../../navigation"; import Navigation from "../../navigation";
import EntryComponent from "./Entry"; import EntryComponent from "./Entry";
import EntryList from "./EntryList"; import EntryList from "./EntryList";

43
src/Views/Vault/vault.scss Executable file
View File

@ -0,0 +1,43 @@
.container> :last-child {
margin-bottom: 15px !important;
}
.vault-list {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-gap: 1rem;
grid-auto-rows: auto;
}
@media screen and (max-width: 50rem) {
.vault-list {
grid-template-columns: 1fr;
}
}
// TODO Media Query for small screens
.vault-vault {
overflow: hidden;
>div {
width: 100%;
font-size: 1.1rem;
margin-left: 1rem;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
>div:nth-of-type(1) {
font-size: 1.3rem;
margin-left: 0;
}
>div:empty {
&::before {
content: " ";
white-space: pre;
}
}
}

View File

@ -1,15 +1,16 @@
import { h } from "preact" import { h, JSX } from "preact"
import { Page } from "../../../page"; import { Page } from "../../page";
import Notes, { VaultList } from "../../../notes"; import Notes, { VaultList } from "../../notes";
import "./vaults.scss" import "./vaults.scss"
import Lock from "feather-icons/dist/icons/lock.svg"; import Lock from "feather-icons/dist/icons/lock.svg";
import Unlock from "feather-icons/dist/icons/unlock.svg"; import Unlock from "feather-icons/dist/icons/unlock.svg";
import Navigation from "../../../navigation"; import Settings from "feather-icons/dist/icons/settings.svg"
import { InputModal } from "../../modals/InputModal"; import Navigation from "../../navigation";
import { YesNoModal } from "../../modals/YesNoModal"; import { InputModal } from "../../components/modals/InputModal";
import AddButton from "../../AddButton"; import { YesNoModal } from "../../components/modals/YesNoModal";
import ContextMenu from "../../context"; import AddButton from "../../components/AddButton";
import Notifications from "../../../notifications"; import ContextMenu from "../../components/context";
import Notifications from "../../notifications";
export interface VaultsProps { export interface VaultsProps {
state: any; state: any;
@ -135,14 +136,14 @@ export default class VaultsPage extends Page<VaultsProps, { vaults: VaultList, m
} }
document.documentElement.addEventListener("click", close); document.documentElement.addEventListener("click", close);
let deleteb = <button class="uk-button" onClick={async () => { let deleteb = <button class="btn" onClick={async () => {
let delete_modal = new YesNoModal("Delete Vault? Cannot be undone!"); let delete_modal = new YesNoModal("Delete Vault? Cannot be undone!");
let result = await delete_modal.getResult(); let result = await delete_modal.getResult();
if (result) { if (result) {
Notes.deleteVault(vault.id).then(() => { Notes.deleteVault(vault.id).then(() => {
this.updateVaults(); this.updateVaults();
}).catch(err => { }).catch(err => {
Notifications.sendError("error deleting vault!") Notifications.sendError("Error deleting vault!")
console.error(err); console.error(err);
}) })
} }
@ -152,15 +153,15 @@ export default class VaultsPage extends Page<VaultsProps, { vaults: VaultList, m
let delete_key; let delete_key;
if (Notes.getVaultKey(vault.id)) { if (Notes.getVaultKey(vault.id)) {
delete_key = <button class="uk-button" onClick={() => { delete_key = <button class="btn" onClick={() => {
Notes.forgetVaultKey(vault.id); Notes.forgetVaultKey(vault.id);
Notifications.sendSuccess("Forgot key!") Notifications.sendSuccess("Forgot password!")
}}> }}>
forget password forget password
</button>; </button>;
} }
let exportb = <button class="uk-button" onClick={async () => { let exportb = <button class="btn" onClick={async () => {
let key: Uint8Array; let key: Uint8Array;
if (vault.encrypted) { if (vault.encrypted) {
await this.getKey(vault, false) await this.getKey(vault, false)
@ -205,9 +206,13 @@ export default class VaultsPage extends Page<VaultsProps, { vaults: VaultList, m
} }
render() { render() {
// <Unlock height={undefined} width={undefined} />}
// <Lock height={undefined} width={undefined} />
let elms = this.state.vaults.map(vault => { let elms = this.state.vaults.map(vault => {
return <li class="vaults_vault" onClick={() => this.openVault(vault)} onContextMenu={(evt) => this.onContext(evt, vault)}> return <li class="vaults_vault" onClick={() => this.openVault(vault)} onContextMenu={(evt) => this.onContext(evt, vault)}>
{vault.encrypted ? <Lock height={undefined} width={undefined} /> : <Unlock height={undefined} width={undefined} />} {vault.encrypted ? <img src={Lock} /> : <img src={Unlock} />}
<span> <span>
{vault.name} {vault.name}
</span> </span>
@ -217,14 +222,17 @@ export default class VaultsPage extends Page<VaultsProps, { vaults: VaultList, m
return <div style={{ marginTop: "-12px", paddingTop: "12px" }} > return <div style={{ marginTop: "-12px", paddingTop: "12px" }} >
{/* {this.state.modal} */} {/* {this.state.modal} */}
{this.state.context} {this.state.context}
<header class="uk-background-primary"> <header class="header">
<span></span> <span></span>
<h3 style="display:inline" onClick={() => Navigation.setPage("/")}>{this.props.selectVault ? "Select Vault for share" : "Your vaults:"}</h3> <h3 style="display:inline" onClick={() => Navigation.setPage("/")}>{this.props.selectVault ? "Select Vault for share" : "Your vaults:"}</h3>
<span></span> <a class="header-icon-button" onClick={() => Navigation.setPage("/settings")}>
<img src={Settings} />
{/* <Settings height={undefined} width={undefined} /> */}
</a>
</header> </header>
<AddButton onClick={() => this.addButtonClick()} /> <AddButton onClick={() => this.addButtonClick()} />
<div class="uk-container"> <div class="container">
<ul class="uk-list uk-list-divider"> <ul class="list list-divider list-clickable">
{elms} {elms}
</ul> </ul>
</div> </div>

19
src/Views/Vaults/vaults.scss Executable file
View File

@ -0,0 +1,19 @@
.vaults_vault {
display: flex;
padding: 0.5rem;
margin-top: 0 !important;
align-items: flex-end;
justify-content: start;
>span {
font-size: 1.5rem;
line-height: 1.5rem;
}
>svg {
display: inline-block;
height: 1.5em;
width: 1.5em;
margin-right: 1rem;
}
}

View File

@ -3,10 +3,12 @@ import "./add_button.scss";
import Plus from "feather-icons/dist/icons/plus.svg"; import Plus from "feather-icons/dist/icons/plus.svg";
export default function AddButton({ onClick }: { onClick: () => void }) { export default function AddButton({ onClick }: { onClick: () => void }) {
return <button return <button
title={"add button"} title="add button"
class="add-button-button uk-button-primary uk-border-circle def-shadow" class="fab btn-primary"
onClick={() => onClick()} onClick={() => onClick()}
> >
<Plus width={undefined} height={undefined} /> <img src={Plus} />
</button> </button>
} }
// <Plus width={undefined} height={undefined} />

View File

@ -56,16 +56,21 @@ export class Footer extends Component<{}, { synced: boolean, syncing: boolean }>
text = "not synced"; text = "not synced";
} }
} }
return <footer class="uk-background-default def-shadow"> return <footer class="elv-8">
<span> <span>
<span class={extrac} ><a onClick={() => this.onSyncClick()} ><Refresh style="height: 1em; width: 1em;"></Refresh></a></span> <span class={extrac} >
<a onClick={() => this.onSyncClick()} >
<img src={Refresh} style="height: 1em; width: 1em;" />
{/* <Refresh style="height: 1em; width: 1em;"></Refresh> */}
</a>
</span>
<span style={"margin-left: 8px; color:" + color}>{text}</span> <span style={"margin-left: 8px; color:" + color}>{text}</span>
</span> </span>
<span> <span>
Welcome <b>{Notes.name}</b> Welcome <b>{Notes.name}</b>
</span> </span>
<span style="color: lightgrey;"> <span style="color: lightgrey;">
v1.3 v1.4
</span> </span>
</footer> </footer>
} }

View File

@ -1,4 +1,4 @@
import { h, Component } from 'preact'; import { h, Component, JSX } from 'preact';
import Navigation from '../navigation'; import Navigation from '../navigation';
import "./routing.scss" import "./routing.scss"
@ -26,7 +26,7 @@ export class Router extends Component<{}, { next?: JSX.Element, current: JSX.Ele
render() { render() {
let overlay; let overlay;
if (this.state.next) { if (this.state.next) {
overlay = <div class="transition_container transition_slidein uk-background-default" key={this.state.next.key} ref={(elm: HTMLDivElement) => { overlay = <div class="transition_container transition_slidein background-default" key={this.state.next.key} ref={(elm: HTMLDivElement) => {
let lst = () => { let lst = () => {
if (this.state.next) if (this.state.next)
this.setState({ current: this.state.next, next: undefined }, () => { this.setState({ current: this.state.next, next: undefined }, () => {
@ -43,7 +43,7 @@ export class Router extends Component<{}, { next?: JSX.Element, current: JSX.Ele
</div> </div>
} }
return <div style="position: relative; overflow-x: hidden; width: 100vw; height: calc(100vh - 2rem);"> return <div style="position: relative; overflow-x: hidden; width: 100vw; height: calc(100vh - 2rem);">
<div class="transition_container uk-background-default" key={this.state.current.key} ref={elm => this.mounted = elm}> <div class="transition_container background-default" key={this.state.current.key} ref={elm => this.mounted = elm}>
{this.state.current} {this.state.current}
</div> </div>
{overlay} {overlay}

View File

@ -1,4 +1,4 @@
import { h } from "preact"; import { h, JSX } from "preact";
import "./context.scss"; import "./context.scss";
export default function ContextMenu({ children, event }: { children: JSX.Element | JSX.Element[], event: MouseEvent }) { export default function ContextMenu({ children, event }: { children: JSX.Element | JSX.Element[], event: MouseEvent }) {

View File

@ -16,7 +16,7 @@
} }
footer { footer {
z-index: 128; // z-index: 128;
position: fixed; position: fixed;
bottom: 0; bottom: 0;
left: 0; left: 0;

View File

@ -27,12 +27,10 @@ export class InputModal extends Modal<string> {
render() { render() {
return <Modal.BaseModal modal={this.props.modal}> return <Modal.BaseModal modal={this.props.modal}>
<div class="uk-form-horizontal uk-margin-large"> <div>
<div class="uk-margin"> <div class="input-group">
<label class="uk-form-label" for={this.rand}>{this.props.modal.fieldname}</label> <label for={this.rand}>{this.props.modal.fieldname}</label>
<div class="uk-form-controls">
<input <input
class="uk-input"
id={this.rand} id={this.rand}
type={this.props.modal.type} type={this.props.modal.type}
placeholder={this.props.modal.fieldname} placeholder={this.props.modal.fieldname}
@ -45,9 +43,8 @@ export class InputModal extends Modal<string> {
}} }}
/> />
</div> </div>
</div> <div class="modal-action">
<div class="uk-margin" style="text-align: right;"> <button class="btn btn-primary" onClick={() => {
<button class="uk-button uk-button-primary" style="display: inline-block;" onClick={() => {
this.props.modal.result(this.input.value); this.props.modal.result(this.input.value);
}}>Enter</button> }}>Enter</button>
</div> </div>

View File

@ -12,7 +12,7 @@ export default class LoadingModal extends Modal<undefined> {
getComponent() { getComponent() {
return <Modal.BaseModal modal={this}> return <Modal.BaseModal modal={this}>
<div style="display: flex; justify-content: center;"> <div style="display: flex; justify-content: center;">
<div style="margin: 3rem;" class="uk-spinner uk-icon"> <div style="margin: 3rem;" class="">
<svg width="90" height="90" viewBox="0 0 30 30" xmlns="http://www.w3.org/2000/svg" data-svg="spinner"><circle fill="none" stroke="#000" cx="15" cy="15" r="14" style="stroke-width: 0.333333px;"></circle></svg> <svg width="90" height="90" viewBox="0 0 30 30" xmlns="http://www.w3.org/2000/svg" data-svg="spinner"><circle fill="none" stroke="#000" cx="15" cy="15" r="14" style="stroke-width: 0.333333px;"></circle></svg>
</div> </div>
</div> </div>

View File

@ -1,5 +1,5 @@
import { Observable } from "@hibas123/utils"; import { Observable } from "@hibas123/utils";
import { h, Component } from "preact"; import { h, Component, JSX } from "preact";
import CloseIcon from "feather-icons/dist/icons/x.svg"; import CloseIcon from "feather-icons/dist/icons/x.svg";
export default abstract class Modal<T> { export default abstract class Modal<T> {
@ -65,12 +65,13 @@ export default abstract class Modal<T> {
this.props.modal.result(null) this.props.modal.result(null)
} }
}}> }}>
<div id="ModalContent" class="uk-card uk-card-body uk-card-body" > <div id="ModalContent" class="modal" >
<div class="modal-title uk-card-title" style=""> <div class="modal-title" style="">
<h3>{this.props.modal.title}</h3> <h3>{this.props.modal.title}</h3>
{/* <div> */} {/* <div> */}
{!this.props.modal.noClose ? {!this.props.modal.noClose ?
<CloseIcon onClick={() => this.props.modal.result(null)} width={undefined} height={undefined} /> <img src={CloseIcon} onClick={() => this.props.modal.result(null)} />
// <CloseIcon onClick={() => this.props.modal.result(null)} width={undefined} height={undefined} />
: undefined : undefined
} }
{/* </div> */} {/* </div> */}

View File

@ -28,16 +28,14 @@ export class YesNoModal extends Modal<boolean> {
render() { render() {
return <Modal.BaseModal modal={this.props.modal}> return <Modal.BaseModal modal={this.props.modal}>
<div class="uk-margin-large"> <div class="modal-action">
<div style="text-align: right;"> <button class="btn-primary" onClick={() => {
<button class="uk-button uk-button-primary uk-margin-right" style="display: inline-block;" onClick={() => {
this.props.modal.result(false); this.props.modal.result(false);
}}><span style="text-decoration: underline;">N</span>o</button> }}><span style="text-decoration: underline;">N</span>o</button>
<button class="uk-button uk-button-primary" style="display: inline-block;" onClick={() => { <button class="btn-primary" onClick={() => {
this.props.modal.result(true); this.props.modal.result(true);
}}><span style="text-decoration: underline;">Y</span>es</button> }}><span style="text-decoration: underline;">Y</span>es</button>
</div> </div>
</div>
</Modal.BaseModal> </Modal.BaseModal>
} }
} }

View File

@ -4,24 +4,25 @@
left: 0; left: 0;
width: 100%; width: 100%;
height: 100%; height: 100%;
background: rgba(0, 0, 0, 0.8);
z-index: 32; z-index: 32;
animation: darkenBackground .2s linear;
background: rgba(0, 0, 0, 0.8)
} }
.modal-container>.uk-card { @keyframes darkenBackground {
position: absolute; from {
left: 0; background: rgba(0, 0, 0, 0);
right: 0; }
top: 10%;
width: 80%; to {
max-width: 800px; background: rgba(0, 0, 0, 0.8);
margin: auto; }
background: white;
} }
.modal-title { .modal-title {
display:flex; display: flex;
justify-content:space-between; justify-content: space-between;
>svg { >svg {
height: 1em; height: 1em;
} }

View File

@ -1,46 +0,0 @@
.uk-container> :last-child {
margin-bottom: 15px !important;
}
.vault-vault {
width: 100%;
>div {
width: 100%;
font-size: 1rem;
margin-left: 1rem;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
>div:nth-of-type(1) {
font-size: 1.3rem;
margin-left: 0;
}
>div:empty {
&::before {
content: " ";
white-space: pre;
}
}
}
// .vault_vault {
// padding: 0.5rem;
// border-bottom: solid 1px var(--card-border-color);
// }
// .vault_vault:hover {
// background: var(--nav-hover-back-color);
// }
// .vault_vault>svg {
// height: 2rem;
// margin-right: 1rem;
// }
// .vault_vault:last-child {
// border-bottom: none;
// }

View File

@ -1,23 +0,0 @@
@import "../../../vars.scss";
.vaults_vault {
padding: 0.5rem;
margin-top: 0 !important;
// >span {
// font-size: 2rem !important;
// }
// &:not(:last-child) {
// border-bottom: 1px $border_color solid;
// }
>svg {
height: 2rem;
margin-right: 1rem;
}
&:hover {
background: $hover-background;
}
}

View File

@ -5,16 +5,9 @@
* @fileoverview Global |this| required for resolving indexes in node. * @fileoverview Global |this| required for resolving indexes in node.
* @suppress {globalThis} * @suppress {globalThis}
*/ */
(function(global) { (function (global) {
'use strict'; 'use strict';
// If we're in node require encoding-indexes and attach it to the global.
if (typeof module !== "undefined" && module.exports &&
!global["encoding-indexes"]) {
global["encoding-indexes"] =
require("./encoding-indexes.js")["encoding-indexes"];
}
// //
// Utilities // Utilities
// //
@ -202,7 +195,7 @@
/** /**
* @return {boolean} True if end-of-stream has been hit. * @return {boolean} True if end-of-stream has been hit.
*/ */
endOfStream: function() { endOfStream: function () {
return !this.tokens.length; return !this.tokens.length;
}, },
@ -214,7 +207,7 @@
* @return {number} Get the next token from the stream, or * @return {number} Get the next token from the stream, or
* end_of_stream. * end_of_stream.
*/ */
read: function() { read: function () {
if (!this.tokens.length) if (!this.tokens.length)
return end_of_stream; return end_of_stream;
return this.tokens.pop(); return this.tokens.pop();
@ -228,7 +221,7 @@
* @param {(number|!Array.<number>)} token The token(s) to prepend to the * @param {(number|!Array.<number>)} token The token(s) to prepend to the
* stream. * stream.
*/ */
prepend: function(token) { prepend: function (token) {
if (Array.isArray(token)) { if (Array.isArray(token)) {
var tokens = /**@type {!Array.<number>}*/(token); var tokens = /**@type {!Array.<number>}*/(token);
while (tokens.length) while (tokens.length)
@ -246,7 +239,7 @@
* @param {(number|!Array.<number>)} token The tokens(s) to push to the * @param {(number|!Array.<number>)} token The tokens(s) to push to the
* stream. * stream.
*/ */
push: function(token) { push: function (token) {
if (Array.isArray(token)) { if (Array.isArray(token)) {
var tokens = /**@type {!Array.<number>}*/(token); var tokens = /**@type {!Array.<number>}*/(token);
while (tokens.length) while (tokens.length)
@ -286,7 +279,7 @@
} }
/** @interface */ /** @interface */
function Decoder() {} function Decoder() { }
Decoder.prototype = { Decoder.prototype = {
/** /**
* @param {Stream} stream The stream of bytes being decoded. * @param {Stream} stream The stream of bytes being decoded.
@ -295,18 +288,18 @@
* decoded, or null if not enough data exists in the input * decoded, or null if not enough data exists in the input
* stream to decode a complete code point, or |finished|. * stream to decode a complete code point, or |finished|.
*/ */
handler: function(stream, bite) {} handler: function (stream, bite) { }
}; };
/** @interface */ /** @interface */
function Encoder() {} function Encoder() { }
Encoder.prototype = { Encoder.prototype = {
/** /**
* @param {Stream} stream The stream of code points being encoded. * @param {Stream} stream The stream of code points being encoded.
* @param {number} code_point Next code point read from the stream. * @param {number} code_point Next code point read from the stream.
* @return {(number|!Array.<number>)} Byte(s) to emit, or |finished|. * @return {(number|!Array.<number>)} Byte(s) to emit, or |finished|.
*/ */
handler: function(stream, code_point) {} handler: function (stream, code_point) { }
}; };
// 5.2 Names and labels // 5.2 Names and labels
@ -798,9 +791,9 @@
// Label to encoding registry. // Label to encoding registry.
/** @type {Object.<string,{name:string,labels:Array.<string>}>} */ /** @type {Object.<string,{name:string,labels:Array.<string>}>} */
var label_to_encoding = {}; var label_to_encoding = {};
encodings.forEach(function(category) { encodings.forEach(function (category) {
category.encodings.forEach(function(encoding) { category.encodings.forEach(function (encoding) {
encoding.labels.forEach(function(label) { encoding.labels.forEach(function (label) {
label_to_encoding[label] = encoding; label_to_encoding[label] = encoding;
}); });
}); });
@ -929,7 +922,7 @@
// 1. Let index be index jis0208 excluding all entries whose // 1. Let index be index jis0208 excluding all entries whose
// pointer is in the range 8272 to 8835, inclusive. // pointer is in the range 8272 to 8835, inclusive.
shift_jis_index = shift_jis_index || shift_jis_index = shift_jis_index ||
index('jis0208').map(function(code_point, pointer) { index('jis0208').map(function (code_point, pointer) {
return inRange(pointer, 8272, 8835) ? null : code_point; return inRange(pointer, 8272, 8835) ? null : code_point;
}); });
var index_ = shift_jis_index; var index_ = shift_jis_index;
@ -948,7 +941,7 @@
function indexBig5PointerFor(code_point) { function indexBig5PointerFor(code_point) {
// 1. Let index be index Big5 excluding all entries whose pointer // 1. Let index be index Big5 excluding all entries whose pointer
big5_index_no_hkscs = big5_index_no_hkscs || big5_index_no_hkscs = big5_index_no_hkscs ||
index('big5').map(function(code_point, pointer) { index('big5').map(function (code_point, pointer) {
return (pointer < (0xA1 - 0x81) * 157) ? null : code_point; return (pointer < (0xA1 - 0x81) * 157) ? null : code_point;
}); });
var index_ = big5_index_no_hkscs; var index_ = big5_index_no_hkscs;
@ -1050,21 +1043,21 @@
// The encoding attribute's getter must return encoding's name. // The encoding attribute's getter must return encoding's name.
Object.defineProperty(TextDecoder.prototype, 'encoding', { Object.defineProperty(TextDecoder.prototype, 'encoding', {
/** @this {TextDecoder} */ /** @this {TextDecoder} */
get: function() { return this._encoding.name.toLowerCase(); } get: function () { return this._encoding.name.toLowerCase(); }
}); });
// The fatal attribute's getter must return true if error mode // The fatal attribute's getter must return true if error mode
// is fatal, and false otherwise. // is fatal, and false otherwise.
Object.defineProperty(TextDecoder.prototype, 'fatal', { Object.defineProperty(TextDecoder.prototype, 'fatal', {
/** @this {TextDecoder} */ /** @this {TextDecoder} */
get: function() { return this._error_mode === 'fatal'; } get: function () { return this._error_mode === 'fatal'; }
}); });
// The ignoreBOM attribute's getter must return true if ignore // The ignoreBOM attribute's getter must return true if ignore
// BOM flag is set, and false otherwise. // BOM flag is set, and false otherwise.
Object.defineProperty(TextDecoder.prototype, 'ignoreBOM', { Object.defineProperty(TextDecoder.prototype, 'ignoreBOM', {
/** @this {TextDecoder} */ /** @this {TextDecoder} */
get: function() { return this._ignoreBOM; } get: function () { return this._ignoreBOM; }
}); });
} }
@ -1093,7 +1086,8 @@
// BOM seen flag. // BOM seen flag.
if (!this._do_not_flush) { if (!this._do_not_flush) {
this._decoder = decoders[this._encoding.name]({ this._decoder = decoders[this._encoding.name]({
fatal: this._error_mode === 'fatal'}); fatal: this._error_mode === 'fatal'
});
this._BOMseen = false; this._BOMseen = false;
} }
@ -1259,7 +1253,7 @@
// The encoding attribute's getter must return encoding's name. // The encoding attribute's getter must return encoding's name.
Object.defineProperty(TextEncoder.prototype, 'encoding', { Object.defineProperty(TextEncoder.prototype, 'encoding', {
/** @this {TextEncoder} */ /** @this {TextEncoder} */
get: function() { return this._encoding.name.toLowerCase(); } get: function () { return this._encoding.name.toLowerCase(); }
}); });
} }
@ -1277,7 +1271,8 @@
// the input is a USVString so streaming is not necessary. // the input is a USVString so streaming is not necessary.
if (!this._do_not_flush) if (!this._do_not_flush)
this._encoder = encoders[this._encoding.name]({ this._encoder = encoders[this._encoding.name]({
fatal: this._fatal === 'fatal'}); fatal: this._fatal === 'fatal'
});
this._do_not_flush = Boolean(options['stream']); this._do_not_flush = Boolean(options['stream']);
// 1. Convert input to a stream. // 1. Convert input to a stream.
@ -1356,7 +1351,7 @@
* decoded, or null if not enough data exists in the input * decoded, or null if not enough data exists in the input
* stream to decode a complete code point. * stream to decode a complete code point.
*/ */
this.handler = function(stream, bite) { this.handler = function (stream, bite) {
// 1. If byte is end-of-stream and utf-8 bytes needed is not 0, // 1. If byte is end-of-stream and utf-8 bytes needed is not 0,
// set utf-8 bytes needed to 0 and return error. // set utf-8 bytes needed to 0 and return error.
if (bite === end_of_stream && utf8_bytes_needed !== 0) { if (bite === end_of_stream && utf8_bytes_needed !== 0) {
@ -1484,7 +1479,7 @@
* @param {number} code_point Next code point read from the stream. * @param {number} code_point Next code point read from the stream.
* @return {(number|!Array.<number>)} Byte(s) to emit. * @return {(number|!Array.<number>)} Byte(s) to emit.
*/ */
this.handler = function(stream, code_point) { this.handler = function (stream, code_point) {
// 1. If code point is end-of-stream, return finished. // 1. If code point is end-of-stream, return finished.
if (code_point === end_of_stream) if (code_point === end_of_stream)
return finished; return finished;
@ -1538,11 +1533,11 @@
} }
/** @param {{fatal: boolean}} options */ /** @param {{fatal: boolean}} options */
encoders['UTF-8'] = function(options) { encoders['UTF-8'] = function (options) {
return new UTF8Encoder(options); return new UTF8Encoder(options);
}; };
/** @param {{fatal: boolean}} options */ /** @param {{fatal: boolean}} options */
decoders['UTF-8'] = function(options) { decoders['UTF-8'] = function (options) {
return new UTF8Decoder(options); return new UTF8Decoder(options);
}; };
@ -1566,7 +1561,7 @@
* decoded, or null if not enough data exists in the input * decoded, or null if not enough data exists in the input
* stream to decode a complete code point. * stream to decode a complete code point.
*/ */
this.handler = function(stream, bite) { this.handler = function (stream, bite) {
// 1. If byte is end-of-stream, return finished. // 1. If byte is end-of-stream, return finished.
if (bite === end_of_stream) if (bite === end_of_stream)
return finished; return finished;
@ -1603,7 +1598,7 @@
* @param {number} code_point Next code point read from the stream. * @param {number} code_point Next code point read from the stream.
* @return {(number|!Array.<number>)} Byte(s) to emit. * @return {(number|!Array.<number>)} Byte(s) to emit.
*/ */
this.handler = function(stream, code_point) { this.handler = function (stream, code_point) {
// 1. If code point is end-of-stream, return finished. // 1. If code point is end-of-stream, return finished.
if (code_point === end_of_stream) if (code_point === end_of_stream)
return finished; return finished;
@ -1626,21 +1621,21 @@
}; };
} }
(function() { (function () {
if (!('encoding-indexes' in global)) if (!('encoding-indexes' in global))
return; return;
encodings.forEach(function(category) { encodings.forEach(function (category) {
if (category.heading !== 'Legacy single-byte encodings') if (category.heading !== 'Legacy single-byte encodings')
return; return;
category.encodings.forEach(function(encoding) { category.encodings.forEach(function (encoding) {
var name = encoding.name; var name = encoding.name;
var idx = index(name.toLowerCase()); var idx = index(name.toLowerCase());
/** @param {{fatal: boolean}} options */ /** @param {{fatal: boolean}} options */
decoders[name] = function(options) { decoders[name] = function (options) {
return new SingleByteDecoder(idx, options); return new SingleByteDecoder(idx, options);
}; };
/** @param {{fatal: boolean}} options */ /** @param {{fatal: boolean}} options */
encoders[name] = function(options) { encoders[name] = function (options) {
return new SingleByteEncoder(idx, options); return new SingleByteEncoder(idx, options);
}; };
}); });
@ -1656,14 +1651,14 @@
// 11.1.1 gbk decoder // 11.1.1 gbk decoder
// gbk's decoder is gb18030's decoder. // gbk's decoder is gb18030's decoder.
/** @param {{fatal: boolean}} options */ /** @param {{fatal: boolean}} options */
decoders['GBK'] = function(options) { decoders['GBK'] = function (options) {
return new GB18030Decoder(options); return new GB18030Decoder(options);
}; };
// 11.1.2 gbk encoder // 11.1.2 gbk encoder
// gbk's encoder is gb18030's encoder with its gbk flag set. // gbk's encoder is gb18030's encoder with its gbk flag set.
/** @param {{fatal: boolean}} options */ /** @param {{fatal: boolean}} options */
encoders['GBK'] = function(options) { encoders['GBK'] = function (options) {
return new GB18030Encoder(options, true); return new GB18030Encoder(options, true);
}; };
@ -1689,7 +1684,7 @@
* decoded, or null if not enough data exists in the input * decoded, or null if not enough data exists in the input
* stream to decode a complete code point. * stream to decode a complete code point.
*/ */
this.handler = function(stream, bite) { this.handler = function (stream, bite) {
// 1. If byte is end-of-stream and gb18030 first, gb18030 // 1. If byte is end-of-stream and gb18030 first, gb18030
// second, and gb18030 third are 0x00, return finished. // second, and gb18030 third are 0x00, return finished.
if (bite === end_of_stream && gb18030_first === 0x00 && if (bite === end_of_stream && gb18030_first === 0x00 &&
@ -1841,7 +1836,7 @@
* @param {number} code_point Next code point read from the stream. * @param {number} code_point Next code point read from the stream.
* @return {(number|!Array.<number>)} Byte(s) to emit. * @return {(number|!Array.<number>)} Byte(s) to emit.
*/ */
this.handler = function(stream, code_point) { this.handler = function (stream, code_point) {
// 1. If code point is end-of-stream, return finished. // 1. If code point is end-of-stream, return finished.
if (code_point === end_of_stream) if (code_point === end_of_stream)
return finished; return finished;
@ -1916,11 +1911,11 @@
} }
/** @param {{fatal: boolean}} options */ /** @param {{fatal: boolean}} options */
encoders['gb18030'] = function(options) { encoders['gb18030'] = function (options) {
return new GB18030Encoder(options); return new GB18030Encoder(options);
}; };
/** @param {{fatal: boolean}} options */ /** @param {{fatal: boolean}} options */
decoders['gb18030'] = function(options) { decoders['gb18030'] = function (options) {
return new GB18030Decoder(options); return new GB18030Decoder(options);
}; };
@ -1949,7 +1944,7 @@
* decoded, or null if not enough data exists in the input * decoded, or null if not enough data exists in the input
* stream to decode a complete code point. * stream to decode a complete code point.
*/ */
this.handler = function(stream, bite) { this.handler = function (stream, bite) {
// 1. If byte is end-of-stream and Big5 lead is not 0x00, set // 1. If byte is end-of-stream and Big5 lead is not 0x00, set
// Big5 lead to 0x00 and return error. // Big5 lead to 0x00 and return error.
if (bite === end_of_stream && Big5_lead !== 0x00) { if (bite === end_of_stream && Big5_lead !== 0x00) {
@ -2044,7 +2039,7 @@
* @param {number} code_point Next code point read from the stream. * @param {number} code_point Next code point read from the stream.
* @return {(number|!Array.<number>)} Byte(s) to emit. * @return {(number|!Array.<number>)} Byte(s) to emit.
*/ */
this.handler = function(stream, code_point) { this.handler = function (stream, code_point) {
// 1. If code point is end-of-stream, return finished. // 1. If code point is end-of-stream, return finished.
if (code_point === end_of_stream) if (code_point === end_of_stream)
return finished; return finished;
@ -2081,11 +2076,11 @@
} }
/** @param {{fatal: boolean}} options */ /** @param {{fatal: boolean}} options */
encoders['Big5'] = function(options) { encoders['Big5'] = function (options) {
return new Big5Encoder(options); return new Big5Encoder(options);
}; };
/** @param {{fatal: boolean}} options */ /** @param {{fatal: boolean}} options */
decoders['Big5'] = function(options) { decoders['Big5'] = function (options) {
return new Big5Decoder(options); return new Big5Decoder(options);
}; };
@ -2117,7 +2112,7 @@
* decoded, or null if not enough data exists in the input * decoded, or null if not enough data exists in the input
* stream to decode a complete code point. * stream to decode a complete code point.
*/ */
this.handler = function(stream, bite) { this.handler = function (stream, bite) {
// 1. If byte is end-of-stream and euc-jp lead is not 0x00, set // 1. If byte is end-of-stream and euc-jp lead is not 0x00, set
// euc-jp lead to 0x00, and return error. // euc-jp lead to 0x00, and return error.
if (bite === end_of_stream && eucjp_lead !== 0x00) { if (bite === end_of_stream && eucjp_lead !== 0x00) {
@ -2212,7 +2207,7 @@
* @param {number} code_point Next code point read from the stream. * @param {number} code_point Next code point read from the stream.
* @return {(number|!Array.<number>)} Byte(s) to emit. * @return {(number|!Array.<number>)} Byte(s) to emit.
*/ */
this.handler = function(stream, code_point) { this.handler = function (stream, code_point) {
// 1. If code point is end-of-stream, return finished. // 1. If code point is end-of-stream, return finished.
if (code_point === end_of_stream) if (code_point === end_of_stream)
return finished; return finished;
@ -2260,11 +2255,11 @@
} }
/** @param {{fatal: boolean}} options */ /** @param {{fatal: boolean}} options */
encoders['EUC-JP'] = function(options) { encoders['EUC-JP'] = function (options) {
return new EUCJPEncoder(options); return new EUCJPEncoder(options);
}; };
/** @param {{fatal: boolean}} options */ /** @param {{fatal: boolean}} options */
decoders['EUC-JP'] = function(options) { decoders['EUC-JP'] = function (options) {
return new EUCJPDecoder(options); return new EUCJPDecoder(options);
}; };
@ -2303,7 +2298,7 @@
* decoded, or null if not enough data exists in the input * decoded, or null if not enough data exists in the input
* stream to decode a complete code point. * stream to decode a complete code point.
*/ */
this.handler = function(stream, bite) { this.handler = function (stream, bite) {
// switching on iso-2022-jp decoder state: // switching on iso-2022-jp decoder state:
switch (iso2022jp_decoder_state) { switch (iso2022jp_decoder_state) {
default: default:
@ -2602,7 +2597,7 @@
* @param {number} code_point Next code point read from the stream. * @param {number} code_point Next code point read from the stream.
* @return {(number|!Array.<number>)} Byte(s) to emit. * @return {(number|!Array.<number>)} Byte(s) to emit.
*/ */
this.handler = function(stream, code_point) { this.handler = function (stream, code_point) {
// 1. If code point is end-of-stream and iso-2022-jp encoder // 1. If code point is end-of-stream and iso-2022-jp encoder
// state is not ASCII, prepend code point to stream, set // state is not ASCII, prepend code point to stream, set
// iso-2022-jp encoder state to ASCII, and return three bytes // iso-2022-jp encoder state to ASCII, and return three bytes
@ -2711,11 +2706,11 @@
} }
/** @param {{fatal: boolean}} options */ /** @param {{fatal: boolean}} options */
encoders['ISO-2022-JP'] = function(options) { encoders['ISO-2022-JP'] = function (options) {
return new ISO2022JPEncoder(options); return new ISO2022JPEncoder(options);
}; };
/** @param {{fatal: boolean}} options */ /** @param {{fatal: boolean}} options */
decoders['ISO-2022-JP'] = function(options) { decoders['ISO-2022-JP'] = function (options) {
return new ISO2022JPDecoder(options); return new ISO2022JPDecoder(options);
}; };
@ -2739,7 +2734,7 @@
* decoded, or null if not enough data exists in the input * decoded, or null if not enough data exists in the input
* stream to decode a complete code point. * stream to decode a complete code point.
*/ */
this.handler = function(stream, bite) { this.handler = function (stream, bite) {
// 1. If byte is end-of-stream and Shift_JIS lead is not 0x00, // 1. If byte is end-of-stream and Shift_JIS lead is not 0x00,
// set Shift_JIS lead to 0x00 and return error. // set Shift_JIS lead to 0x00 and return error.
if (bite === end_of_stream && Shift_JIS_lead !== 0x00) { if (bite === end_of_stream && Shift_JIS_lead !== 0x00) {
@ -2833,7 +2828,7 @@
* @param {number} code_point Next code point read from the stream. * @param {number} code_point Next code point read from the stream.
* @return {(number|!Array.<number>)} Byte(s) to emit. * @return {(number|!Array.<number>)} Byte(s) to emit.
*/ */
this.handler = function(stream, code_point) { this.handler = function (stream, code_point) {
// 1. If code point is end-of-stream, return finished. // 1. If code point is end-of-stream, return finished.
if (code_point === end_of_stream) if (code_point === end_of_stream)
return finished; return finished;
@ -2888,11 +2883,11 @@
} }
/** @param {{fatal: boolean}} options */ /** @param {{fatal: boolean}} options */
encoders['Shift_JIS'] = function(options) { encoders['Shift_JIS'] = function (options) {
return new ShiftJISEncoder(options); return new ShiftJISEncoder(options);
}; };
/** @param {{fatal: boolean}} options */ /** @param {{fatal: boolean}} options */
decoders['Shift_JIS'] = function(options) { decoders['Shift_JIS'] = function (options) {
return new ShiftJISDecoder(options); return new ShiftJISDecoder(options);
}; };
@ -2920,7 +2915,7 @@
* decoded, or null if not enough data exists in the input * decoded, or null if not enough data exists in the input
* stream to decode a complete code point. * stream to decode a complete code point.
*/ */
this.handler = function(stream, bite) { this.handler = function (stream, bite) {
// 1. If byte is end-of-stream and euc-kr lead is not 0x00, set // 1. If byte is end-of-stream and euc-kr lead is not 0x00, set
// euc-kr lead to 0x00 and return error. // euc-kr lead to 0x00 and return error.
if (bite === end_of_stream && euckr_lead !== 0) { if (bite === end_of_stream && euckr_lead !== 0) {
@ -2994,7 +2989,7 @@
* @param {number} code_point Next code point read from the stream. * @param {number} code_point Next code point read from the stream.
* @return {(number|!Array.<number>)} Byte(s) to emit. * @return {(number|!Array.<number>)} Byte(s) to emit.
*/ */
this.handler = function(stream, code_point) { this.handler = function (stream, code_point) {
// 1. If code point is end-of-stream, return finished. // 1. If code point is end-of-stream, return finished.
if (code_point === end_of_stream) if (code_point === end_of_stream)
return finished; return finished;
@ -3024,11 +3019,11 @@
} }
/** @param {{fatal: boolean}} options */ /** @param {{fatal: boolean}} options */
encoders['EUC-KR'] = function(options) { encoders['EUC-KR'] = function (options) {
return new EUCKREncoder(options); return new EUCKREncoder(options);
}; };
/** @param {{fatal: boolean}} options */ /** @param {{fatal: boolean}} options */
decoders['EUC-KR'] = function(options) { decoders['EUC-KR'] = function (options) {
return new EUCKRDecoder(options); return new EUCKRDecoder(options);
}; };
@ -3081,7 +3076,7 @@
* decoded, or null if not enough data exists in the input * decoded, or null if not enough data exists in the input
* stream to decode a complete code point. * stream to decode a complete code point.
*/ */
this.handler = function(stream, bite) { this.handler = function (stream, bite) {
// 1. If byte is end-of-stream and either utf-16 lead byte or // 1. If byte is end-of-stream and either utf-16 lead byte or
// utf-16 lead surrogate is not null, set utf-16 lead byte and // utf-16 lead surrogate is not null, set utf-16 lead byte and
// utf-16 lead surrogate to null, and return error. // utf-16 lead surrogate to null, and return error.
@ -3171,7 +3166,7 @@
* @param {number} code_point Next code point read from the stream. * @param {number} code_point Next code point read from the stream.
* @return {(number|!Array.<number>)} Byte(s) to emit. * @return {(number|!Array.<number>)} Byte(s) to emit.
*/ */
this.handler = function(stream, code_point) { this.handler = function (stream, code_point) {
// 1. If code point is end-of-stream, return finished. // 1. If code point is end-of-stream, return finished.
if (code_point === end_of_stream) if (code_point === end_of_stream)
return finished; return finished;
@ -3200,24 +3195,24 @@
// 15.3 utf-16be // 15.3 utf-16be
// 15.3.1 utf-16be decoder // 15.3.1 utf-16be decoder
/** @param {{fatal: boolean}} options */ /** @param {{fatal: boolean}} options */
encoders['UTF-16BE'] = function(options) { encoders['UTF-16BE'] = function (options) {
return new UTF16Encoder(true, options); return new UTF16Encoder(true, options);
}; };
// 15.3.2 utf-16be encoder // 15.3.2 utf-16be encoder
/** @param {{fatal: boolean}} options */ /** @param {{fatal: boolean}} options */
decoders['UTF-16BE'] = function(options) { decoders['UTF-16BE'] = function (options) {
return new UTF16Decoder(true, options); return new UTF16Decoder(true, options);
}; };
// 15.4 utf-16le // 15.4 utf-16le
// 15.4.1 utf-16le decoder // 15.4.1 utf-16le decoder
/** @param {{fatal: boolean}} options */ /** @param {{fatal: boolean}} options */
encoders['UTF-16LE'] = function(options) { encoders['UTF-16LE'] = function (options) {
return new UTF16Encoder(false, options); return new UTF16Encoder(false, options);
}; };
// 15.4.2 utf-16le encoder // 15.4.2 utf-16le encoder
/** @param {{fatal: boolean}} options */ /** @param {{fatal: boolean}} options */
decoders['UTF-16LE'] = function(options) { decoders['UTF-16LE'] = function (options) {
return new UTF16Decoder(false, options); return new UTF16Decoder(false, options);
}; };
@ -3238,7 +3233,7 @@
* decoded, or null if not enough data exists in the input * decoded, or null if not enough data exists in the input
* stream to decode a complete code point. * stream to decode a complete code point.
*/ */
this.handler = function(stream, bite) { this.handler = function (stream, bite) {
// 1. If byte is end-of-stream, return finished. // 1. If byte is end-of-stream, return finished.
if (bite === end_of_stream) if (bite === end_of_stream)
return finished; return finished;
@ -3266,7 +3261,7 @@
* @param {number} code_point Next code point read from the stream. * @param {number} code_point Next code point read from the stream.
* @return {(number|!Array.<number>)} Byte(s) to emit. * @return {(number|!Array.<number>)} Byte(s) to emit.
*/ */
this.handler = function(stream, code_point) { this.handler = function (stream, code_point) {
// 1.If code point is end-of-stream, return finished. // 1.If code point is end-of-stream, return finished.
if (code_point === end_of_stream) if (code_point === end_of_stream)
return finished; return finished;
@ -3287,11 +3282,11 @@
} }
/** @param {{fatal: boolean}} options */ /** @param {{fatal: boolean}} options */
encoders['x-user-defined'] = function(options) { encoders['x-user-defined'] = function (options) {
return new XUserDefinedEncoder(options); return new XUserDefinedEncoder(options);
}; };
/** @param {{fatal: boolean}} options */ /** @param {{fatal: boolean}} options */
decoders['x-user-defined'] = function(options) { decoders['x-user-defined'] = function (options) {
return new XUserDefinedDecoder(options); return new XUserDefinedDecoder(options);
}; };
@ -3308,6 +3303,6 @@
}; };
} }
// For strict environments where `this` inside the global scope // For strict environments where `this` inside the global scope
// is `undefined`, take a pure object instead // is `undefined`, take a pure object instead
}(this || {})); }(this || {}));

View File

@ -1,14 +1,12 @@
import { Lock } from "@hibas123/utils"; import { Lock } from "@hibas123/utils";
import { DB, openDb, Transaction } from "idb"; import { openDB, IDBPDatabase, IDBPTransaction, } from "idb";
export default class IDB { export default class IDB {
initLock = new Lock(); initLock = new Lock();
db: DB; db: IDBPDatabase;
constructor(database: string, private stores: string[]) { constructor(database: string, private stores: string[]) {
let lock = this.initLock.getLock(); this.initLock.getLock().then(async l => {
lock.then(async l => {
let v = localStorage.getItem(database + "_version"); let v = localStorage.getItem(database + "_version");
let version = 0; let version = 0;
if (v) version = Number(v) if (v) version = Number(v)
@ -21,12 +19,15 @@ export default class IDB {
localStorage.setItem(database + "_version", version.toString()); localStorage.setItem(database + "_version", version.toString());
localStorage.setItem(database + "_stores", stores.join(",")); localStorage.setItem(database + "_stores", stores.join(","));
this.db = await openDb(database, version, db => { this.db = await openDB(database, version, {
upgrade: (db) => {
console.log("IndexedDB need update") console.log("IndexedDB need update")
const check = name => (<any>db.objectStoreNames as DOMStringList).contains ? (<any>db.objectStoreNames as DOMStringList).contains(name) : db.objectStoreNames.find(e => e === name);
stores.forEach(store => { stores.forEach(store => {
if (!db.objectStoreNames.contains(store)) if (!check(store))
db.createObjectStore(store); db.createObjectStore(store);
}) })
},
}) })
console.log("Got DATABASE", this.db) console.log("Got DATABASE", this.db)
l.release(); l.release();
@ -48,42 +49,42 @@ export default class IDB {
return { return {
name: name, name: name,
transaction: () => { transaction: () => {
return this.db.transaction(name, "readwrite") return <any>this.db.transaction(name, "readwrite") as IDBPTransaction<unknown, string[]>;
}, },
get: async (key: string, transaction?: Transaction): Promise<T> => { get: async (key: string, transaction?: IDBPTransaction<unknown, string[]>): Promise<T> => {
(await this.initLock.getLock()).release() (await this.initLock.getLock()).release()
return (transaction || this.db.transaction(name)) return (transaction || this.db.transaction(name))
.objectStore(name).get(key); .objectStore(name).get(key);
}, },
getAll: async (transaction?: Transaction): Promise<T[]> => { getAll: async (transaction?: IDBPTransaction<unknown, string[]>): Promise<T[]> => {
(await this.initLock.getLock()).release() (await this.initLock.getLock()).release()
return (transaction || this.db.transaction(name)) return (transaction || this.db.transaction(name))
.objectStore(name).getAll(); .objectStore(name).getAll();
}, },
set: async (key: string, val: T, transaction?: Transaction) => { set: async (key: string, val: T, transaction?: IDBPTransaction<unknown, string[]>) => {
(await this.initLock.getLock()).release() (await this.initLock.getLock()).release()
const tx = (transaction || this.db.transaction(name, "readwrite")); const tx = (transaction || this.db.transaction(name, "readwrite"));
tx.objectStore(name).put(val, key); tx.objectStore(name).put(val, key);
return tx.complete; return tx.done;
}, },
delete: async (key: string, transaction?: Transaction) => { delete: async (key: string, transaction?: IDBPTransaction<unknown, string[]>) => {
(await this.initLock.getLock()).release() (await this.initLock.getLock()).release()
const tx = (transaction || this.db.transaction(name, "readwrite")); const tx = (transaction || this.db.transaction(name, "readwrite"));
tx.objectStore(name).delete(key); tx.objectStore(name).delete(key);
return tx.complete; return tx.done;
}, },
clear: async (transaction?: Transaction) => { clear: async (transaction?: IDBPTransaction<unknown, string[]>) => {
(await this.initLock.getLock()).release() (await this.initLock.getLock()).release()
const tx = (transaction || this.db.transaction(name, "readwrite")); const tx = (transaction || this.db.transaction(name, "readwrite"));
tx.objectStore(name).clear(); tx.objectStore(name).clear();
return tx.complete; return tx.done;
}, },
keys: async (transaction?: Transaction): Promise<string[]> => { keys: async (transaction?: IDBPTransaction<unknown, string[]>): Promise<string[]> => {
(await this.initLock.getLock()).release() (await this.initLock.getLock()).release()
const tx = (transaction || this.db.transaction(name)); const tx = (transaction || this.db.transaction(name));
const keys: string[] = []; const keys: string[] = [];
@ -91,13 +92,15 @@ export default class IDB {
// This would be store.getAllKeys(), but it isn't supported by Edge or Safari. // This would be store.getAllKeys(), but it isn't supported by Edge or Safari.
// openKeyCursor isn't supported by Safari, so we fall back // openKeyCursor isn't supported by Safari, so we fall back
(store.iterateKeyCursor || store.iterateCursor).call(store, (cursor: any) => { store.getAllKeys()
if (!cursor) return;
keys.push(cursor.key);
cursor.continue();
});
return tx.complete.then(() => keys); // (store.iterateKeyCursor || store.iterateCursor).call(store, (cursor: any) => {
// if (!cursor) return;
// keys.push(cursor.key);
// cursor.continue();
// });
return tx.done.then(() => keys);
} }
} }
} }

View File

@ -6,7 +6,7 @@
<meta charset="utf8" /> <meta charset="utf8" />
<meta name="Description" content="Notes app"> <meta name="Description" content="Notes app">
<meta name="viewport" content="width=device-width,initial-scale=1" /> <meta name="viewport" content="width=device-width,initial-scale=1" />
<link rel="manifest" href="/manifest.json"> <link rel="manifest" href="./manifest.json">
<!-- <link rel="shortcut icon" href="/public/icon-72x72.png"> --> <!-- <link rel="shortcut icon" href="/public/icon-72x72.png"> -->
<!-- Add to home screen for Safari on iOS --> <!-- Add to home screen for Safari on iOS -->
@ -15,9 +15,9 @@
<meta name="apple-mobile-web-app-title" content="Secure Notes"> <meta name="apple-mobile-web-app-title" content="Secure Notes">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"> <!-- <link rel="apple-touch-icon" sizes="180x180" href="../public/apple-touch-icon.png"> -->
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#1E88E5"> <!-- <link rel="mask-icon" href="/safari-pinned-tab.svg" color="#1E88E5"> -->
<script src="encoding.js"></script> <script src="./encoding.js"></script>
<meta name="msapplication-TileColor" content="#1E88E5"> <meta name="msapplication-TileColor" content="#1E88E5">
<meta name="theme-color" content="#1E88E5"> <meta name="theme-color" content="#1E88E5">
</head> </head>
@ -45,7 +45,7 @@
console.warn("Disabling Service Worker in debug mode!") console.warn("Disabling Service Worker in debug mode!")
} else { } else {
// Register the ServiceWorker // Register the ServiceWorker
navigator.serviceWorker.register('/serviceworker.js', { navigator.serviceWorker.register('./serviceworker.ts', {
scope: '/' scope: '/'
}).then(function (reg) { }).then(function (reg) {
console.log('Service worker has been registered for scope:' + reg.scope); console.log('Service worker has been registered for scope:' + reg.scope);
@ -56,6 +56,7 @@
} }
} }
</script> </script>
<script src="./index.tsx"></script>
</body> </body>
</html> </html>

View File

@ -1,26 +1,16 @@
@import "./vars.scss"; @import "./vars.scss";
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body { body {
font-family: 'Roboto', sans-serif; // font-family: Verdana, Geneva, sans-serif;
font-size: 18px;
width: 100%;
height: 100%;
overscroll-behavior-y: contain; overscroll-behavior-y: contain;
} }
html { // html {
min-height: 100%; // min-height: 100%;
display: flex; // display: flex;
} // }
$header-margin: .5em; $header-margin: .5em;
$header-icon-size: calc(1.5rem * 1); // $header-icon-size: calc(1.5rem * 1);
// $header-icon-size: 100%; // $header-icon-size: 100%;
header { header {
@ -52,16 +42,21 @@ header {
display: block; display: block;
margin-top: auto; margin-top: auto;
margin-bottom: auto; margin-bottom: auto;
min-width: $header-icon-size; // min-width: $header-icon-size;
>svg { // >svg {
height: $header-icon-size; // height: $header-icon-size;
width: $header-icon-size; // width: $header-icon-size;
} // }
} }
} }
body {
overscroll-behavior-y: contain;
}
.def-shadow { .def-shadow {
box-shadow: 0px 5px 8px 2px rgba(66, 66, 66, 0.53); box-shadow: 0px 5px 8px 2px rgba(66, 66, 66, 0.53);
} }

View File

@ -64,22 +64,31 @@ import { h, render } from 'preact';
import App from './components/App'; import App from './components/App';
import "uikit"; // import "uikit";
import "uikit/dist/css/uikit.css" // import "uikit/dist/css/uikit.css"
import "@hibas123/theme/out/base.css"
// import "@hibas123/theme/out/light.css"
// import "@hibas123/theme/out/dark.css"
import "./index.scss"; import "./index.scss";
import Navigation from './navigation'; import Navigation from './navigation';
import VaultsPage from './components/routes/vaults/Vaults'; import VaultsPage from './Views/Vaults/Vaults';
import { Page } from './page'; import { Page } from './page';
import Notes from "./notes" import Notes from "./notes"
import DemoPage from './components/demo'; import DemoPage from './components/demo';
import VaultPage from './components/routes/vault/Vault'; import VaultPage from './Views/Vault/Vault';
import SharePage from './components/routes/share/Share'; import SharePage from './Views/Share/Share';
import Notifications from './notifications'; import Notifications from './notifications';
import Error404Page from './components/routes/404'; import Error404Page from './Views/404';
import SettingsPage from './Views/Settings/Settings';
window.debug.notes = Notes; window.debug.notes = Notes;
import Theme from "./theme";
console.log("Dark mode:", Theme.active);
(async () => { (async () => {
// Initialize notes provider // Initialize notes provider
if (Notes.loginRequired()) { if (Notes.loginRequired()) {
@ -90,21 +99,30 @@ window.debug.notes = Notes;
let err = await Notes.getToken(code) let err = await Notes.getToken(code)
if (err) { if (err) {
Notifications.sendError("Login failed: " + err) Notifications.sendError("Login failed: " + err)
Notes.login() return Notes.login()
} else { } else {
window.history.replaceState(null, document.title, "/" + window.location.hash); window.history.replaceState(null, document.title, "/" + window.location.hash);
} }
} else { } else {
Notes.login() return Notes.login()
} }
} }
await Notes.start(); await Notes.start();
if (window.navigator.storage && navigator.storage.persist) {
navigator.storage.persisted()
.then(has => has ? true : navigator.storage.persist())
.then(is => {
console.log("Persistant Storage:", is);
})
}
Navigation.default = VaultsPage as typeof Page; Navigation.default = VaultsPage as typeof Page;
Navigation.addPage("/vault", VaultPage as typeof Page) Navigation.addPage("/vault", VaultPage as typeof Page)
Navigation.addPage("/demo", DemoPage as typeof Page) Navigation.addPage("/demo", DemoPage as typeof Page)
Navigation.addPage("/share", SharePage as typeof Page) Navigation.addPage("/share", SharePage as typeof Page)
Navigation.addPage("/settings", SettingsPage as typeof Page)
Navigation.addPage("/404", Error404Page); Navigation.addPage("/404", Error404Page);
const trad = window.location.pathname; const trad = window.location.pathname;
if (trad && trad !== "/" && trad !== "") { if (trad && trad !== "/" && trad !== "") {

View File

@ -1,6 +1,6 @@
import { Observable } from "@hibas123/utils"; import { Observable } from "@hibas123/utils";
import { Page, PageProps } from "./page"; import { Page, PageProps } from "./page";
import { h, VNode } from "preact"; import { h, VNode, JSX } from "preact";
function serializQuery(obj: any) { function serializQuery(obj: any) {
var str = []; var str = [];

View File

@ -1,8 +1,14 @@
import * as config from "../config.json"
import { Lock, Observable } from "@hibas123/utils"
import SecureFile, { IFile } from "@hibas123/secure-file-wrapper"; import SecureFile, { IFile } from "@hibas123/secure-file-wrapper";
import * as b64 from "./helper/base64" import { Lock, Observable } from "@hibas123/utils";
import * as aesjs from "aes-js";
import { IDBPTransaction } from "idb";
import { sha256 } from "js-sha256";
import uuidv4 from "uuid/v4";
import * as config from "../config.json";
import * as b64 from "./helper/base64";
import IDB from "./helper/indexeddb";
import Notifications, { MessageType } from "./notifications";
export class HttpError extends Error { export class HttpError extends Error {
constructor(public status: number, public statusText: string) { constructor(public status: number, public statusText: string) {
@ -32,13 +38,8 @@ export interface ViewNote extends BaseNote {
__value: string; __value: string;
} }
import * as aesjs from "aes-js";
import { sha256 } from "js-sha256"
import clonedeep = require("lodash.clonedeep"); import clonedeep = require("lodash.clonedeep");
import * as uuidv4 from "uuid/v4" import uuid = require("uuid");
import IDB from "./helper/indexeddb";
import { Transaction } from "idb";
import Notifications, { MessageType } from "./notifications";
const Encoder = new TextEncoder(); const Encoder = new TextEncoder();
const Decoder = new TextDecoder(); const Decoder = new TextDecoder();
@ -81,6 +82,7 @@ export interface IVault {
saveNote(note: ViewNote, date?: Date): Promise<void>; saveNote(note: ViewNote, date?: Date): Promise<void>;
getNote(id: string): Promise<ViewNote>; getNote(id: string): Promise<ViewNote>;
deleteNote(id: string): Promise<void>; deleteNote(id: string): Promise<void>;
// type: string; //Defines type of plugin, that is required to handle this vault
} }
const awaitTimeout = (ms: number) => new Promise<void>(resolve => setTimeout(resolve, ms)); const awaitTimeout = (ms: number) => new Promise<void>(resolve => setTimeout(resolve, ms));
@ -420,6 +422,7 @@ class NotesProvider {
} }
public async createVault(name: string, key?: Uint8Array) { public async createVault(name: string, key?: Uint8Array) {
// console.log(uuidv4, uuid);
let vault: DBNote = { let vault: DBNote = {
__value: this.encrypt("__BASELINE__", key), __value: this.encrypt("__BASELINE__", key),
_id: uuidv4(), _id: uuidv4(),
@ -480,7 +483,7 @@ class NotesProvider {
return Decoder.decode(this._decrypt(msg, this.generalEncryption)) return Decoder.decode(this._decrypt(msg, this.generalEncryption))
} }
async addop(note_id: string, type: OpLogType, values: { value: Uint8Array, preview: Uint8Array }, date: Date, transaction?: Transaction) { async addop(note_id: string, type: OpLogType, values: { value: Uint8Array, preview: Uint8Array }, date: Date, transaction?: IDBPTransaction<unknown, string[]>) {
let tx = transaction || this.oplogDB.transaction(); let tx = transaction || this.oplogDB.transaction();
let oplog = await this.oplogDB.get(note_id, tx); let oplog = await this.oplogDB.get(note_id, tx);
if (!oplog) oplog = { logs: [], id: note_id }; if (!oplog) oplog = { logs: [], id: note_id };

View File

@ -27,19 +27,9 @@ self.addEventListener('activate', (event) => {
}); });
self.addEventListener('message', (event) => { self.addEventListener('message', (event) => {
if (event.data === "clear_cache") {
log("Clearing cache"); log("Clearing cache");
caches.delete(CACHE); caches.delete(CACHE);
} event.waitUntil(precache());
if (event.data === "update_index") {
log("Updating index");
event.waitUntil(caches.open(CACHE).then((cache) => {
return cache.addAll(["/", "/index.html"]).then(() => {
event.ports[0].postMessage("reload");
});
}))
}
}); });
var Types; var Types;

54
src/theme.ts Normal file
View File

@ -0,0 +1,54 @@
import { readFileSync } from "fs";
const light = readFileSync("./node_modules/@hibas123/theme/out/light.css", "utf8")
const dark = readFileSync("./node_modules/@hibas123/theme/out/dark.css", "utf8")
export enum ThemeStates {
AUTO,
LIGHT,
DARK
}
let themeConfig: ThemeStates = Number(localStorage.getItem("theme"));
if (Number.isNaN(themeConfig))
themeConfig = ThemeStates.AUTO;
let isDark = false;
let mediaIsDark = false;
if (window.matchMedia) {
const mediaq = matchMedia("(prefers-color-scheme: dark)");
mediaIsDark = mediaq.matches;
mediaq.onchange = ev => {
mediaIsDark = ev.matches;
apply();
}
console.log(mediaq);
}
let styleElm: HTMLStyleElement;
function apply(force?: boolean) {
let shouldDark = themeConfig === ThemeStates.AUTO ? mediaIsDark : themeConfig === ThemeStates.DARK;
if (force || shouldDark !== isDark) {
if (styleElm) styleElm.remove();
styleElm = document.createElement("style");
document.head.appendChild(styleElm);
styleElm.innerHTML = shouldDark ? dark : light;
isDark = shouldDark;
}
}
apply(true);
function change(state: ThemeStates) {
themeConfig = state;
localStorage.setItem("theme", String(themeConfig));
apply();
}
export default {
active: () => themeConfig,
change: (state: ThemeStates) => change(state)
}

17
src/types.d.ts vendored
View File

@ -1,10 +1,15 @@
// declare module "*.svg" {
// const SVG: (props: {
// width?: number | undefined
// height?: number | undefined
// onClick?: (evt: MouseEvent) => void;
// style?: string;
// }) => JSX.Element;
// export default SVG;
// }
declare module "*.svg" { declare module "*.svg" {
const SVG: (props: { const SVG: string;
width?: number | undefined
height?: number | undefined
onClick?: (evt: MouseEvent) => void;
style?: string;
}) => JSX.Element;
export default SVG; export default SVG;
} }

View File

@ -1,21 +1,9 @@
:root { :root {
--primary: #1E88E5; --primary: #1E88E5;
--on-primary: white;
// --mdc-theme-primary: var(--primary); // --mdc-theme-primary: var(--primary);
// --mdc-theme-primary-bg: var(--mdc-theme--primary); // --mdc-theme-primary-bg: var(--mdc-theme--primary);
// --mdc-theme-on-primary: white; // --mdc-theme-on-primary: white;
--error: #ff2f00; --error: #ff2f00;
--border-color: #ababab; --border-color: #ababab;
--default-font-size: 1.05rem;
} }
.uk-button-primary {
background: var(--primary) !important;
color: white;
}
.uk-background-primary {
background: var(--primary) !important;
color: white;
}
$hover-background: #DDDDDD;

View File

@ -13,7 +13,8 @@
"dom", "dom",
"esnext" "esnext"
], ],
"resolveJsonModule": true "resolveJsonModule": true,
"esModuleInterop": true
}, },
"include": [ "include": [
"./src/types.d.ts", "./src/types.d.ts",

View File

@ -1,5 +1,4 @@
const MiniCssExtractPlugin = require("mini-css-extract-plugin"); const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const WorkboxPlugin = require("workbox-webpack-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin') const CopyWebpackPlugin = require('copy-webpack-plugin')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;