diff --git a/src/presentation/lib/query.mts b/src/presentation/lib/query.mts deleted file mode 100644 index a8658047..00000000 --- a/src/presentation/lib/query.mts +++ /dev/null @@ -1,11 +0,0 @@ -/*! - * @license - * Copyright (C) 2023 Final Hill LLC - * SPDX-License-Identifier: AGPL-3.0-only - * @see - */ -export const qs = (sel: string, ctx: Element = document.documentElement) => - ctx.querySelector(sel); - -export const qsa = (sel: string, ctx: Element = document.documentElement) => - Array.from(ctx.querySelectorAll(sel)); \ No newline at end of file diff --git a/src/presentation/lib/svg.mts b/src/presentation/lib/svg.mts deleted file mode 100644 index 57ef60ce..00000000 --- a/src/presentation/lib/svg.mts +++ /dev/null @@ -1,67 +0,0 @@ -/*! - * @license - * Copyright (C) 2023 Final Hill LLC - * SPDX-License-Identifier: AGPL-3.0-only - * @see - */ -type SvgAttributes = Partial; - -const create = ( - tagName: T, - objAttribs: SvgAttributes, - children: (SVGElement | string)[] -): SVGElementTagNameMap[T] => { - const element = document.createElementNS('http://www.w3.org/2000/svg', tagName); - - Object.entries(objAttribs).forEach(([attr, value]) => { - if (Object.prototype.hasOwnProperty.call(objAttribs, attr)) - // Ensure that the attribute exists on the element - if (attr in element) - (element as any)[attr] = value; - else - // If the attribute does not exist, set it as a standard attributes - element.setAttribute(attr, value); - }); - - children.forEach(child => { - element.appendChild( - typeof child === 'string' - ? document.createTextNode(child) - : child - ); - }); - - return element; -}; - -type Children = string | SVGElement | (SVGElement | string)[]; - -type ElementMethods = { - [K in keyof SVGElementTagNameMap]: - ((objAttribs: SvgAttributes, children: Children) => SVGElementTagNameMap[K]) - & ((children: Children) => SVGElementTagNameMap[K]) -}; - -const isObjectLiteral = (obj: any) => { - if (obj === null || typeof obj !== 'object') - return false; - - return Object.getPrototypeOf(obj) === Object.prototype; -}; - -export default new Proxy({}, { - get(_, prop: keyof SVGElementTagNameMap) { - return (objAttribs: any, children: any) => { - if (Array.isArray(children)) - return create(prop, objAttribs, children); - else if (children != undefined) - return create(prop, objAttribs, [children]); - else if (Array.isArray(objAttribs)) - return create(prop, {}, objAttribs); - else if (!isObjectLiteral(objAttribs)) - return create(prop, {}, [objAttribs]); - else - return create(prop, objAttribs, []); - }; - }, -}) as ElementMethods; \ No newline at end of file