import { HTMLTag, HTMLText, ElementStructure } from "./htmlStructure" import * as pathModule from "path" import * as Helper from "./helper" import * as Leaf from "../../dist/leaf.module" export function getElementTypeStringByTagName(name: string): string { let map = { "a": "HTMLAnchorElement", "audio": "HTMLAudioElement", "body": "HTMLBodyElement", "button": "HTMLButtonElement", "canvas": "HTMLCanvasElement", "content": "HTMLContentElement", "div": "HTMLDivElement", "embeded": "HTMLEmbedElement", "form": "HTMLFormElement", "head": "HTMLHeadElement", "h1": "HTMLHeadingElement", "h2": "HTMLHeadingElement", "h3": "HTMLHeadingElement", "h4": "HTMLHeadingElement", "h5": "HTMLHeadingElement", "h6": "HTMLHeadingElement", "html": "HTMLHtmlElement", "iframe": "HTMLIFrameElement", "img": "HTMLImageElement", "input": "HTMLInputElement", "li": "HTMLLIElement", "label": "HTMLLabelElement", "link": "HTMLLinkElement", "ol": "HTMLOListElement", "object": "HTMLObjectElement", "p": "HTMLParagraphElement", "picture": "HTMLPictureElement", "pre": "HTMLPreElement", "progress": "HTMLProgressElement", "quote": "HTMLQuoteElement", "script": "HTMLScriptElement", "select": "HTMLSelectElement", "span": "HTMLSpanElement", "style": "HTMLStyleElement", "template": "HTMLTemplateElement", "textarea": "HTMLTextAreaElement", "title": "HTMLTitleElement", "ul": "HTMLUListElement", "video": "HTMLVideoElement" } return map[name.toLowerCase()] || "HTMLDivElement" } const EVMap = {} const EVMapReverse = { MouseEvent: ["click", "mouseup", "mousedown", "mousemove", "mouseleave", "mouseenter", "mouseover"], TouchEvent: ["touchstart", "touchend", "touchmove"], KeyboardEvent: ["keydown", "keyup", "keypress"], FocusEvent: ["focus", "blur"], Event: ["change", "submit"] } for (let event in EVMapReverse) { for (let name of EVMapReverse[event]) { EVMap[name] = event } } export function getEventTypeStringByEventName(tagName: string): string { return EVMap[tagName] || "Event" } export function getPossibleEventsByTagName(tagName: string): string[] { let visualEvents = ["click", "mouseup", "mousedown", "mousemove", "mouseleave", "mouseenter", "mouseover", "touchstart", "touchend", "touchmove"] let keyEvents = ["keydown", "keyup", "keypress"] let inputEvent = ["focus", "blur", "change"] let formEvent = ["submit"] let noneVisualTags = ["html", "script", "template", "head"] let withKeyEvents = ["input", "textarea", "body"] let events = visualEvents.slice() if (noneVisualTags.indexOf(tagName) >= 0) { events.length = 0 } if (tagName === "form") { events.push(...formEvent) } if (withKeyEvents.indexOf(tagName) >= 0) { events.push(...withKeyEvents) } return events } export function pathToName(path: string) { let ext = pathModule.extname(path) let base = pathModule.basename(path, ext) return base } export function pathToResourceResolution(path) { let ext = pathModule.extname(path) let dir = pathModule.dirname(path) let base = pathModule.basename(path, ext) let full = pathModule.join(dir, base) full = pathModule.normalize(full) return full.split("/").filter(item => !!item).map(item => Leaf.Util.capitalize(Leaf.Util.slugToCamel(item))).join(".") } export function pathToId(path: string) { let name = pathModule.basename(path) return Leaf.Util.camelToSlug(name) + "-" + Helper.hash(path).slice(0, 6) }