diff --git a/mod.ts b/mod.ts
index 0e775f1..1ca76cc 100644
--- a/mod.ts
+++ b/mod.ts
@@ -1,20 +1,24 @@
///
type BasicProperties = {
- [K in keyof T as T[K] extends (string | number | boolean) ? K : never]: T[K]
-}
+ [K in keyof T as T[K] extends string | number | boolean ? K : never]: T[K];
+};
type Child = Node | string | null;
-type SwelOpts =
- Partial> & {
- on: Partial<{
- [Ev in keyof HTMLElementEventMap]:
- (this: HTMLElement, ev: HTMLElementEventMap[Ev]) => any
- }>,
- children: (Node | string)[] | null,
- attributes: Record,
- className: string,
- };
+type SwelOpts = Partial<
+ BasicProperties
+> & {
+ on: Partial<{
+ [Ev in keyof HTMLElementEventMap]: (
+ this: HTMLElement,
+ ev: HTMLElementEventMap[Ev],
+ ) => any;
+ }>;
+ children: (Node | string)[] | null;
+ attributes: Record;
+ className: string;
+ style: Record | null;
+};
interface Swel {
(
@@ -71,10 +75,12 @@ export const swel: Swel = (
} else {
o = opts;
}
+ } else {
+ o = {};
}
let o_ = o!;
if (o_.children) {
- o_.children = o_.children.filter(c => !!c) as any;
+ o_.children = o_.children.filter((c) => !!c) as any;
}
return swel_(tag, o);
@@ -82,11 +88,11 @@ export const swel: Swel = (
const swel_ = (
tag: T,
- opts: Partial> | null
+ opts: Partial> | null,
): HTMLElementTagNameMap[T] => {
const el = document.createElement(tag) as unknown as HTMLElementTagNameMap[T];
if (opts) {
- const { children, on, attributes, ...rest } = opts;
+ const { children, on, attributes, style, ...rest } = opts;
if (children) {
el.append(...children);
@@ -101,6 +107,11 @@ const swel_ = (
el.setAttribute(k, v as unknown as string);
});
}
+ if (style) {
+ Object.entries(style).map(([k, v]) => {
+ Reflect.set(el.style, k, v);
+ });
+ }
Object.assign(el, rest);
}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..c9d7f9b
--- /dev/null
+++ b/package.json
@@ -0,0 +1,9 @@
+{
+ "name": "swel",
+ "version": "0.0.0",
+ "description": "",
+ "author": "",
+ "main": "mod.ts",
+ "module": "mod.ts",
+ "license": "UNLICENSED"
+}
diff --git a/prettier.config.js b/prettier.config.js
new file mode 100644
index 0000000..13a984f
--- /dev/null
+++ b/prettier.config.js
@@ -0,0 +1,11 @@
+module.exports = {
+ printWidth: 80,
+ useTabs: true,
+ semi: true,
+ singleQuote: false,
+ quoteProps: "as-needed",
+ trailingComma: "all",
+ bracketSpacing: true,
+ arrowParens: "always",
+ parser: "typescript",
+};