mirror of
https://github.com/mickael-kerjean/filestash
synced 2025-12-06 08:22:24 +01:00
chore (cleanup): tsc and linter rules
This commit is contained in:
parent
5ed2159ea7
commit
41754ea45d
12 changed files with 51 additions and 49 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import { toHref } from "../lib/skeleton/router.js";
|
||||
import { animate, slideYOut, slideYIn, opacityOut } from "../lib/animate.js";
|
||||
import { forwardURLParams } from "../lib/path.js";
|
||||
import { safe } from "../../lib/dom.js";
|
||||
import { safe } from "../lib/dom.js";
|
||||
import assert from "../lib/assert.js";
|
||||
import { settingsSave } from "../lib/store.js";
|
||||
import { get as getConfig } from "../model/config.js";
|
||||
|
|
|
|||
|
|
@ -79,13 +79,13 @@ export default async function ctrlSidebar(render, nRestart = 0) {
|
|||
ctrlTagPane(createRender(qs($sidebar, `[data-bind="your-tags"]`)));
|
||||
}
|
||||
|
||||
const withResize = (function () {
|
||||
const withResize = (function() {
|
||||
let memory = null;
|
||||
return ($sidebar) => {
|
||||
const $resize = createElement(`<div class="resizer"></div>`);
|
||||
effect(rxjs.fromEvent($resize, "mousedown").pipe(
|
||||
rxjs.mergeMap((e0) => rxjs.fromEvent(document, "mousemove").pipe(
|
||||
rxjs.takeUntil(rxjs.fromEvent(document, "mouseup")),
|
||||
rxjs.takeUntil(rxjs.fromEvent(document, "mouseup")),
|
||||
rxjs.startWith(e0),
|
||||
rxjs.pairwise(),
|
||||
rxjs.map(([prevX, currX]) => currX.clientX - prevX.clientX),
|
||||
|
|
@ -100,7 +100,7 @@ const withResize = (function () {
|
|||
}),
|
||||
));
|
||||
$sidebar.appendChild($resize);
|
||||
}
|
||||
};
|
||||
}());
|
||||
|
||||
async function ctrlNavigationPane(render, { $sidebar, nRestart }) {
|
||||
|
|
|
|||
|
|
@ -242,10 +242,8 @@ export class Wasi {
|
|||
true,
|
||||
);
|
||||
if (fd === 1 || fd === 2) {
|
||||
let msg = fd === 1? "stdout: " : "stderr: ";
|
||||
msg += new TextDecoder().decode(readFS(fd));
|
||||
FS[fd] = {
|
||||
buffer: new Uint8Array(0),
|
||||
buffer: new Uint8Array(readFS(fd)),
|
||||
position: 0,
|
||||
path: FS[fd].path || "",
|
||||
};
|
||||
|
|
@ -300,7 +298,7 @@ export class Wasi {
|
|||
|
||||
const start = (offset_hi >>> 0) * 0x100000000 + (offset_lo >>> 0);
|
||||
const ioVec = new Uint32Array(this.#instance.exports.memory.buffer, iovs, iovs_len * 2);
|
||||
const mem = new Uint8Array(this.#instance.exports.memory.buffer);
|
||||
const mem = new Uint8Array(this.#instance.exports.memory.buffer);
|
||||
|
||||
let total = 0;
|
||||
for (let i = 0; i < iovs_len * 2; i += 2) {
|
||||
|
|
@ -311,7 +309,7 @@ export class Wasi {
|
|||
Math.min(len, file.buffer.length - (start + total)),
|
||||
);
|
||||
if (avail === 0) {
|
||||
console.log(`len=[${len}] buffLength=[${file.buffer.length}] start=[${start}] total=[${total}]`)
|
||||
console.log(`len=[${len}] buffLength=[${file.buffer.length}] start=[${start}] total=[${total}]`);
|
||||
break;
|
||||
}
|
||||
mem.set(
|
||||
|
|
@ -469,19 +467,19 @@ export class Wasi {
|
|||
__syscall_fstat64(fd, buf) {
|
||||
log(` syscall::fstat64 fd=${fd}, buf=${buf}`);
|
||||
const file = FS[fd];
|
||||
if (!file) return -1; // EBADF
|
||||
if (!file) return -1; // EBADF
|
||||
|
||||
const size = file.buffer.byteLength >>> 0; // ≤ 4 GB
|
||||
const size = file.buffer.byteLength >>> 0; // ≤ 4 GB
|
||||
const nowSec = (Date.now() / 1000) | 0;
|
||||
const H32 = new Int32Array(this.#instance.exports.memory.buffer);
|
||||
const H32 = new Int32Array(this.#instance.exports.memory.buffer);
|
||||
|
||||
/* basic fields */
|
||||
H32[ buf >> 2] = 1; /* st_dev */
|
||||
H32[(buf+4) >> 2] = 0o100644; /* st_mode */
|
||||
H32[(buf+8) >> 2] = 1; /* st_nlink */
|
||||
H32[(buf+12) >> 2] = 1000; /* st_uid */
|
||||
H32[(buf+16) >> 2] = 1000; /* st_gid */
|
||||
H32[(buf+20) >> 2] = 0; /* st_rdev */
|
||||
H32[buf >> 2] = 1; /* st_dev */
|
||||
H32[(buf+4) >> 2] = 0o100644; /* st_mode */
|
||||
H32[(buf+8) >> 2] = 1; /* st_nlink */
|
||||
H32[(buf+12) >> 2] = 1000; /* st_uid */
|
||||
H32[(buf+16) >> 2] = 1000; /* st_gid */
|
||||
H32[(buf+20) >> 2] = 0; /* st_rdev */
|
||||
|
||||
H32[((buf + 24) >> 2)] = size & 0xFFFFFFFF;
|
||||
H32[((buf + 28) >> 2)] = Math.floor(size / 4294967296);
|
||||
|
|
@ -490,22 +488,21 @@ export class Wasi {
|
|||
H32[(buf+36) >> 2] = (size + 511) >> 9;
|
||||
|
||||
/* st_size lives at byte 40 in Emscripten’s 32-bit stat64 */
|
||||
H32[(buf+40) >> 2] = size; /* low 32 bits (high word = 0) */
|
||||
H32[(buf+40) >> 2] = size; /* low 32 bits (high word = 0) */
|
||||
H32[(buf+44) >> 2] = 0;
|
||||
|
||||
H32[(buf+32) >> 2] = 4096; /* st_blksize */
|
||||
H32[(buf+32) >> 2] = 4096; /* st_blksize */
|
||||
H32[(buf+36) >> 2] = (size + 511) >> 9; /* st_blocks */
|
||||
|
||||
/* atime / mtime / ctime: seconds, nsec = 0 */
|
||||
for (let off of [48, 56, 64]) {
|
||||
H32[((buf+off) >> 2)] = nowSec;
|
||||
for (const off of [48, 56, 64]) {
|
||||
H32[((buf+off) >> 2)] = nowSec;
|
||||
H32[((buf+off+4) >> 2)] = 0;
|
||||
}
|
||||
|
||||
H32[(buf+72) >> 2] = fd; /* st_ino (low) */
|
||||
H32[(buf+76) >> 2] = 0; /* st_ino (high) */
|
||||
H32[(buf+72) >> 2] = fd; /* st_ino (low) */
|
||||
H32[(buf+76) >> 2] = 0; /* st_ino (high) */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
2
public/assets/lib/dom.d.ts
vendored
2
public/assets/lib/dom.d.ts
vendored
|
|
@ -2,4 +2,4 @@ export function qs($node: HTMLElement | DocumentFragment, selector: string);
|
|||
|
||||
export function qsa($node: HTMLElement | DocumentFragment, selector: string);
|
||||
|
||||
export function safe(str: string): string;
|
||||
export function safe(str: string | null): string;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import { createElement } from "../../lib/skeleton/index.js";
|
||||
import { animate, opacityOut, opacityIn } from "../../lib/animate.js";
|
||||
import assert from "../../lib/assert.js";
|
||||
import { safe } from "../../lib/dom.js";
|
||||
import { forwardURLParams } from "../../lib/path.js";
|
||||
import { get as getConfig } from "../../model/config.js";
|
||||
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ export default async function(render, { acl$, getFilename, getDownloadUrl, mime
|
|||
rxjs.tap((editor) => requestAnimationFrame(() => editor.refresh())),
|
||||
);
|
||||
}),
|
||||
rxjs.mergeMap(async (editor) => {
|
||||
rxjs.mergeMap(async(editor) => {
|
||||
const loader = await loadPlugin(mime);
|
||||
if (loader) new (await loader(IEditor, { mime, $menubar: $dom.menubar(), getFilename, getDownloadUrl }))(editor);
|
||||
return editor;
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ export default function(render, { getFilename, getDownloadUrl, mime, hasMenubar
|
|||
rxjs.tap(() => {
|
||||
const cancel = animate($photo, {
|
||||
onEnter: () => $photo.classList.remove("hidden"),
|
||||
onExit: async () => (await cancel)(),
|
||||
onExit: async() => (await cancel)(),
|
||||
time: 300,
|
||||
easing: "cubic-bezier(.51,.92,.24,1.15)",
|
||||
keyframes: [
|
||||
|
|
@ -84,7 +84,7 @@ export default function(render, { getFilename, getDownloadUrl, mime, hasMenubar
|
|||
{ opacity: 1 },
|
||||
{ opacity: 1, transform: "scale(1)" },
|
||||
],
|
||||
})
|
||||
});
|
||||
}),
|
||||
rxjs.catchError((err) => {
|
||||
if (err.target instanceof HTMLElement && err.type === "error") {
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ function initMobileNavigation({ $img, $navigation }) {
|
|||
active: false,
|
||||
originX: null,
|
||||
originT: null,
|
||||
dist: null,
|
||||
dist: null,
|
||||
};
|
||||
|
||||
effect(rxjs.fromEvent($img, "touchstart", { passive: true }).pipe(rxjs.debounceTime(10), rxjs.tap((event) => {
|
||||
|
|
@ -122,7 +122,7 @@ function initMobileNavigation({ $img, $navigation }) {
|
|||
$img.style.transform = `translateX(${state.dist}px)`;
|
||||
})));
|
||||
|
||||
effect(rxjs.fromEvent($img, "touchend").pipe(rxjs.tap(async (event) => {
|
||||
effect(rxjs.fromEvent($img, "touchend").pipe(rxjs.tap(async(event) => {
|
||||
if (state.active === false) return;
|
||||
state.active = false;
|
||||
|
||||
|
|
@ -148,10 +148,13 @@ function initMobileNavigation({ $img, $navigation }) {
|
|||
}
|
||||
|
||||
$navlink.click();
|
||||
await animate($img, { time: 200, keyframes: [
|
||||
{ transform: `translateX(${state.dist}px)`, opacity: 1 },
|
||||
{ transform: `translateX(${$img.clientWidth*Math.sign(state.dist)}px)`, opacity: 0 },
|
||||
]});
|
||||
await animate($img, {
|
||||
time: 200,
|
||||
keyframes: [
|
||||
{ transform: `translateX(${state.dist}px)`, opacity: 1 },
|
||||
{ transform: `translateX(${$img.clientWidth*Math.sign(state.dist)}px)`, opacity: 0 },
|
||||
]
|
||||
});
|
||||
$img.classList.add("hidden");
|
||||
})));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import rxjs, { effect } from "../../../lib/rx.js";
|
||||
import { qs } from "../../../lib/dom.js";
|
||||
|
||||
export default function ({ $img, $page }) {
|
||||
export default function({ $img, $page }) {
|
||||
const $navigation = qs($page, `[data-bind="component_navigation"]`);
|
||||
|
||||
effect(rxjs.merge(...builder({ $img })).pipe(
|
||||
|
|
@ -12,8 +12,8 @@ export default function ({ $img, $page }) {
|
|||
const next = Math.min(20, Math.max(1, state.scale * (scale ?? 1)));
|
||||
if (next > 1) {
|
||||
const rect = $img.getBoundingClientRect();
|
||||
const ox = (clientX ?? rect.left + rect.width / 2) - rect.left;
|
||||
const oy = (clientY ?? rect.top + rect.height / 2) - rect.top;
|
||||
const ox = (clientX ?? rect.left + rect.width / 2) - rect.left;
|
||||
const oy = (clientY ?? rect.top + rect.height / 2) - rect.top;
|
||||
const f = next / state.scale;
|
||||
state.x += (1 - f) * ox;
|
||||
state.y += (1 - f) * oy;
|
||||
|
|
@ -27,7 +27,7 @@ export default function ({ $img, $page }) {
|
|||
}, { scale: 1, x: 0, y: 0, duration: 0 }),
|
||||
rxjs.tap(({ scale, x, y, duration }) => {
|
||||
$img.style.transition = `transform ${duration}ms ease`;
|
||||
$img.style.transform = `translate(${x}px,${y}px) scale(${scale})`;
|
||||
$img.style.transform = `translate(${x}px,${y}px) scale(${scale})`;
|
||||
if (scale === 1) $navigation.classList.remove("hidden");
|
||||
}),
|
||||
));
|
||||
|
|
@ -47,11 +47,11 @@ function builder({ $img }) {
|
|||
rxjs.fromEvent($img.parentElement, "wheel").pipe(
|
||||
rxjs.tap((e) => e.preventDefault()),
|
||||
rxjs.bufferTime(100),
|
||||
rxjs.filter(events => events.length > 0),
|
||||
rxjs.filter((events) => events.length > 0),
|
||||
rxjs.map((events) => {
|
||||
let out = null;
|
||||
for (let i=0; i<events.length; i++) {
|
||||
const scale = Math.min(Math.exp(-events[i].deltaY / 300), 2)
|
||||
const scale = Math.min(Math.exp(-events[i].deltaY / 300), 2);
|
||||
if (out === null) out = ({ scale, clientX: events[i].clientX, clientY: events[i].clientY });
|
||||
else if (Math.abs(scale) > Math.abs(out.scale)) out = ({ scale, clientX: events[i].clientX, clientY: events[i].clientY });
|
||||
}
|
||||
|
|
@ -99,12 +99,12 @@ function builder({ $img }) {
|
|||
),
|
||||
// grab and drag
|
||||
rxjs.fromEvent($img.parentElement, "mousedown").pipe(
|
||||
rxjs.filter(e => e.target === $img && e.button === 0),
|
||||
rxjs.filter((e) => e.target === $img && e.button === 0),
|
||||
rxjs.switchMap((down) => {
|
||||
let prev = { x: down.clientX, y: down.clientY, t: down.timeStamp };
|
||||
const move$ = rxjs.fromEvent(window, "mousemove").pipe(
|
||||
rxjs.takeUntil(rxjs.fromEvent(window, "mouseup")),
|
||||
rxjs.map(m => {
|
||||
rxjs.map((m) => {
|
||||
const dx = m.clientX - prev.x;
|
||||
const dy = m.clientY - prev.y;
|
||||
const dt = m.timeStamp - prev.t || 1;
|
||||
|
|
@ -138,5 +138,5 @@ function builder({ $img }) {
|
|||
return rxjs.merge(move$, $inertia);
|
||||
}),
|
||||
),
|
||||
]
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createElement, nop } from "../../lib/skeleton/index.js";
|
||||
import { createElement } from "../../lib/skeleton/index.js";
|
||||
import rxjs, { effect } from "../../lib/rx.js";
|
||||
import { qs, qsa, safe } from "../../lib/dom.js";
|
||||
import ajax from "../../lib/ajax.js";
|
||||
|
|
@ -19,7 +19,7 @@ class ITable {
|
|||
getBody() { throw new Error("NOT_IMPLEMENTED"); }
|
||||
}
|
||||
|
||||
export default async function(render, { mime, getDownloadUrl = nop, getFilename = nop, hasMenubar = true, acl$ = rxjs.EMPTY }) {
|
||||
export default async function(render, { mime, getDownloadUrl, getFilename, hasMenubar = true, acl$ = rxjs.EMPTY }) {
|
||||
const $page = createElement(`
|
||||
<div class="component_tableviewer">
|
||||
<component-menubar filename="${safe(getFilename())}" class="${!hasMenubar && "hidden"}"></component-menubar>
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ self.addEventListener("activate", (event) => {
|
|||
})());
|
||||
});
|
||||
|
||||
self.addEventListener("fetch", async (event) => {
|
||||
self.addEventListener("fetch", async(event) => {
|
||||
if (!event.request.url.startsWith(location.origin + "/assets/")) return;
|
||||
|
||||
event.respondWith((async() => {
|
||||
|
|
@ -78,7 +78,7 @@ async function preload({ urls, cache, cleanup }) {
|
|||
cleanup.push(() => evtsrc.close());
|
||||
|
||||
let i = 0;
|
||||
const messageHandler = async (resolve, event, decoder) => {
|
||||
const messageHandler = async(resolve, event, decoder) => {
|
||||
const url = event.lastEventId;
|
||||
let mime = "application/octet-stream";
|
||||
if (url.endsWith(".css")) mime = "text/css";
|
||||
|
|
|
|||
|
|
@ -133,6 +133,9 @@
|
|||
],
|
||||
"accessor-pairs": [
|
||||
"off"
|
||||
],
|
||||
"no-new": [
|
||||
"off"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue