chore: setup linting
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import throttle from "$lib/helpers/throttle";
|
||||
import throttle from '$lib/helpers/throttle';
|
||||
|
||||
type EventMap = Record<string, unknown>;
|
||||
type EventKey<T extends EventMap> = string & keyof T;
|
||||
type EventReceiver<T> = (params: T, stuff?: Record<string, unknown>) => unknown;
|
||||
|
||||
export default class EventEmitter<
|
||||
T extends EventMap = { [key: string]: unknown },
|
||||
T extends EventMap = { [key: string]: unknown }
|
||||
> {
|
||||
index = 0;
|
||||
public eventMap: T = {} as T;
|
||||
@@ -32,11 +32,11 @@ export default class EventEmitter<
|
||||
public on<K extends EventKey<T>>(
|
||||
event: K,
|
||||
cb: EventReceiver<T[K]>,
|
||||
throttleTimer = 0,
|
||||
throttleTimer = 0
|
||||
) {
|
||||
if (throttleTimer > 0) cb = throttle(cb, throttleTimer);
|
||||
const cbs = Object.assign(this.cbs, {
|
||||
[event]: [...(this.cbs[event] || []), cb],
|
||||
[event]: [...(this.cbs[event] || []), cb]
|
||||
});
|
||||
this.cbs = cbs;
|
||||
|
||||
@@ -54,10 +54,10 @@ export default class EventEmitter<
|
||||
*/
|
||||
public once<K extends EventKey<T>>(
|
||||
event: K,
|
||||
cb: EventReceiver<T[K]>,
|
||||
cb: EventReceiver<T[K]>
|
||||
): () => void {
|
||||
const cbsOnce = Object.assign(this.cbsOnce, {
|
||||
[event]: [...(this.cbsOnce[event] || []), cb],
|
||||
[event]: [...(this.cbsOnce[event] || []), cb]
|
||||
});
|
||||
this.cbsOnce = cbsOnce;
|
||||
|
||||
|
||||
@@ -36,7 +36,8 @@ export function createNodePath({
|
||||
aspectRatio = 1
|
||||
} = {}) {
|
||||
return `M0,${cornerTop}
|
||||
${cornerTop
|
||||
${
|
||||
cornerTop
|
||||
? ` V${cornerTop}
|
||||
Q0,0 ${cornerTop * aspectRatio},0
|
||||
H${100 - cornerTop * aspectRatio}
|
||||
@@ -45,40 +46,37 @@ export function createNodePath({
|
||||
: ` V0
|
||||
H100
|
||||
`
|
||||
}
|
||||
}
|
||||
V${y - height / 2}
|
||||
${rightBump
|
||||
${
|
||||
rightBump
|
||||
? ` C${100 - depth},${y - height / 2} ${100 - depth},${y + height / 2} 100,${y + height / 2}`
|
||||
: ` H100`
|
||||
}
|
||||
${cornerBottom
|
||||
}
|
||||
${
|
||||
cornerBottom
|
||||
? ` V${100 - cornerBottom}
|
||||
Q100,100 ${100 - cornerBottom * aspectRatio},100
|
||||
H${cornerBottom * aspectRatio}
|
||||
Q0,100 0,${100 - cornerBottom}
|
||||
`
|
||||
: `${leftBump ? `V100 H0` : `V100`}`
|
||||
}
|
||||
${leftBump
|
||||
? ` V${y + height / 2} C${depth},${y + height / 2} ${depth},${y - height / 2} 0,${y - height / 2}`
|
||||
}
|
||||
${
|
||||
leftBump
|
||||
? ` V${y + height / 2} C${depth},${y + height / 2} ${depth},${y - height / 2} 0,${
|
||||
y - height / 2
|
||||
}`
|
||||
: ` H0`
|
||||
}
|
||||
}
|
||||
Z`.replace(/\s+/g, ' ');
|
||||
}
|
||||
|
||||
export const debounce = (fn: Function, ms = 300) => {
|
||||
let timeoutId: ReturnType<typeof setTimeout>;
|
||||
return function (this: any, ...args: any[]) {
|
||||
clearTimeout(timeoutId);
|
||||
timeoutId = setTimeout(() => fn.apply(this, args), ms);
|
||||
};
|
||||
};
|
||||
|
||||
export const clone: <T>(v: T) => T = 'structedClone' in globalThis
|
||||
? globalThis.structuredClone
|
||||
: (obj) => JSON.parse(JSON.stringify(obj));
|
||||
|
||||
export function withSubComponents<A, B extends Record<string, any>>(
|
||||
export function withSubComponents<A, B extends Record<string, unknown>>(
|
||||
component: A,
|
||||
subcomponents: B
|
||||
): A & B {
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
import { writable, type Writable } from "svelte/store";
|
||||
import { type Writable, writable } from 'svelte/store';
|
||||
|
||||
function isStore(v: unknown): v is Writable<unknown> {
|
||||
return v !== null && typeof v === "object" && "subscribe" in v && "set" in v;
|
||||
return v !== null && typeof v === 'object' && 'subscribe' in v && 'set' in v;
|
||||
}
|
||||
|
||||
const storeIds: Map<string, ReturnType<typeof createLocalStore>> = new Map();
|
||||
|
||||
const HAS_LOCALSTORAGE = "localStorage" in globalThis;
|
||||
const HAS_LOCALSTORAGE = 'localStorage' in globalThis;
|
||||
|
||||
function createLocalStore<T>(key: string, initialValue: T | Writable<T>) {
|
||||
|
||||
let store: Writable<T>;
|
||||
|
||||
if (HAS_LOCALSTORAGE) {
|
||||
@@ -36,18 +35,15 @@ function createLocalStore<T>(key: string, initialValue: T | Writable<T>) {
|
||||
subscribe: store.subscribe,
|
||||
set: store.set,
|
||||
update: store.update
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export default function localStore<T>(key: string, initialValue: T | Writable<T>): Writable<T> {
|
||||
|
||||
if (storeIds.has(key)) return storeIds.get(key) as Writable<T>;
|
||||
|
||||
const store = createLocalStore(key, initialValue)
|
||||
const store = createLocalStore(key, initialValue);
|
||||
|
||||
storeIds.set(key, store);
|
||||
|
||||
return store
|
||||
|
||||
return store;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user