UNPKG

ucbuilder

Version:

:Shree Ganeshay Namah: new way app design

154 lines 4.32 kB
import { codeFileInfo } from "../build/codeFileInfo.js"; import { nodeFn } from "../renderer/nodeFn.js"; const VOID_HTML_NODE_NAMES = [ 'AREA', 'BASE', 'BR', 'COL', 'EMBED', 'HR', 'IMG', 'INPUT', 'LINK', 'META', 'PARAM', 'SOURCE', 'TRACK', 'WBR' ]; const VOID_SVG_ELEMENTS = [ "CIRCLE", "ELLIPSE", "LINE", "RECT", "USE", "IMAGE", "PATH", "STOP", "FEGAUSSIANBLUR", "FEOFFSET", "FEBLEND", "FECOLORMATRIX", "FECOMPONENTTRANSFER", "FECOMPOSITE", "FECONVOLVEMATRIX", "FEDIFFUSELIGHTING", "FEDISPLACEMENTMAP", "FEFLOOD", "FEFUNCA", "FEFUNCB", "FEFUNCG", "FEFUNCR", "FEMERGENODE", "FEMORPHOLOGY", "FESPECULARLIGHTING", "FETILE", "FETURBULENCE", "ANIMATE", "ANIMATETRANSFORM", "ANIMATEMOTION", "MPATH", "SET" ]; const NON_VOID_SVG_ELEMENTS = [ "SVG", "G", "DEFS", "SYMBOL", "MASK", "PATTERN", "MARKER", "TEXT", "TSPAN", "TEXTPATH", "A", "SWITCH", "CLIPPATH", "LINEARGRADIENT", "RADIALGRADIENT", "FILTER", "FOREIGNOBJECT", "DESC", "METADATA", "TITLE" ]; ; export class HTMLx { static Design = (pera) => { return pera; }; static htmlSource; /** out dynamic js file path */ static dynamicFilePath; static Tag = (tagName, prefDefinedProps, ...childs) => { tagName = tagName ?? 'div'; tagName = tagName.toUpperCase(); let htCode = `<${tagName} `; childs = childs ?? []; if (prefDefinedProps != undefined) { if (prefDefinedProps["<childs>"] != undefined) { //childs = childs ?? []; childs.unshift(...prefDefinedProps["<childs>"]); delete prefDefinedProps['<childs>']; } for (let [key, value] of Object.entries(prefDefinedProps)) htCode += ` ${key}="${value}"`; } if (VOID_HTML_NODE_NAMES.includes(tagName)) { // if none closable element htCode += ' />'; if (childs.length > 0) { console.error(`at WrapperHelper.Tag(); NONE CLOSABLE ELEMENT CANT HAVE CHILDREN.`); } } else { htCode += ` >`; childs?.forEach(s => htCode += s); htCode += `</${tagName}>`; } return htCode; }; static Wrapper = (wrapperProps, ...childs) => { return HTMLx.Tag('wrapper', wrapperProps, ...childs); }; static Template = (templates) => { let cntnt = []; for (const [id, template] of Object.entries(templates)) { cntnt.push(this.Wrapper([Object.assign({ id: id }, template)])); } return HTMLx.Tag('x:template', { "<childs>": cntnt }); }; static Usercontrol = (name, targetUc, outDynamicJsPath, ucProps, ...childs) => { let relpath; const targetCinfo = new codeFileInfo(); // debugger; targetCinfo.parseUrl(nodeFn.url.fileURLToPath(targetUc.dynamicFilePath), undefined, undefined); // DESIGNER OUT const outDynamicCinfo = new codeFileInfo(); outDynamicCinfo.parseUrl(nodeFn.url.fileURLToPath(outDynamicJsPath), undefined, undefined); // DESIGNER OUT const pref = targetCinfo.projectInfo?.config?.preference; if (targetCinfo.pathOf != undefined) { relpath = nodeFn.path.relativeFilePath(outDynamicCinfo.pathOf.html, targetCinfo.pathOf.html); ucProps = ucProps ?? {}; if (name != undefined) ucProps["x-name"] = name; ucProps["x-from"] = `{:${relpath}}`; return HTMLx.Tag(targetCinfo.name, ucProps, ...childs); } return undefined; //console.log(['Absolute', obj['AbsolutePath']]); // relpath = nodeFn.path.relativeFilePath(htmlFilePath, targetUc['AbsolutePath']); //console.log(relpath); }; } export async function DynamicToHtml(fpath) { try { return await (await import(fpath))?.default; } catch (e) { //console.warn('at WrapperHelper > DynamicToHtml \n ERROR IN :' + fpath); return undefined; } } //# sourceMappingURL=WrapperHelper.js.map