aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorJoris2022-06-11 16:42:33 +0200
committerJoris2022-06-11 16:42:33 +0200
commit03197b1ab992540b951fcbc6f841cfcd42a757f3 (patch)
tree2eb5277462b8dfef41e901a945f251725fb7ad8f /src/lib
parent70c672535f36edaeaf1d63d4637830b564271c34 (diff)
Add kick sequencer
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/h.ts34
-rw-r--r--src/lib/time.ts8
2 files changed, 42 insertions, 0 deletions
diff --git a/src/lib/h.ts b/src/lib/h.ts
new file mode 100644
index 0000000..8b1abf3
--- /dev/null
+++ b/src/lib/h.ts
@@ -0,0 +1,34 @@
+type Child = Element | Text | string | number
+
+export default function h(
+ tagName: string,
+ attrs: object,
+ ...children: Child[]
+): Element {
+ const isSvg = tagName === 'svg' || tagName === 'path'
+
+ let elem = isSvg
+ ? document.createElementNS('http://www.w3.org/2000/svg', tagName)
+ : document.createElement(tagName)
+
+ if (isSvg) {
+ Object.entries(attrs).forEach(([key, value]) => {
+ elem.setAttribute(key, value)
+ })
+ } else {
+ elem = Object.assign(elem, attrs)
+ }
+
+ for (const child of children) {
+ if (typeof child === 'number')
+ elem.append(child.toString())
+ else
+ elem.append(child)
+ }
+
+ return elem
+}
+
+export function classNames(obj: {[key: string]: boolean }): string {
+ return Object.keys(obj).filter(k => obj[k]).join(' ')
+}
diff --git a/src/lib/time.ts b/src/lib/time.ts
new file mode 100644
index 0000000..d85e935
--- /dev/null
+++ b/src/lib/time.ts
@@ -0,0 +1,8 @@
+export function debounce<A extends any[]>(f: (...args: A) => void, timeout: number): (...args: A) => void {
+ let interval: number | undefined = undefined
+
+ return (...args: A) => {
+ clearTimeout(interval)
+ interval = setTimeout(() => f.apply(this, args), timeout)
+ }
+}