first commit

This commit is contained in:
douboer@gmail.com
2026-03-03 13:23:14 +08:00
commit 3b7c1d558a
161 changed files with 28120 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
import { isArray, isObject } from "../helpers";
import type { IElementProps } from "./interface";
export const NEWLINE = "\n";
export const SPACE = " ";
/**
* CSS class names
*/
export const THEME = {
CONTAINER: "xt",
INACTIVE: "xt-inactive",
CURSOR: "xt-cursor",
OUTPUT: "xt-stdout",
INPUT: "xt-stdin"
};
export function scrollDown(el: HTMLElement): void {
if (el) el.scrollTo(0, el.scrollHeight);
}
/**
* Create a ready to use HTMLElement
*
* https://github.com/henryhale/render-functions
*
* https://vuejs.org/guide/extras/render-function.html
*
* @param tag The HTML element tag
* @param options The some properties of the element
* @returns The HTML Element
*/
export function h<T extends HTMLElement>(
tag: string,
options?: IElementProps
): T {
const elem = document.createElement(tag);
if (!isObject(options)) {
return elem as T;
}
if (options?.id) {
elem.id = options.id || "";
}
if (options?.class) {
elem.className = options.class || "";
}
if (options?.content) {
elem.appendChild(document.createTextNode(options.content || ""));
}
if (options?.html) {
elem.innerHTML = options.html;
}
if (isArray(options?.children)) {
options.children.forEach((c) => elem.append(c));
}
if (isObject(options?.props)) {
Object.entries(options.props).forEach((v) =>
elem.setAttribute(v[0], v[1])
);
}
return elem as T;
}