shwimple 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,2 +1,12 @@
1
- # shwimple
2
- shwimple - a simple HTML writer
1
+ # shwimple
2
+
3
+ shwimple - a simple backend HTML writer/renderer
4
+
5
+ ## TODO
6
+
7
+ - ~~Implement `ShwimplePageBuilder`~~
8
+ - ~~Implement `renderPipe` functionality~~
9
+ - Implement `insertBefore`, `insertAfter`, `getParent` functions in `ShwimpleNode`
10
+ - getParent -> always return top level node if already main parent node e.g. <html></html>
11
+ - ~~Move `ShwimpleDocument.createBoilerplateDocument` to semantic HTML~~
12
+ - Add tests
package/dist/index.d.ts CHANGED
@@ -1,13 +1 @@
1
- export declare class Page {
2
- constructor();
3
- html: string;
4
- createEmptyPage: () => this;
5
- withTitle: (title: string) => this;
6
- withStyle: (style: string) => this;
7
- withStyleLink: (style: string) => this;
8
- withHeaderSection: () => this;
9
- withHeaderContent: (content: string) => this;
10
- withContentSection: () => this;
11
- withContent: (content: string) => this;
12
- }
13
- export declare const bootstrapPage: () => Page;
1
+ export { ShwimpleBuildFunction, ShwimplePageBuilder, TryAddFuncResult, ShwimpleDocument, ShwimpleNode, ShwimpleElementNode, ShwimpleHeadNode, ShwimpleBodyNode, } from './src/Shwimple';
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var h=class{constructor(){this.html=""}html;createEmptyPage=()=>(this.html="<html><head></head><body></body></html>",this);withTitle=t=>{if(n(t))return this;let e=this.html.split("<head>");return this.html=`<head>${e[0]}<title>${t}</title>${e[1]}`,this};withStyle=t=>{if(n(t))return this;let e=this.html.split("<head>");return this.html=`<head>${e[0]}<style>${t}</style>${e[1]}`,this};withStyleLink=t=>{if(n(t))return this;let e=this.html.split("<head>");return this.html=`<head>${e[0]}<style>${t}</style>${e[1]}`,this};withHeaderSection=()=>{let t=this.html.split("<body>"),e='<div id="header-section" class="header-section"></div>';return this.html=`${t[0]}<body>${e}${t[1]}`,this};withHeaderContent=t=>{if(n(t))return this;if(this.html.includes("header-section")){let i=this.html.split('<div id="header-section" class="header-section">');this.html=`${i[0]}<div id="header-section" class="header-section">${t}${i[1]}`}return this};withContentSection=()=>{let t='<div id="content-section" class="content-section"></div>';if(this.html.includes("header-section")){let i=this.html.split("</div>");this.html=`${i[0]}</div>${t}${i[1]}`}else{let i=this.html.split("<body>");this.html=`${i[0]}<body>${t}${i[1]}`}return this};withContent=t=>{if(n(t))return this;if(this.html.includes("content-section")){let i=this.html.split('<div id="content-section" class="content-section">');this.html=`${i[0]}<div id="content-section" class="content-section">${t}${i[1]}`}return this}},o=()=>{let s=new h;return s.createEmptyPage().withHeaderSection().withContentSection(),s},n=s=>!s||s.trim()===""||s.trim().length===0;export{h as Page,o as bootstrapPage};
1
+ var w=Object.defineProperty;var g=(n,e,t)=>e in n?w(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var p=(n,e,t)=>(g(n,typeof e!="symbol"?e+"":e,t),t);var u=class{mainNode;headNode;bodyNode;childNodes;constructor(){this.childNodes=[],this.mainNode=new o("html"),this.headNode=new c,this.bodyNode=new m,this.childNodes.push(this.headNode),this.childNodes.push(this.bodyNode)}createElement=(e,t,i)=>new l(e,t,i);querySelectorById=e=>{let t,i=this.childNodes.find(d=>d instanceof l&&d.id===e);return i&&(t=i),t};querySelectorByIndex=e=>{let t;if(e>this.childNodes.length)return t;let i=this.childNodes[e];return i&&(t=i),t};getHead=()=>this.headNode;getBody=()=>this.bodyNode;html="";getHtmlAsString=()=>{if(!!this.mainNode)return this.html=`<${this.mainNode.tag}>`,this.childNodes.forEach(e=>{this.parseChildNodes(e)}),this.html+=`</${this.mainNode.tag}>`,this.html};parseChildNodes=e=>{this.html+=`<${e.tag}>`,e.textContent&&(this.html+=e.textContent),e.children&&e.children.length>0&&e.children.forEach(t=>{this.parseChildNodes(t)}),this.html+=`</${e.tag}>`}},r=u;p(r,"createBoilerplateDocument",e=>{let t=new u,i=new o("title",e),d=new l("div","header-section","header-section"),s=new l("div","content-section","content-section");return t.headNode.appendChild(i),t.bodyNode.appendChild(d),t.bodyNode.appendChild(s),t}),p(r,"createEmptyDocument",()=>new u);var o=class{children;tag;textContent;constructor(e,t){this.tag=e,this.textContent=t}appendChild=e=>{this.children||(this.children=[]),this.children.push(e)};insertBefore=(e,t)=>{};insertAfter=(e,t)=>{};getParent=()=>this},l=class extends o{className;id;constructor(e,t,i,d){super(e,d);this.id=t,this.className=i}};var c=class extends o{constructor(){super("head")}},m=class extends o{constructor(){super("body")}};var a=(...n)=>e=>n.reduce((t,i)=>i(t),e),N=class{page;buildFunctions=[];constructor(e){this.page=r.createBoilerplateDocument(e)}addRenderFunction=e=>(e.id||(e.id="blah"),this.buildFunctions.push(e),e.id);addRenderFunctionAt=(e,t)=>(e.id||(e.id="blah"),this.buildFunctions.splice(t,0,e),e.id);tryAddRenderFunctionBeforeFuncId=(e,t)=>{e.id||(e.id="blah");let i={success:!1,id:e.id},d=this.buildFunctions.findIndex(h=>h.id===t),s=d-1<0?0:d-1;return s&&(this.buildFunctions.splice(s,0,e),i.success=!0),i};tryAddRenderFunctionAfterFuncId=(e,t)=>{e.id||(e.id="blah");let i={success:!1,id:e.id},d=this.buildFunctions.findIndex(S=>S.id===t),s=this.buildFunctions.length-1,h=d+1>s?s:d-1;return h&&(this.buildFunctions.splice(h,0,e),i.success=!0),i};builder=a(...this.buildFunctions);build=()=>this.buildFunctions.length<=0?void 0:a(...this.buildFunctions)(this.page);buildAsString=()=>this.buildFunctions.length<=0?void 0:a(...this.buildFunctions)(this.page).getHtmlAsString()};export{m as ShwimpleBodyNode,r as ShwimpleDocument,l as ShwimpleElementNode,c as ShwimpleHeadNode,o as ShwimpleNode,N as ShwimplePageBuilder};
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/index.ts"],
4
- "sourcesContent": ["export class Page {\r\n constructor() {\r\n this.html = \"\";\r\n }\r\n\r\n html: string;\r\n //renderPipe = (...fns) => (arg) => fns.reduce((value, fn) => fn(value), arg);\r\n createEmptyPage = () => {\r\n this.html = `<html><head></head><body></body></html>`;\r\n return this;\r\n };\r\n withTitle = (title: string) => {\r\n if (isNullOrEmpty(title)) {\r\n return this;\r\n }\r\n const headSection = this.html.split(`<head>`);\r\n this.html = `<head>${headSection[0]}<title>${title}</title>${headSection[1]}`;\r\n\r\n return this;\r\n };\r\n withStyle = (style: string) => {\r\n if (isNullOrEmpty(style)) {\r\n return this;\r\n }\r\n const headSection = this.html.split(`<head>`);\r\n this.html = `<head>${headSection[0]}<style>${style}</style>${headSection[1]}`;\r\n\r\n return this;\r\n };\r\n //TODO: make proper link tag\r\n withStyleLink = (style: string) => {\r\n if (isNullOrEmpty(style)) {\r\n return this;\r\n }\r\n const headSection = this.html.split(`<head>`);\r\n this.html = `<head>${headSection[0]}<style>${style}</style>${headSection[1]}`;\r\n\r\n return this;\r\n };\r\n withHeaderSection = () => {\r\n const innerBody = this.html.split(`<body>`);\r\n const headerSection = `<div id=\"header-section\" class=\"header-section\"></div>`;\r\n this.html = `${innerBody[0]}<body>${headerSection}${innerBody[1]}`;\r\n\r\n return this;\r\n };\r\n withHeaderContent = (content: string) => {\r\n if (isNullOrEmpty(content)) {\r\n return this;\r\n }\r\n\r\n const hasHeaderSection = this.html.includes(\"header-section\");\r\n if (hasHeaderSection) {\r\n const headerSectionSplit = this.html.split(`<div id=\"header-section\" class=\"header-section\">`);\r\n this.html = `${headerSectionSplit[0]}<div id=\"header-section\" class=\"header-section\">${content}${headerSectionSplit[1]}`;\r\n }\r\n\r\n return this;\r\n };\r\n withContentSection = () => {\r\n const contentSection = `<div id=\"content-section\" class=\"content-section\"></div>`;\r\n const hasHeaderSection = this.html.includes(\"header-section\");\r\n if (hasHeaderSection) {\r\n const headerSectionSplit = this.html.split(`</div>`);\r\n this.html = `${headerSectionSplit[0]}</div>${contentSection}${headerSectionSplit[1]}`;\r\n } else {\r\n const innerBody = this.html.split(`<body>`);\r\n this.html = `${innerBody[0]}<body>${contentSection}${innerBody[1]}`;\r\n }\r\n\r\n return this;\r\n };\r\n withContent = (content: string) => {\r\n if (isNullOrEmpty(content)) {\r\n return this;\r\n }\r\n\r\n const hasContentSection = this.html.includes(\"content-section\");\r\n if (hasContentSection) {\r\n const contentSectionSplit = this.html.split(`<div id=\"content-section\" class=\"content-section\">`);\r\n this.html = `${contentSectionSplit[0]}<div id=\"content-section\" class=\"content-section\">${content}${contentSectionSplit[1]}`;\r\n }\r\n\r\n return this;\r\n };\r\n};\r\n\r\nexport const bootstrapPage = () => {\r\n const page = new Page();\r\n page.createEmptyPage().withHeaderSection().withContentSection();\r\n return page;\r\n};\r\n\r\nconst isNullOrEmpty = (value: string) => {\r\n if (!value || value.trim() === \"\" || value.trim().length === 0) {\r\n return true;\r\n }\r\n\r\n return false;\r\n};\r\n"],
5
- "mappings": "AAAO,WAAW,CACd,aAAc,CACV,KAAK,KAAO,GAGhB,KAEA,gBAAkB,IACd,MAAK,KAAO,0CACL,MAEX,UAAY,AAAC,GAAkB,CAC3B,GAAI,EAAc,GACd,MAAO,MAEX,GAAM,GAAc,KAAK,KAAK,MAAM,UACpC,YAAK,KAAO,SAAS,EAAY,YAAY,YAAgB,EAAY,KAElE,MAEX,UAAY,AAAC,GAAkB,CAC3B,GAAI,EAAc,GACd,MAAO,MAEX,GAAM,GAAc,KAAK,KAAK,MAAM,UACpC,YAAK,KAAO,SAAS,EAAY,YAAY,YAAgB,EAAY,KAElE,MAGX,cAAgB,AAAC,GAAkB,CAC/B,GAAI,EAAc,GACd,MAAO,MAEX,GAAM,GAAc,KAAK,KAAK,MAAM,UACpC,YAAK,KAAO,SAAS,EAAY,YAAY,YAAgB,EAAY,KAElE,MAEX,kBAAoB,IAAM,CACtB,GAAM,GAAY,KAAK,KAAK,MAAM,UAC5B,EAAgB,yDACtB,YAAK,KAAO,GAAG,EAAU,WAAW,IAAgB,EAAU,KAEvD,MAEX,kBAAoB,AAAC,GAAoB,CACrC,GAAI,EAAc,GACd,MAAO,MAIX,GADyB,KAAK,KAAK,SAAS,kBACtB,CAClB,GAAM,GAAqB,KAAK,KAAK,MAAM,oDAC3C,KAAK,KAAO,GAAG,EAAmB,qDAAqD,IAAU,EAAmB,KAGxH,MAAO,OAEX,mBAAqB,IAAM,CACvB,GAAM,GAAiB,2DAEvB,GADyB,KAAK,KAAK,SAAS,kBACtB,CAClB,GAAM,GAAqB,KAAK,KAAK,MAAM,UAC3C,KAAK,KAAO,GAAG,EAAmB,WAAW,IAAiB,EAAmB,SAC9E,CACH,GAAM,GAAY,KAAK,KAAK,MAAM,UAClC,KAAK,KAAO,GAAG,EAAU,WAAW,IAAiB,EAAU,KAGnE,MAAO,OAEX,YAAc,AAAC,GAAoB,CAC/B,GAAI,EAAc,GACd,MAAO,MAIX,GAD0B,KAAK,KAAK,SAAS,mBACtB,CACnB,GAAM,GAAsB,KAAK,KAAK,MAAM,sDAC5C,KAAK,KAAO,GAAG,EAAoB,uDAAuD,IAAU,EAAoB,KAG5H,MAAO,QAIF,EAAgB,IAAM,CAC/B,GAAM,GAAO,GAAI,GACjB,SAAK,kBAAkB,oBAAoB,qBACpC,GAGL,EAAgB,AAAC,GACf,CAAC,GAAS,EAAM,SAAW,IAAM,EAAM,OAAO,SAAW",
3
+ "sources": ["../src/ShwimpleDocument.ts", "../src/ShwimplePageBuilder.ts"],
4
+ "sourcesContent": ["export interface IShwimpleDocument {\r\n mainNode: ShwimpleMainNode;\r\n headNode: ShwimpleHeadNode;\r\n bodyNode: ShwimpleBodyNode;\r\n childNodes: ShwimpleNode[];\r\n createElement: (tag: string, id: string, className?: string) => ShwimpleNode;\r\n querySelectorById: (nodeId: string) => ShwimpleNode | undefined;\r\n querySelectorByIndex: (nodeIndex: number) => ShwimpleNode | undefined;\r\n getHead: () => ShwimpleNode;\r\n getBody: () => ShwimpleNode;\r\n getHtmlAsString: () => string | undefined;\r\n}\r\n\r\nexport interface IShwimpleNode {\r\n appendChild: (child: ShwimpleNode) => void;\r\n children?: ShwimpleNode[];\r\n insertBefore: (nodeToInsert: ShwimpleNode, locatorNode: ShwimpleNode) => void;\r\n insertAfter: (nodeToInsert: ShwimpleNode, locatorNode: ShwimpleNode) => void;\r\n getParent: () => ShwimpleNode; // TODO: Always return top level node if already main parent node e.g. <html></html>\r\n tag: string;\r\n textContent?: string;\r\n}\r\n\r\nexport interface IShwimpleElementNode extends IShwimpleNode {\r\n className?: string;\r\n id: string;\r\n}\r\n\r\nexport interface IShwimpleHeadElementNode extends IShwimpleNode {\r\n rel?: string;\r\n typeName?: string;\r\n href?: string;\r\n}\r\n\r\nexport class ShwimpleDocument implements IShwimpleDocument {\r\n mainNode: ShwimpleNode;\r\n headNode: ShwimpleHeadNode;\r\n bodyNode: ShwimpleBodyNode;\r\n childNodes: ShwimpleNode[];\r\n\r\n constructor() {\r\n this.childNodes = [];\r\n this.mainNode = new ShwimpleNode('html');\r\n this.headNode = new ShwimpleHeadNode();\r\n this.bodyNode = new ShwimpleBodyNode();\r\n this.childNodes.push(this.headNode);\r\n this.childNodes.push(this.bodyNode);\r\n }\r\n\r\n static createBoilerplateDocument = (title?: string) => {\r\n const doc = new ShwimpleDocument();\r\n const titleNode = new ShwimpleNode('title', title);\r\n const headerSectionNode = new ShwimpleElementNode('div', 'header-section', 'header-section');\r\n const contentSectionNode = new ShwimpleElementNode('div', 'content-section', 'content-section');\r\n doc.headNode.appendChild(titleNode);\r\n doc.bodyNode.appendChild(headerSectionNode);\r\n doc.bodyNode.appendChild(contentSectionNode);\r\n return doc;\r\n };\r\n static createEmptyDocument = () => {\r\n return new ShwimpleDocument();\r\n };\r\n createElement = (tag: string, id: string, className?: string) => {\r\n return new ShwimpleElementNode(tag, id, className);\r\n };\r\n querySelectorById = (nodeId: string) => {\r\n let result: ShwimpleNode | undefined = undefined;\r\n const node = this.childNodes.find((n) => n instanceof ShwimpleElementNode && n.id === nodeId);\r\n\r\n if (node) {\r\n result = node;\r\n }\r\n\r\n return result;\r\n };\r\n querySelectorByIndex = (nodeIndex: number) => {\r\n let result: ShwimpleNode | undefined = undefined;\r\n\r\n if (nodeIndex > this.childNodes.length) {\r\n return result;\r\n }\r\n\r\n const node = this.childNodes[nodeIndex];\r\n if (node) {\r\n result = node;\r\n }\r\n\r\n return result;\r\n };\r\n getHead = () => this.headNode;\r\n getBody = () => this.bodyNode;\r\n\r\n private html: string = '';\r\n getHtmlAsString = () => {\r\n if (!this.mainNode) {\r\n return undefined;\r\n }\r\n\r\n this.html = `<${this.mainNode.tag}>`;\r\n\r\n this.childNodes.forEach((node) => {\r\n this.parseChildNodes(node);\r\n });\r\n\r\n this.html += `</${this.mainNode.tag}>`;\r\n\r\n return this.html;\r\n };\r\n\r\n private parseChildNodes = (node: ShwimpleNode) => {\r\n this.html += `<${node.tag}>`;\r\n\r\n if (node.textContent) {\r\n this.html += node.textContent;\r\n }\r\n\r\n if (node.children && node.children.length > 0) {\r\n node.children.forEach((child) => {\r\n this.parseChildNodes(child);\r\n });\r\n }\r\n\r\n this.html += `</${node.tag}>`;\r\n };\r\n}\r\n\r\nexport class ShwimpleNode implements IShwimpleNode {\r\n children?: ShwimpleNode[];\r\n tag: string;\r\n textContent?: string;\r\n\r\n constructor(tag: string, textContent?: string) {\r\n this.tag = tag;\r\n this.textContent = textContent;\r\n }\r\n\r\n appendChild = (child: ShwimpleNode) => {\r\n if (!this.children) {\r\n this.children = [];\r\n }\r\n\r\n this.children.push(child);\r\n };\r\n insertBefore = (nodeToInsert: ShwimpleNode, locatorNode: ShwimpleNode) => {};\r\n insertAfter = (nodeToInsert: ShwimpleNode, locatorNode: ShwimpleNode) => {};\r\n getParent = () => {\r\n return this;\r\n };\r\n}\r\n\r\nexport class ShwimpleElementNode extends ShwimpleNode implements IShwimpleElementNode {\r\n className?: string;\r\n id: string;\r\n\r\n constructor(tag: string, id: string, className?: string, textContent?: string) {\r\n super(tag, textContent);\r\n this.id = id;\r\n this.className = className;\r\n }\r\n}\r\n\r\nexport class ShwimpleHeadElementNode extends ShwimpleNode implements IShwimpleHeadElementNode {\r\n rel?: string;\r\n typeName?: string;\r\n href?: string;\r\n\r\n constructor(rel?: string, typeName?: string, href?: string, textContent?: string) {\r\n super('head', textContent);\r\n this.rel = rel;\r\n this.typeName = typeName;\r\n this.href = href;\r\n }\r\n}\r\n\r\nexport class ShwimpleMainNode extends ShwimpleNode implements IShwimpleNode {\r\n constructor() {\r\n super('html');\r\n }\r\n}\r\n\r\nexport class ShwimpleHeadNode extends ShwimpleNode implements IShwimpleNode {\r\n constructor() {\r\n super('head');\r\n }\r\n}\r\n\r\nexport class ShwimpleBodyNode extends ShwimpleNode implements IShwimpleNode {\r\n constructor() {\r\n super('body');\r\n }\r\n}\r\n", "import { ShwimpleDocument } from './ShwimpleDocument';\r\n\r\nexport type ShwimpleBuildFunction = {\r\n id?: string;\r\n (value: ShwimpleDocument): ShwimpleDocument;\r\n};\r\n\r\nexport type TryAddFuncResult = {\r\n success: boolean;\r\n id: string;\r\n};\r\n\r\nconst buildPipe =\r\n (...fns: ShwimpleBuildFunction[]) =>\r\n (arg: ShwimpleDocument) =>\r\n fns.reduce((value, fn) => fn(value), arg);\r\n\r\nexport class ShwimplePageBuilder {\r\n page: ShwimpleDocument;\r\n buildFunctions: ShwimpleBuildFunction[] = [];\r\n\r\n constructor(title?: string) {\r\n this.page = ShwimpleDocument.createBoilerplateDocument(title);\r\n }\r\n\r\n addRenderFunction = (func: ShwimpleBuildFunction) => {\r\n // TODO: This check can probably be refactored somehow\r\n if (!func.id) {\r\n func.id = 'blah'; // TODO: implement proper uuid generation\r\n }\r\n\r\n this.buildFunctions.push(func);\r\n return func.id;\r\n };\r\n addRenderFunctionAt = (func: ShwimpleBuildFunction, index: number) => {\r\n if (!func.id) {\r\n func.id = 'blah'; // TODO: implement proper uuid generation\r\n }\r\n\r\n this.buildFunctions.splice(index, 0, func);\r\n return func.id;\r\n };\r\n tryAddRenderFunctionBeforeFuncId = (func: ShwimpleBuildFunction, locatorId: string) => {\r\n if (!func.id) {\r\n func.id = 'blah'; // TODO: implement proper uuid generation\r\n }\r\n\r\n const result: TryAddFuncResult = { success: false, id: func.id };\r\n\r\n const funcLocation = this.buildFunctions.findIndex((bf) => bf.id === locatorId);\r\n const index = funcLocation - 1 < 0 ? 0 : funcLocation - 1;\r\n if (index) {\r\n this.buildFunctions.splice(index, 0, func);\r\n result.success = true;\r\n }\r\n\r\n return result;\r\n };\r\n tryAddRenderFunctionAfterFuncId = (func: ShwimpleBuildFunction, locatorId: string) => {\r\n if (!func.id) {\r\n func.id = 'blah'; // TODO: implement proper uuid generation\r\n }\r\n\r\n const result: TryAddFuncResult = { success: false, id: func.id };\r\n\r\n const funcLocation = this.buildFunctions.findIndex((bf) => bf.id === locatorId);\r\n const currentLastIndex = this.buildFunctions.length - 1;\r\n const index = funcLocation + 1 > currentLastIndex ? currentLastIndex : funcLocation - 1;\r\n if (index) {\r\n this.buildFunctions.splice(index, 0, func);\r\n result.success = true;\r\n }\r\n\r\n return result;\r\n };\r\n private builder = buildPipe(...this.buildFunctions);\r\n build = () => {\r\n if (this.buildFunctions.length <= 0) {\r\n return undefined;\r\n }\r\n\r\n const builder = buildPipe(...this.buildFunctions);\r\n\r\n return builder(this.page);\r\n };\r\n buildAsString = () => {\r\n if (this.buildFunctions.length <= 0) {\r\n return undefined;\r\n }\r\n\r\n const builder = buildPipe(...this.buildFunctions);\r\n\r\n const builtPage = builder(this.page);\r\n return builtPage.getHtmlAsString();\r\n };\r\n}\r\n"],
5
+ "mappings": "wKAkCO,WAAoD,CACvD,SACA,SACA,SACA,WAEA,aAAc,CACV,KAAK,WAAa,GAClB,KAAK,SAAW,GAAI,GAAa,QACjC,KAAK,SAAW,GAAI,GACpB,KAAK,SAAW,GAAI,GACpB,KAAK,WAAW,KAAK,KAAK,UAC1B,KAAK,WAAW,KAAK,KAAK,UAgB9B,cAAgB,CAAC,E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AQ,EAAe,EAAI,EAAmB,EAAmB,EAAe,EACtF,MAAI,IACA,MAAK,eAAe,OAAO,EAAO,EAAG,GACrC,EAAO,QAAU,IAGd,GAEH,QAAU,EAAU,GAAG,KAAK,gBACpC,MAAQ,IACA,KAAK,eAAe,QAAU,EAC9B,OAKG,AAFS,EAAU,GAAG,KAAK,gBAEnB,KAAK,MAExB,cAAgB,IACR,KAAK,eAAe,QAAU,EAC9B,OAMG,AADW,AAFF,EAAU,GAAG,KAAK,gBAER,KAAK,MACd",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,3 @@
1
+ import { ShwimpleBuildFunction, ShwimplePageBuilder, TryAddFuncResult } from './ShwimplePageBuilder';
2
+ import { ShwimpleDocument, ShwimpleNode, ShwimpleElementNode, ShwimpleHeadNode, ShwimpleBodyNode } from './ShwimpleDocument';
3
+ export { ShwimpleBuildFunction, ShwimplePageBuilder, TryAddFuncResult, ShwimpleDocument, ShwimpleNode, ShwimpleElementNode, ShwimpleHeadNode, ShwimpleBodyNode, };
@@ -0,0 +1,77 @@
1
+ export interface IShwimpleDocument {
2
+ mainNode: ShwimpleMainNode;
3
+ headNode: ShwimpleHeadNode;
4
+ bodyNode: ShwimpleBodyNode;
5
+ childNodes: ShwimpleNode[];
6
+ createElement: (tag: string, id: string, className?: string) => ShwimpleNode;
7
+ querySelectorById: (nodeId: string) => ShwimpleNode | undefined;
8
+ querySelectorByIndex: (nodeIndex: number) => ShwimpleNode | undefined;
9
+ getHead: () => ShwimpleNode;
10
+ getBody: () => ShwimpleNode;
11
+ getHtmlAsString: () => string | undefined;
12
+ }
13
+ export interface IShwimpleNode {
14
+ appendChild: (child: ShwimpleNode) => void;
15
+ children?: ShwimpleNode[];
16
+ insertBefore: (nodeToInsert: ShwimpleNode, locatorNode: ShwimpleNode) => void;
17
+ insertAfter: (nodeToInsert: ShwimpleNode, locatorNode: ShwimpleNode) => void;
18
+ getParent: () => ShwimpleNode;
19
+ tag: string;
20
+ textContent?: string;
21
+ }
22
+ export interface IShwimpleElementNode extends IShwimpleNode {
23
+ className?: string;
24
+ id: string;
25
+ }
26
+ export interface IShwimpleHeadElementNode extends IShwimpleNode {
27
+ rel?: string;
28
+ typeName?: string;
29
+ href?: string;
30
+ }
31
+ export declare class ShwimpleDocument implements IShwimpleDocument {
32
+ mainNode: ShwimpleNode;
33
+ headNode: ShwimpleHeadNode;
34
+ bodyNode: ShwimpleBodyNode;
35
+ childNodes: ShwimpleNode[];
36
+ constructor();
37
+ static createBoilerplateDocument: (title?: string | undefined) => ShwimpleDocument;
38
+ static createEmptyDocument: () => ShwimpleDocument;
39
+ createElement: (tag: string, id: string, className?: string | undefined) => ShwimpleElementNode;
40
+ querySelectorById: (nodeId: string) => ShwimpleNode | undefined;
41
+ querySelectorByIndex: (nodeIndex: number) => ShwimpleNode | undefined;
42
+ getHead: () => ShwimpleHeadNode;
43
+ getBody: () => ShwimpleBodyNode;
44
+ private html;
45
+ getHtmlAsString: () => string | undefined;
46
+ private parseChildNodes;
47
+ }
48
+ export declare class ShwimpleNode implements IShwimpleNode {
49
+ children?: ShwimpleNode[];
50
+ tag: string;
51
+ textContent?: string;
52
+ constructor(tag: string, textContent?: string);
53
+ appendChild: (child: ShwimpleNode) => void;
54
+ insertBefore: (nodeToInsert: ShwimpleNode, locatorNode: ShwimpleNode) => void;
55
+ insertAfter: (nodeToInsert: ShwimpleNode, locatorNode: ShwimpleNode) => void;
56
+ getParent: () => this;
57
+ }
58
+ export declare class ShwimpleElementNode extends ShwimpleNode implements IShwimpleElementNode {
59
+ className?: string;
60
+ id: string;
61
+ constructor(tag: string, id: string, className?: string, textContent?: string);
62
+ }
63
+ export declare class ShwimpleHeadElementNode extends ShwimpleNode implements IShwimpleHeadElementNode {
64
+ rel?: string;
65
+ typeName?: string;
66
+ href?: string;
67
+ constructor(rel?: string, typeName?: string, href?: string, textContent?: string);
68
+ }
69
+ export declare class ShwimpleMainNode extends ShwimpleNode implements IShwimpleNode {
70
+ constructor();
71
+ }
72
+ export declare class ShwimpleHeadNode extends ShwimpleNode implements IShwimpleNode {
73
+ constructor();
74
+ }
75
+ export declare class ShwimpleBodyNode extends ShwimpleNode implements IShwimpleNode {
76
+ constructor();
77
+ }
@@ -0,0 +1,21 @@
1
+ import { ShwimpleDocument } from './ShwimpleDocument';
2
+ export declare type ShwimpleBuildFunction = {
3
+ id?: string;
4
+ (value: ShwimpleDocument): ShwimpleDocument;
5
+ };
6
+ export declare type TryAddFuncResult = {
7
+ success: boolean;
8
+ id: string;
9
+ };
10
+ export declare class ShwimplePageBuilder {
11
+ page: ShwimpleDocument;
12
+ buildFunctions: ShwimpleBuildFunction[];
13
+ constructor(title?: string);
14
+ addRenderFunction: (func: ShwimpleBuildFunction) => string;
15
+ addRenderFunctionAt: (func: ShwimpleBuildFunction, index: number) => string;
16
+ tryAddRenderFunctionBeforeFuncId: (func: ShwimpleBuildFunction, locatorId: string) => TryAddFuncResult;
17
+ tryAddRenderFunctionAfterFuncId: (func: ShwimpleBuildFunction, locatorId: string) => TryAddFuncResult;
18
+ private builder;
19
+ build: () => ShwimpleDocument | undefined;
20
+ buildAsString: () => string | undefined;
21
+ }
@@ -0,0 +1 @@
1
+ export declare const isNullOrEmpty: (value: string) => boolean;
package/index.ts ADDED
@@ -0,0 +1,10 @@
1
+ export {
2
+ ShwimpleBuildFunction,
3
+ ShwimplePageBuilder,
4
+ TryAddFuncResult,
5
+ ShwimpleDocument,
6
+ ShwimpleNode,
7
+ ShwimpleElementNode,
8
+ ShwimpleHeadNode,
9
+ ShwimpleBodyNode,
10
+ } from './src/Shwimple';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shwimple",
3
- "version": "2.0.0",
3
+ "version": "3.0.0",
4
4
  "description": "shwimple - a simple HTML writer",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -18,7 +18,8 @@
18
18
  "shwimple",
19
19
  "wooffet",
20
20
  "html",
21
- "writer"
21
+ "writer",
22
+ "renderer"
22
23
  ],
23
24
  "author": "wooffet",
24
25
  "license": "MIT",
@@ -34,4 +35,4 @@
34
35
  "engines": {
35
36
  "node": ">=14.17.0 || >=16.0.0"
36
37
  }
37
- }
38
+ }