vaderjs 1.3.1 → 1.3.2

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/worker-min.js CHANGED
@@ -1 +1 @@
1
- onmessage=e=>{let a=Date.now(),l=e.data.strings,s=e.data.args,t="",r=e.data.location.split("/").slice(0,-1).join("/"),c="";for(let e=0;e<l.length;e++)c+=l[e],e<s.length&&(c+=s[e]);let o=c.match(/--([^>]*)--/gs);if(o)for(;o.length;){let e=o.pop();console.log(e),c=c.replace(e,"")}if(c=c.replace(/(#+)(.*)/g,((e,a,l)=>{if(console.log(e),e.includes("<")&&e.includes(">"))return e;{let e=a.length;return`<h ${e} class="markdown_heading">${l}</h${e}>`}})),c=c.replace(/\*\*(.*?)\*\*/g,((e,a)=>`<b class="markdown_bold">${a}</b>`)),c=c.replace(/\*(.*?)\*/g,((e,a)=>`<i class="markdown_italic">${a}</i>`)),c=c.replace(/`(.*?)`/g,((e,a)=>`<code>${a}</code>`)),c=c.replace(/\[([^\]]+)\]\(([^)]+)\)/g,((e,a,l)=>`<a class="markdown_link" href="${l}">${a}</a>`)),c=c.replace(/!\[([^\]]+)\]\(([^)]+)\)/g,((e,a,l)=>`<img class="markdown_image" src="${l}" alt="${a}" />`)),c.split("\n").forEach(((e,a,l)=>{e.match(/^\s*-\s+(.*?)$/gm)&&(c=0!==a&&l[a-1].match(/^\s*-\s+(.*?)$/gm)?a!==l.length-1&&l[a+1].match(/^\s*-\s+(.*?)$/gm)?c.replace(e,`<li>${e.replace(/^\s*-\s+(.*?)$/gm,"$1")}</li>`):c.replace(e,`<li>${e.replace(/^\s*-\s+(.*?)$/gm,"$1")}</li></ul>`):c.replace(e,`<ul class="markdown_unordered" style="list-style-type:disc;list-style:inside"><li>${e.replace(/^\s*-\s+(.*?)$/gm,"$1")}</li>`))})),c.split("\n").forEach(((e,a,l)=>{e.match(/^\s*\d+\.\s+(.*?)$/gm)&&(c=0!==a&&l[a-1].match(/^\s*\d+\.\s+(.*?)$/gm)?a!==l.length-1&&l[a+1].match(/^\s*\d+\.\s+(.*?)$/gm)?c.replace(e,`<li>${e.replace(/^\s*\d+\.\s+(.*?)$/gm,"$1")}</li>`):c.replace(e,`<li>${e.replace(/^\s*\d+\.\s+(.*?)$/gm,"$1")}</li></ol>`):c.replace(e,`<ol class="markdown_ordered" style="list-style-type:decimal;"><li>${e.replace(/^\s*\d+\.\s+(.*?)$/gm,"$1")}</li>`))})),c=c.replace(/^\s*-\s+(.*?)$/gm,((e,a)=>`<li class="markdown_list_item">${a}</li>`)),c=c.replace(/^\s*---\s*$/gm,'<hr class="markdown_horizontal" />'),c=c.replace(/^\s*> (.*)$/gm,((e,a)=>`<blockquote class="markdown_blockquote">${a}</blockquote>`)),c=c.replace(/((?: *\|.*?)+)\n((?: *\|.*?)+)/gm,((e,a,l)=>{const s=a.split("|").slice(1,-1),t=l.split("|").slice(1,-1);let r='<table class="markdown_table">';return r+='<thead class="markdown_table_head"><tr class="markdown_table_row">',s.forEach((e=>{r+=`<th class="markdown_table_header_cell">${e}</th>`})),r+='</tr></thead><tbody class="markdown_table_body"><tr class="markdown_table_row">',t.forEach((e=>{r+=`<td class="markdown_table_body_cell">${e}</td>`})),r+="</tr></tbody></table>",r})),!c.includes("<body>"))throw new Error(`Vader Error: You must enclose your html in a body tag for all components. \n\n${c}`);c=c.replace(/classname/g,"class");let n=c.match(/<img([^>]*)>/g);if(n)for(let a=0;a<n.length;a++){let l=n[a],s=l.match(/src="([^"]*)"/),t=l.match(/alt="([^"]*)"/);if(s){if(s[1].includes("http")&&c.includes("\x3c!-- #vader-disable_relative-paths --\x3e"))throw new Error(`Vader Error: You cannot use relative paths in the src attribute of ${s[0]}. Use absolute paths instead. \n\n${s[0]}`);c=c.replace(s[1],`${r}/${s[1]}`)}if(!t&&!c.includes("\x3c!-- #vader-disable_accessibility --\x3e"))throw new Error(`Vader Error: You must include an alt attribute in the image tag \n\n${l} of class ${e.data.name}. `);caches.match(`${r}/${s[1]}`)?console.log("already cached",caches.match(`${r}/${s[1]}`)):caches.open("vader").then((e=>{e.add(`${r}/${s[1]}`),console.log("cached",`${r}/${s[1]}`)})).catch((e=>{console.log(e)}))}let i=c.match(/href="([^"]*)"/g);if(i)for(;i.length;){let a=i.pop();if(a=a.replace('href="',"").replace('"',""),a.includes("http")&&c.includes("\x3c!-- #vader-disable_relative-paths --\x3e"))throw new Error(`Vader Error: You cannot use relative paths in ${e.data.file}. Use absolute paths instead. \n\n${a}`);c=c.replace(`href="${a}"`,`href="#${a}"`)}let d=Date.now()-a,$=!1;(r.includes("localhost")||r.includes("127.0.0.1")&&!$)&&($=!0,c+=`\${console.log('%c${e.data.name} component rendered in ${d}ms','color:#fff;background:#000;padding:5px;border-radius:5px;font-size:12px;font-weight:bold'),""}`);const h=c.split("<script>");h&&h.forEach(((e,a)=>{if(0===a)c=e;else{if(e.includes("// <![CDATA[ <-- For SVG support"))return;let a=e.split("<\/script>")[0];t+=a}}));let p=c.match(/(\$\(.*?\))/gs);if(p)for(;p.length;){let e=p.pop();c=c.replace(e,`\${${e.replace("$(","").replace(")","")}}`)}postMessage({template:`<div data-component=${e.data.name}>${c}</div>`,js:t||""})};
1
+ onmessage=e=>{let a=Date.now(),l=e.data.strings,s=e.data.args,t="",r=e.data.location.split("/").slice(0,-1).join("/"),c="";for(let e=0;e<l.length;e++)c+=l[e],e<s.length&&(c+=s[e]);let o=c.match(/--([^>]*)--/gs);if(o)for(;o.length;){let e=o.pop();console.log(e),c=c.replace(e,"")}if(c=c.replace(/(#+)(.*)/g,((e,a,l)=>{if(console.log(e),e.includes("<")&&e.includes(">"))return e;{let e=a.length;return`<h ${e} class="markdown_heading">${l}</h${e}>`}})),c=c.replace(/\*\*(.*?)\*\*/g,((e,a)=>`<b class="markdown_bold">${a}</b>`)),c=c.replace(/\*(.*?)\*/g,((e,a)=>`<i class="markdown_italic">${a}</i>`)),c=c.replace(/`(.*?)`/g,((e,a)=>`<code>${a}</code>`)),c=c.replace(/\[([^\]]+)\]\(([^)]+)\)/g,((e,a,l)=>`<a class="markdown_link" href="${l}">${a}</a>`)),c=c.replace(/!\[([^\]]+)\]\(([^)]+)\)/g,((e,a,l)=>`<img class="markdown_image" src="${l}" alt="${a}" />`)),c.split("\n").forEach(((e,a,l)=>{e.match(/^\s*-\s+(.*?)$/gm)&&(c=0!==a&&l[a-1].match(/^\s*-\s+(.*?)$/gm)?a!==l.length-1&&l[a+1].match(/^\s*-\s+(.*?)$/gm)?c.replace(e,`<li>${e.replace(/^\s*-\s+(.*?)$/gm,"$1")}</li>`):c.replace(e,`<li>${e.replace(/^\s*-\s+(.*?)$/gm,"$1")}</li></ul>`):c.replace(e,`<ul class="markdown_unordered" style="list-style-type:disc;list-style:inside"><li>${e.replace(/^\s*-\s+(.*?)$/gm,"$1")}</li>`))})),c.split("\n").forEach(((e,a,l)=>{e.match(/^\s*\d+\.\s+(.*?)$/gm)&&(c=0!==a&&l[a-1].match(/^\s*\d+\.\s+(.*?)$/gm)?a!==l.length-1&&l[a+1].match(/^\s*\d+\.\s+(.*?)$/gm)?c.replace(e,`<li>${e.replace(/^\s*\d+\.\s+(.*?)$/gm,"$1")}</li>`):c.replace(e,`<li>${e.replace(/^\s*\d+\.\s+(.*?)$/gm,"$1")}</li></ol>`):c.replace(e,`<ol class="markdown_ordered" style="list-style-type:decimal;"><li>${e.replace(/^\s*\d+\.\s+(.*?)$/gm,"$1")}</li>`))})),c=c.replace(/^\s*-\s+(.*?)$/gm,((e,a)=>`<li class="markdown_list_item">${a}</li>`)),c=c.replace(/^\s*---\s*$/gm,'<hr class="markdown_horizontal" />'),c=c.replace(/^\s*> (.*)$/gm,((e,a)=>`<blockquote class="markdown_blockquote">${a}</blockquote>`)),c=c.replace(/((?: *\|.*?)+)\n((?: *\|.*?)+)/gm,((e,a,l)=>{const s=a.split("|").slice(1,-1),t=l.split("|").slice(1,-1);let r='<table class="markdown_table">';return r+='<thead class="markdown_table_head"><tr class="markdown_table_row">',s.forEach((e=>{r+=`<th class="markdown_table_header_cell">${e}</th>`})),r+='</tr></thead><tbody class="markdown_table_body"><tr class="markdown_table_row">',t.forEach((e=>{r+=`<td class="markdown_table_body_cell">${e}</td>`})),r+="</tr></tbody></table>",r})),!c.includes("<body>"))throw new Error(`Vader Error: You must enclose your html in a body tag for all components. \n\n${c}`);c=c.replace(/classname/g,"class");let i=c.match(/<img([^>]*)>/g);if(i)for(let a=0;a<i.length;a++){let l=i[a],s=l.match(/src="([^"]*)"/),t=l.match(/alt="([^"]*)"/);if(s)if(s[1].includes("http")||c.includes("\x3c!-- #vader-disable_relative-paths --\x3e")){if(!s[1].includes("http")&&s[1].startsWith(".")&&!c.includes("\x3c!-- #vader-disable_relative-paths --\x3e"))throw new Error(`Vader Error: You cannot use absolute paths since relative paths are not disabled in ${e.data.file}. Use relative paths instead. \n\n${s[1]}`)}else c=c.replace(s[1],`${r}/${s[1]}`);if(!t&&!c.includes("\x3c!-- #vader-disable_accessibility --\x3e"))throw new Error(`Vader Error: You must include an alt attribute in the image tag \n\n${l} of class ${e.data.name}. `);caches.match(`${r}/${s[1]}`)?console.log("already cached",caches.match(`${r}/${s[1]}`)):caches.open("vader").then((e=>{e.add(`${r}/${s[1]}`),console.log("cached",`${r}/${s[1]}`)})).catch((e=>{console.log(e)}))}let n=c.match(/href="([^"]*)"/g);if(n)for(;n.length;){let a=n.pop();if(a=a.replace('href="',"").replace('"',""),a.includes("http")||c.includes("\x3c!-- #vader-disable_relative-paths --\x3e")){if(!a.includes("http")&&a.startsWith(".")&&!c.includes("\x3c!-- #vader-disable_relative-paths --\x3e"))throw new Error(`Vader Error: You cannot use absolute paths since relative paths are not disabled in ${e.data.file}. Use relative paths instead. \n\n${a}`)}else c=c.replace(`href="${a}"`,`href="#${a}"`)}let d=Date.now()-a,h=!1;(r.includes("localhost")||r.includes("127.0.0.1")&&!h)&&(h=!0,c+=`\${console.log('%c${e.data.name} component rendered in ${d}ms','color:#fff;background:#000;padding:5px;border-radius:5px;font-size:12px;font-weight:bold'),""}`);const p=c.split("<script>");p&&p.forEach(((e,a)=>{if(0===a)c=e;else{if(e.includes("// <![CDATA[ <-- For SVG support"))return;let a=e.split("<\/script>")[0];t+=a}}));let $=c.match(/(\$\(.*?\))/gs);if($)for(;$.length;){let e=$.pop();c=c.replace(e,`\${${e.replace("$(","").replace(")","")}}`)}postMessage({template:`<div data-component=${e.data.name}>${c}</div>`,js:t||""})};
package/worker.js CHANGED
@@ -1,223 +1,226 @@
1
1
 
2
2
  onmessage = (e)=>{
3
- let time_started = Date.now()
4
- let strings = e.data.strings
5
- let args = e.data.args
6
- let js = ''
7
- let l = e.data.location.split('/').slice(0,-1).join('/')
8
- let result = "";
9
- for (let i = 0; i < strings.length; i++) {
10
- result += strings[i];
11
- if (i < args.length) {
12
- result += args[i];
13
- }
3
+ let time_started = Date.now()
4
+ let strings = e.data.strings
5
+ let args = e.data.args
6
+ let js = ''
7
+ let l = e.data.location.split('/').slice(0,-1).join('/')
8
+ let result = "";
9
+ for (let i = 0; i < strings.length; i++) {
10
+ result += strings[i];
11
+ if (i < args.length) {
12
+ result += args[i];
14
13
  }
14
+ }
15
+
16
+ let comments = result.match(/--([^>]*)--/gs)
17
+ if(comments){
18
+ while(comments.length){
19
+ let comment = comments.pop()
20
+ console.log(comment)
21
+ // @ts-ignore
22
+ result = result.replace(comment,'')
23
+ }
24
+ }
15
25
 
16
- let comments = result.match(/--([^>]*)--/gs)
17
- if(comments){
18
- while(comments.length){
19
- let comment = comments.pop()
20
- console.log(comment)
21
- // @ts-ignore
22
- result = result.replace(comment,'')
23
- }
24
- }
26
+
27
+ // Convert headings (e.g., #1-6 Heading => <h1-6>Heading</h1-6>)
28
+ // @ts-ignore
29
+ result = result.replace(/(#+)(.*)/g, (match, hashes, text) => {
30
+ console.log(match)
31
+ if(!match.includes('<') || !match.includes('>')){
32
+ let level = hashes.length;
33
+ return `<h ${level} class="markdown_heading">${text}</h${level}>`;
34
+ }else{
35
+ return match
36
+ }
37
+ });
38
+
39
+
25
40
 
26
41
 
27
- // Convert headings (e.g., #1-6 Heading => <h1-6>Heading</h1-6>)
28
- // @ts-ignore
29
- result = result.replace(/(#+)(.*)/g, (match, hashes, text) => {
30
- console.log(match)
31
- if(!match.includes('<') || !match.includes('>')){
32
- let level = hashes.length;
33
- return `<h ${level} class="markdown_heading">${text}</h${level}>`;
34
- }else{
35
- return match
36
- }
37
- });
42
+ // Convert bold (e.g., **Bold** => <b>Bold</b>)
43
+ result = result.replace(/\*\*(.*?)\*\*/g, (match, text) => {
44
+ return `<b class="markdown_bold">${text}</b>`;
45
+ });
38
46
 
39
-
40
- // Convert bold (e.g., **Bold** => <b>Bold</b>)
41
- result = result.replace(/\*\*(.*?)\*\*/g, (match, text) => {
42
- return `<b class="markdown_bold">${text}</b>`;
43
- });
44
-
45
- // Convert italic (e.g., *Italic* => <i>Italic</i>)
46
- result = result.replace(/\*(.*?)\*/g, (match, text) => {
47
- return `<i class="markdown_italic">${text}</i>`;
48
- });
49
-
50
- // Convert code (e.g., `code` => <code>code</code>)
51
- result = result.replace(/`(.*?)`/g, (match, text) => {
52
- return `<code>${text}</code>`;
53
- });
54
-
55
- // Convert links (e.g., [Text](URL) => <a href="URL">Text</a>)
56
- result = result.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (match, text, url) => {
57
- return `<a class="markdown_link" href="${url}">${text}</a>`;
58
- });
59
-
60
- // Convert images (e.g., ![Alt](URL) => <img src="URL" alt="Alt" />)
61
- result = result.replace(/!\[([^\]]+)\]\(([^)]+)\)/g, (match, alt, src) => {
62
- return `<img class="markdown_image" src="${src}" alt="${alt}" />`;
63
- });
64
-
65
- // Convert unordered lists (e.g., * Item => <ul><li>Item</li></ul>)
66
- result.split('\n').forEach((line, index, arr) => {
67
- if (line.match(/^\s*-\s+(.*?)$/gm)) {
68
- if (index === 0 || !arr[index - 1].match(/^\s*-\s+(.*?)$/gm)) {
69
- result = result.replace(line, `<ul class="markdown_unordered" style="list-style-type:disc;list-style:inside"><li>${line.replace(/^\s*-\s+(.*?)$/gm, '$1')}</li>`);
70
- } else if (index === arr.length - 1 || !arr[index + 1].match(/^\s*-\s+(.*?)$/gm)) {
71
- result = result.replace(line, `<li>${line.replace(/^\s*-\s+(.*?)$/gm, '$1')}</li></ul>`);
72
- } else {
73
- result = result.replace(line, `<li>${line.replace(/^\s*-\s+(.*?)$/gm, '$1')}</li>`);
74
- }
47
+ // Convert italic (e.g., *Italic* => <i>Italic</i>)
48
+ result = result.replace(/\*(.*?)\*/g, (match, text) => {
49
+ return `<i class="markdown_italic">${text}</i>`;
50
+ });
51
+
52
+ // Convert code (e.g., `code` => <code>code</code>)
53
+ result = result.replace(/`(.*?)`/g, (match, text) => {
54
+ return `<code>${text}</code>`;
55
+ });
56
+
57
+ // Convert links (e.g., [Text](URL) => <a href="URL">Text</a>)
58
+ result = result.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (match, text, url) => {
59
+ return `<a class="markdown_link" href="${url}">${text}</a>`;
60
+ });
61
+
62
+ // Convert images (e.g., ![Alt](URL) => <img src="URL" alt="Alt" />)
63
+ result = result.replace(/!\[([^\]]+)\]\(([^)]+)\)/g, (match, alt, src) => {
64
+ return `<img class="markdown_image" src="${src}" alt="${alt}" />`;
65
+ });
66
+
67
+ // Convert unordered lists (e.g., * Item => <ul><li>Item</li></ul>)
68
+ result.split('\n').forEach((line, index, arr) => {
69
+ if (line.match(/^\s*-\s+(.*?)$/gm)) {
70
+ if (index === 0 || !arr[index - 1].match(/^\s*-\s+(.*?)$/gm)) {
71
+ result = result.replace(line, `<ul class="markdown_unordered" style="list-style-type:disc;list-style:inside"><li>${line.replace(/^\s*-\s+(.*?)$/gm, '$1')}</li>`);
72
+ } else if (index === arr.length - 1 || !arr[index + 1].match(/^\s*-\s+(.*?)$/gm)) {
73
+ result = result.replace(line, `<li>${line.replace(/^\s*-\s+(.*?)$/gm, '$1')}</li></ul>`);
74
+ } else {
75
+ result = result.replace(line, `<li>${line.replace(/^\s*-\s+(.*?)$/gm, '$1')}</li>`);
75
76
  }
76
- });
77
-
78
- // Convert ordered lists (e.g., 1. Item => <ol><li>Item</li></ol>) in order
79
-
80
- result.split('\n').forEach((line, index, arr) => {
81
- if (line.match(/^\s*\d+\.\s+(.*?)$/gm)) {
82
- if (index === 0 || !arr[index - 1].match(/^\s*\d+\.\s+(.*?)$/gm)) {
83
- result = result.replace(line, `<ol class="markdown_ordered" style="list-style-type:decimal;"><li>${line.replace(/^\s*\d+\.\s+(.*?)$/gm, '$1')}</li>`);
84
- } else if (index === arr.length - 1 || !arr[index + 1].match(/^\s*\d+\.\s+(.*?)$/gm)) {
85
- result = result.replace(line, `<li>${line.replace(/^\s*\d+\.\s+(.*?)$/gm, '$1')}</li></ol>`);
86
- } else {
87
- result = result.replace(line, `<li>${line.replace(/^\s*\d+\.\s+(.*?)$/gm, '$1')}</li>`);
88
- }
77
+ }
78
+ });
79
+
80
+ // Convert ordered lists (e.g., 1. Item => <ol><li>Item</li></ol>) in order
81
+
82
+ result.split('\n').forEach((line, index, arr) => {
83
+ if (line.match(/^\s*\d+\.\s+(.*?)$/gm)) {
84
+ if (index === 0 || !arr[index - 1].match(/^\s*\d+\.\s+(.*?)$/gm)) {
85
+ result = result.replace(line, `<ol class="markdown_ordered" style="list-style-type:decimal;"><li>${line.replace(/^\s*\d+\.\s+(.*?)$/gm, '$1')}</li>`);
86
+ } else if (index === arr.length - 1 || !arr[index + 1].match(/^\s*\d+\.\s+(.*?)$/gm)) {
87
+ result = result.replace(line, `<li>${line.replace(/^\s*\d+\.\s+(.*?)$/gm, '$1')}</li></ol>`);
88
+ } else {
89
+ result = result.replace(line, `<li>${line.replace(/^\s*\d+\.\s+(.*?)$/gm, '$1')}</li>`);
89
90
  }
90
- });
91
+ }
92
+ });
91
93
 
92
-
93
- result = result.replace(/^\s*-\s+(.*?)$/gm, (match, text) => {
94
- return `<li class="markdown_list_item">${text}</li>`;
95
- });
96
- result = result.replace(/^\s*---\s*$/gm, '<hr class="markdown_horizontal" />');
97
94
 
98
- // Convert blockquotes (e.g., > Quote => <blockquote>Quote</blockquote>)
99
- result = result.replace(/^\s*> (.*)$/gm, (match, text) => {
100
- return `<blockquote class="markdown_blockquote">${text}</blockquote>`;
101
- });
95
+ result = result.replace(/^\s*-\s+(.*?)$/gm, (match, text) => {
96
+ return `<li class="markdown_list_item">${text}</li>`;
97
+ });
98
+ result = result.replace(/^\s*---\s*$/gm, '<hr class="markdown_horizontal" />');
99
+
100
+ // Convert blockquotes (e.g., > Quote => <blockquote>Quote</blockquote>)
101
+ result = result.replace(/^\s*> (.*)$/gm, (match, text) => {
102
+ return `<blockquote class="markdown_blockquote">${text}</blockquote>`;
103
+ });
102
104
 
103
- // Convert tables (e.g., | Header | Cell | => <table><thead><tr><th>Header</th><th>Cell</th></tr></thead></table>)
104
- result = result.replace(/((?: *\|.*?)+)\n((?: *\|.*?)+)/gm, (match, header, cell) => {
105
- const headerCells = header.split('|').slice(1, -1);
106
- const cells = cell.split('|').slice(1, -1);
107
- let table = '<table class="markdown_table">';
108
- table += '<thead class="markdown_table_head"><tr class="markdown_table_row">';
109
- headerCells.forEach((headerCell) => {
110
- table += `<th class="markdown_table_header_cell">${headerCell}</th>`;
111
- });
112
- table += '</tr></thead><tbody class="markdown_table_body"><tr class="markdown_table_row">';
113
- cells.forEach((cell) => {
114
- table += `<td class="markdown_table_body_cell">${cell}</td>`;
115
- });
116
- table += '</tr></tbody></table>';
117
- return table;
105
+ // Convert tables (e.g., | Header | Cell | => <table><thead><tr><th>Header</th><th>Cell</th></tr></thead></table>)
106
+ result = result.replace(/((?: *\|.*?)+)\n((?: *\|.*?)+)/gm, (match, header, cell) => {
107
+ const headerCells = header.split('|').slice(1, -1);
108
+ const cells = cell.split('|').slice(1, -1);
109
+ let table = '<table class="markdown_table">';
110
+ table += '<thead class="markdown_table_head"><tr class="markdown_table_row">';
111
+ headerCells.forEach((headerCell) => {
112
+ table += `<th class="markdown_table_header_cell">${headerCell}</th>`;
118
113
  });
119
-
114
+ table += '</tr></thead><tbody class="markdown_table_body"><tr class="markdown_table_row">';
115
+ cells.forEach((cell) => {
116
+ table += `<td class="markdown_table_body_cell">${cell}</td>`;
117
+ });
118
+ table += '</tr></tbody></table>';
119
+ return table;
120
+ });
121
+
120
122
 
121
-
122
- if(!result.includes('<body>')){
123
- throw new Error(`Vader Error: You must enclose your html in a body tag for all components. \n\n${result}`)
123
+
124
+
125
+ if(!result.includes('<body>')){
126
+ throw new Error(`Vader Error: You must enclose your html in a body tag for all components. \n\n${result}`)
127
+ }
128
+ /**
129
+ * @type {string[]}
130
+ * @description - grabbing all className attributes and replace them with class
131
+ */
132
+ // @ts-ignore
133
+ result = result.replace(/classname/g,'class')
134
+ /**
135
+ * @type {string[]}
136
+ * @description - grabbing all image tags and replace the src attribute with the absolute path
137
+ */
138
+ // @ts-ignore
139
+ let images = result.match(/<img([^>]*)>/g)
140
+ if(images){
141
+ for(let i = 0; i < images.length; i++){
142
+ let image = images[i]
143
+ let src = image.match(/src="([^"]*)"/)
144
+ let alt = image.match(/alt="([^"]*)"/)
145
+ if(src){
146
+ if(!src[1].includes('http') && !result.includes('<!-- #vader-disable_relative-paths -->')){
147
+ // @ts-ignore
148
+ result = result.replace(src[1],`${l}/${src[1]}`)
149
+ } else if(!src[1].includes('http') && src[1].startsWith('.') && !result.includes('<!-- #vader-disable_relative-paths -->')){
150
+ throw new Error(`Vader Error: You cannot use absolute paths since relative paths are not disabled in ${e.data.file}. Use relative paths instead. \n\n${src[1]}`)
124
151
  }
125
- /**
126
- * @type {string[]}
127
- * @description - grabbing all className attributes and replace them with class
128
- */
129
- // @ts-ignore
130
- result = result.replace(/classname/g,'class')
131
- /**
132
- * @type {string[]}
133
- * @description - grabbing all image tags and replace the src attribute with the absolute path
134
- */
152
+ }
153
+ if(!alt && !result.includes('<!-- #vader-disable_accessibility -->')){
154
+ throw new Error(`Vader Error: You must include an alt attribute in the image tag \n\n${image} of class ${e.data.name}. `)
155
+ }
156
+
135
157
  // @ts-ignore
136
- let images = result.match(/<img([^>]*)>/g)
137
- if(images){
138
- for(let i = 0; i < images.length; i++){
139
- let image = images[i]
140
- let src = image.match(/src="([^"]*)"/)
141
- let alt = image.match(/alt="([^"]*)"/)
142
- if(src){
143
- if(!src[1].includes('http') || !result.includes('<!-- #vader-disable_relative-paths -->')){
144
- // @ts-ignore
145
- result = result.replace(src[1],`${l}/${src[1]}`)
146
- }else{
147
- throw new Error(`Vader Error: You cannot use relative paths in the src attribute of ${src[0]}. Use absolute paths instead. \n\n${src[0]}`)
148
- }
149
- }
150
- if(!alt && !result.includes('<!-- #vader-disable_accessibility -->')){
151
- throw new Error(`Vader Error: You must include an alt attribute in the image tag \n\n${image} of class ${e.data.name}. `)
152
- }
153
-
158
+ if(!caches.match(`${l}/${src[1]}`)){
159
+ caches.open('vader').then((cache)=>{
160
+ // @ts-ignore
161
+ cache.add(`${l}/${src[1]}`)
162
+ // @ts-ignore
163
+ console.log('cached', `${l}/${src[1]}`)
164
+ }).catch((err)=>{
165
+ console.log(err)
166
+ })
167
+ }else{
154
168
  // @ts-ignore
155
- if(!caches.match(`${l}/${src[1]}`)){
156
- caches.open('vader').then((cache)=>{
157
- // @ts-ignore
158
- cache.add(`${l}/${src[1]}`)
159
- // @ts-ignore
160
- console.log('cached', `${l}/${src[1]}`)
161
- }).catch((err)=>{
162
- console.log(err)
163
- })
164
- }else{
165
- // @ts-ignore
166
- console.log('already cached', caches.match(`${l}/${src[1]}`))
167
- }
168
- }
169
+ console.log('already cached', caches.match(`${l}/${src[1]}`))
169
170
  }
171
+ }
172
+ }
170
173
 
171
- let href = result.match(/href="([^"]*)"/g)
172
- if(href){
173
- while(href.length){
174
- let h = href.pop()
175
- // @ts-ignore
176
- h = h.replace('href="','').replace('"','')
177
- if(!h.includes('http') || !result.includes('<!-- #vader-disable_relative-paths -->')){
178
- result = result.replace(`href="${h}"`,`href="#${h}"`)
179
- }else{
180
- throw new Error(`Vader Error: You cannot use relative paths in ${e.data.file}. Use absolute paths instead. \n\n${h}`)
181
- }
182
- }
183
- }
184
-
185
- let time_ended = Date.now()
186
- let time_taken = time_ended - time_started
187
- let hasran = false
188
- if(l.includes('localhost') || l.includes('127.0.0.1') && !hasran){
189
- hasran = true
190
- result+= `\$\{console.log('%c${e.data.name} component rendered in ${time_taken}ms','color:#fff;background:#000;padding:5px;border-radius:5px;font-size:12px;font-weight:bold'),""\}`
191
- }
192
-
193
-
194
- const d = result.split('<script>')
195
-
196
- if (d) {
197
- d.forEach((scriptTag, index) => {
198
- if (index === 0) {
199
- result = scriptTag;
200
- } else {
201
- if(scriptTag.includes('// <![CDATA[ <-- For SVG support')){
202
- return
174
+ let href = result.match(/href="([^"]*)"/g)
175
+ if(href){
176
+ while(href.length){
177
+ let h = href.pop()
178
+ // @ts-ignore
179
+ h = h.replace('href="','').replace('"','')
180
+ if(!h.includes('http') && !result.includes('<!-- #vader-disable_relative-paths -->')){
181
+ result = result.replace(`href="${h}"`,`href="#${h}"`)
182
+ }else if(!h.includes('http') && h.startsWith('.') && !result.includes('<!-- #vader-disable_relative-paths -->')){
183
+ throw new Error(`Vader Error: You cannot use absolute paths since relative paths are not disabled in ${e.data.file}. Use relative paths instead. \n\n${h}`)
203
184
  }
204
- let script = scriptTag.split('</script>')[0];
205
- js += script;
206
- }
207
- });
208
- }
209
-
210
- let jstemplates = result.match(/(\$\(.*?\))/gs)
211
- if(jstemplates){
212
- while(jstemplates.length){
213
- let jstemplate = jstemplates.pop()
214
- // @ts-ignore
215
- result = result.replace(jstemplate,`$\{${jstemplate.replace('$(','').replace(')','')}\}`)
185
+ }
186
+ }
187
+
188
+ let time_ended = Date.now()
189
+ let time_taken = time_ended - time_started
190
+ let hasran = false
191
+ if(l.includes('localhost') || l.includes('127.0.0.1') && !hasran){
192
+ hasran = true
193
+ result+= `\$\{console.log('%c${e.data.name} component rendered in ${time_taken}ms','color:#fff;background:#000;padding:5px;border-radius:5px;font-size:12px;font-weight:bold'),""\}`
194
+ }
195
+
196
+
197
+ const d = result.split('<script>')
198
+
199
+ if (d) {
200
+ d.forEach((scriptTag, index) => {
201
+ if (index === 0) {
202
+ result = scriptTag;
203
+ } else {
204
+ if(scriptTag.includes('// <![CDATA[ <-- For SVG support')){
205
+ return
216
206
  }
217
- }
218
- postMessage({
219
- template: `<div data-component=${e.data.name}>${result}</div>`,
220
- js: js ? js : ''
221
- })
207
+ let script = scriptTag.split('</script>')[0];
208
+ js += script;
209
+ }
210
+ });
211
+ }
222
212
 
223
- }
213
+ let jstemplates = result.match(/(\$\(.*?\))/gs)
214
+ if(jstemplates){
215
+ while(jstemplates.length){
216
+ let jstemplate = jstemplates.pop()
217
+ // @ts-ignore
218
+ result = result.replace(jstemplate,`$\{${jstemplate.replace('$(','').replace(')','')}\}`)
219
+ }
220
+ }
221
+ postMessage({
222
+ template: `<div data-component=${e.data.name}>${result}</div>`,
223
+ js: js ? js : ''
224
+ })
225
+
226
+ }