vaderjs 1.3.5 → 1.3.7-alpha-1
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 +167 -0
- package/logo.png +0 -0
- package/package.json +15 -23
- package/runtime/router.js +261 -0
- package/runtime/static/index.html +21 -0
- package/vader +0 -0
- package/.vscode/settings.json +0 -5
- package/.vscode/vaderjs.autosense.json +0 -5
- package/images/router.png +0 -0
- package/images/state.png +0 -0
- package/index.js +0 -12
- package/jsconfig.json +0 -17
- package/readme.md +0 -262
- package/ts.config.json +0 -1
- package/tsconfig.json +0 -18
- package/vader-min.js +0 -1
- package/vader.js +0 -1115
- package/vaderRouter.js +0 -231
- package/worker-min.js +0 -1
- package/worker.js +0 -326
package/vaderRouter.js
DELETED
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @class VaderRouter
|
|
4
|
-
* @description - creates an instance of Vader Express Router
|
|
5
|
-
*
|
|
6
|
-
* @param {String} path
|
|
7
|
-
* @param {Function} handler
|
|
8
|
-
* @param {object} req request object
|
|
9
|
-
* @param {object} res response object
|
|
10
|
-
* @returns {Object} Express
|
|
11
|
-
*
|
|
12
|
-
*/
|
|
13
|
-
class VaderRouter{
|
|
14
|
-
/**
|
|
15
|
-
* @constructor
|
|
16
|
-
* @param {*} basePath
|
|
17
|
-
*
|
|
18
|
-
*/
|
|
19
|
-
constructor(basePath) {
|
|
20
|
-
this.routes = [];
|
|
21
|
-
this.middlewares = [];
|
|
22
|
-
this.errorMiddlewares = [];
|
|
23
|
-
this.listeners = [];
|
|
24
|
-
|
|
25
|
-
this.basePath = basePath;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* @method get
|
|
30
|
-
* @param {String} path
|
|
31
|
-
* @param {Function} handler
|
|
32
|
-
* @description This method is used to register a get route
|
|
33
|
-
* @returns {void}
|
|
34
|
-
* @memberof Express
|
|
35
|
-
*/
|
|
36
|
-
get(path, handler) {
|
|
37
|
-
|
|
38
|
-
this.routes.push({
|
|
39
|
-
path,
|
|
40
|
-
handler,
|
|
41
|
-
method: 'get',
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* @method use
|
|
46
|
-
* @description This method allows you to use middlewares
|
|
47
|
-
* @param {Function} middleware
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
use(/* path, */ middleware) {
|
|
51
|
-
this.middlewares.push(middleware);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* @method listen
|
|
56
|
-
* @param {*} port - unique id for the listener
|
|
57
|
-
* @param {Function} callback - callback function
|
|
58
|
-
* @description This method is used to start listening to the routes
|
|
59
|
-
* @returns {void}
|
|
60
|
-
*
|
|
61
|
-
*/
|
|
62
|
-
|
|
63
|
-
listen(port, callback) {
|
|
64
|
-
if(!port){
|
|
65
|
-
port = Math.random().toString(36).substring(7);
|
|
66
|
-
}
|
|
67
|
-
this.listeners.push(port);
|
|
68
|
-
callback();
|
|
69
|
-
if (this.listeners.length === 1) {
|
|
70
|
-
this.handleRoute(window.location.hash);
|
|
71
|
-
}else{
|
|
72
|
-
this.listeners.pop();
|
|
73
|
-
}
|
|
74
|
-
if (callback) {
|
|
75
|
-
callback();
|
|
76
|
-
}
|
|
77
|
-
window.onhashchange = () => {
|
|
78
|
-
this.handleRoute(window.location.hash);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* @method extractParams
|
|
83
|
-
* @description This method is used to extract parameters from the route path
|
|
84
|
-
* @param {*} routePath
|
|
85
|
-
* @param {*} hash
|
|
86
|
-
* @returns {Object} params
|
|
87
|
-
* @memberof Express
|
|
88
|
-
*/
|
|
89
|
-
|
|
90
|
-
extractParams(routePath, hash) {
|
|
91
|
-
const routeParts = routePath.split('/');
|
|
92
|
-
const hashParts = hash.split('/');
|
|
93
|
-
const params = {};
|
|
94
|
-
routeParts.forEach((part, index) => {
|
|
95
|
-
if (part.startsWith(':')) {
|
|
96
|
-
const paramName = part.slice(1);
|
|
97
|
-
params[paramName] = hashParts[index];
|
|
98
|
-
}else if(part.startsWith('*')){
|
|
99
|
-
// remove queries from this par
|
|
100
|
-
params[0] = hashParts.slice(index).join('/').split('?')[0];
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
return params;
|
|
104
|
-
}
|
|
105
|
-
extractQueryParams(hash){
|
|
106
|
-
|
|
107
|
-
const queryParams = hash.split('?')[1];
|
|
108
|
-
if(!queryParams){
|
|
109
|
-
return {};
|
|
110
|
-
}
|
|
111
|
-
const params = {};
|
|
112
|
-
queryParams.split('&').forEach((param)=>{
|
|
113
|
-
const [key, value] = param.split('=');
|
|
114
|
-
params[key] = value;
|
|
115
|
-
})
|
|
116
|
-
return params;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* @method handleRoute
|
|
121
|
-
* @param {String} hash
|
|
122
|
-
* @description This method is used to handle the route
|
|
123
|
-
*/
|
|
124
|
-
|
|
125
|
-
handleRoute(hash) {
|
|
126
|
-
hash = hash.slice(1);
|
|
127
|
-
let status = 200;
|
|
128
|
-
let route = this.routes.find((route) => {
|
|
129
|
-
|
|
130
|
-
if (route.path === hash) {
|
|
131
|
-
return true;
|
|
132
|
-
}
|
|
133
|
-
const routePathParts = route.path.split('/');
|
|
134
|
-
const hashParts = hash.split('/');
|
|
135
|
-
if (routePathParts.length !== hashParts.length) {
|
|
136
|
-
return false;
|
|
137
|
-
}else if(routePathParts[routePathParts.length-1].startsWith('*')){
|
|
138
|
-
return true;
|
|
139
|
-
}
|
|
140
|
-
const params = this.extractParams( route.path, hash);
|
|
141
|
-
return Object.keys(params).length > 0;
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
if (!route) {
|
|
145
|
-
route = this.routes.find((route) => {
|
|
146
|
-
|
|
147
|
-
if(route.path === '/404'){
|
|
148
|
-
return true;
|
|
149
|
-
}else{
|
|
150
|
-
window.location.hash = this.basePath
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
route ? status = 200 :
|
|
155
|
-
|
|
156
|
-
status = 404;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const queryParams = this.extractQueryParams(hash);
|
|
161
|
-
const params = route && route.path ? this.extractParams(route.path, hash) : {};
|
|
162
|
-
const req = {
|
|
163
|
-
headers: {},
|
|
164
|
-
params: params,
|
|
165
|
-
query: queryParams,
|
|
166
|
-
path: hash,
|
|
167
|
-
method: route ? route.method : 'get',
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
// @ts-ignore
|
|
171
|
-
window.$CURRENT_URL = req.path
|
|
172
|
-
|
|
173
|
-
// @ts-ignore
|
|
174
|
-
window.$FULL_URL = window.location.href.replace('#', '')
|
|
175
|
-
|
|
176
|
-
const res = {
|
|
177
|
-
status: status,
|
|
178
|
-
/**
|
|
179
|
-
* @method log
|
|
180
|
-
* @param {String} type
|
|
181
|
-
* @description This method is used to log the request and response
|
|
182
|
-
*/
|
|
183
|
-
log: (type) => {
|
|
184
|
-
if(type === undefined){
|
|
185
|
-
console.log(`${req.path} ${req.method} ${res.status} ${req.timestamp}`);
|
|
186
|
-
}else{
|
|
187
|
-
console.table({
|
|
188
|
-
'Request Path': req.path,
|
|
189
|
-
'Request Method': route.method,
|
|
190
|
-
'Response Status': res.status,
|
|
191
|
-
'Request Timestamp': req.timestamp,
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
},
|
|
195
|
-
send: (selector, data) => {
|
|
196
|
-
if(typeof selector === 'string'){
|
|
197
|
-
// @ts-ignore
|
|
198
|
-
document.querySelector(selector).innerHTML = data;
|
|
199
|
-
}else if(typeof selector === 'number'){
|
|
200
|
-
res.status = selector;
|
|
201
|
-
}else if(typeof selector === 'object'){
|
|
202
|
-
res.status = selector.status;
|
|
203
|
-
}
|
|
204
|
-
},
|
|
205
|
-
json: (selector, data) => {
|
|
206
|
-
|
|
207
|
-
if(typeof selector === 'string'){
|
|
208
|
-
// @ts-ignore
|
|
209
|
-
let obj = document.createElement('object');
|
|
210
|
-
// data url
|
|
211
|
-
obj.data = URL.createObjectURL(new Blob([JSON.stringify(data)], {type: 'application/json'}));
|
|
212
|
-
// @ts-ignore
|
|
213
|
-
document.querySelector(selector).appendChild(obj);
|
|
214
|
-
}else{
|
|
215
|
-
throw new Error('Selector must be a string');
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
|
-
};
|
|
219
|
-
this.middlewares.forEach((middleware) => {
|
|
220
|
-
middleware(req, res);
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
route ? route.handler(req, res) : null;
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
export default VaderRouter;
|
|
230
|
-
|
|
231
|
-
|
package/worker-min.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
onmessage=e=>{let l=Date.now(),a=e.data.strings,t=e.data.args,s="",r=e.data.location.split("/").slice(0,-1).join("/"),c="";for(let e=0;e<a.length;e++)c+=a[e],e<t.length&&(c+=t[e]);let i=c.match(/--([^>]*)--/gs);if(i)for(;i.length;){let e=i.pop();c=c.replace(e,"")}if(c=c.replace(/(#+)([^<>\n]*)(?![^<]*>)(?![^{]*})/g,((e,l,a)=>{let t=l.length;return`<h${t} class="markdown_heading">${a}</h${t}>`})),c=c.replace(/\*\*(.*?)\*\*/g,((e,l)=>`<b class="markdown_bold">${l}</b>`)),c=c.replace(/\*(.*?)\*/g,((e,l)=>`<i class="markdown_italic">${l}</i>`)),c=c.replace(/`(.*?)`/g,((e,l)=>`<code>${l}</code>`)),c=c.replace(/\[([^\]]+)\]\(([^)]+)\)/g,((e,l,a)=>`<a class="markdown_link" href="${a}">${l}</a>`)),c=c.replace(/!\[([^\]]+)\]\(([^)]+)\)/g,((e,l,a)=>`<img class="markdown_image" src="${a}" alt="${l}" />`)),c.split("\n").forEach(((e,l,a)=>{e.match(/^\s*-\s+(.*?)$/gm)&&(c=0!==l&&a[l-1].match(/^\s*-\s+(.*?)$/gm)?l!==a.length-1&&a[l+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,l,a)=>{e.match(/^\s*\d+\.\s+(.*?)$/gm)&&(c=0!==l&&a[l-1].match(/^\s*\d+\.\s+(.*?)$/gm)?l!==a.length-1&&a[l+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,l)=>`<li class="markdown_list_item">${l}</li>`)),c=c.replace(/^\s*---\s*$/gm,'<hr class="markdown_horizontal" />'),c=c.replace(/^\s*> (.*)$/gm,((e,l)=>`<blockquote class="markdown_blockquote">${l}</blockquote>`)),c=c.replace(/((?: *\|.*?)+)\n((?: *\|.*?)+)/gm,((e,l,a)=>{const t=l.split("|").slice(1,-1),s=a.split("|").slice(1,-1);let r='<table class="markdown_table">';return r+='<thead class="markdown_table_head"><tr class="markdown_table_row">',t.forEach((e=>{r+=`<th class="markdown_table_header_cell">${e}</th>`})),r+='</tr></thead><tbody class="markdown_table_body"><tr class="markdown_table_row">',s.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 o=c.match(/<img([^>]*)>/g);if(o)for(let l=0;l<o.length;l++){let a=o[l],t=a.match(/src="([^"]*)"/);if(!a.match(/alt="([^"]*)"/)&&!c.includes("\x3c!-- #vader-disable_accessibility --\x3e"))throw new Error(`Vader Error: You must include an alt attribute in the image tag \n\n${a} of class ${e.data.name}. `);t&&t.forEach((l=>{if(l.includes("http")||c.includes("\x3c!-- #vader-disable_relative-paths --\x3e")){if(!l.includes("http")&&l.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${l}`)}else c=c.replace(`src="${l}"`,`src="${r}/${l}"`)}))}let n=c.match(/href="([^"]*)"/g);if(n)for(;n.length;){let l=n.pop();if(l=l.replace('href="',"").replace('"',""),l.includes("http")||c.includes("\x3c!-- #vader-disable_relative-paths --\x3e")){if(!l.includes("http")&&l.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${l}`)}else c=c.replace(`href="${l}"`,`href="#${l}"`)}let d=Date.now()-l,p=!1;(r.includes("localhost")||r.includes("127.0.0.1")&&!p)&&(p=!0,c+=`\${console.log('%c${e.data.name} component rendered in ${d}ms')}`);const h=c.split("<script>");h&&h.forEach(((e,l)=>{if(0===l)c=e;else{if(e.includes("// <![CDATA[ <-- For SVG support"))return;let l=e.split("<\/script>")[0];s+=l}}));let m=c.match(/(\$\(.*?\))/gs);if(m)for(;m.length;){let e=m.pop();c=c.replace(e,`\${${e.replace("$(","").replace(")","")}}`)}let $=c.match(/@title '([^>]*)';/);if($){let e=`{document.title = "${$[1]}", ""}`;c=c.replace($[0],"$"+e)}let g=c.match(/@style{([^>]*)};/gs);if(g)for(let e=0;e<g.length;e++){if(!g[e].includes("style"))continue;let l=g[e];console.log(l);let a=l.replace("@style{","").replace("};","");a=a.replaceAll(",",";"),a=a.replaceAll(/[A-Z]/g,(e=>`-${e.toLowerCase()}`)),a=a.replaceAll(/'/g," "),c=c.replace(l,`style="${a}"`)}let u=c.match(/@stylesheet{([^>]*)};/);if(u){let e=u[1].replaceAll(" ","");e=e.replaceAll(",",";"),e=e.replaceAll(/[A-Z]/g,(e=>`-${e.toLowerCase()}`)),e=e.replaceAll(/'/g," "),c=c.replace(u[0],`<style>${e}</style>`)}postMessage({template:`<div data-component=${e.data.name}>${c}</div>`,js:s||""})};
|
package/worker.js
DELETED
|
@@ -1,326 +0,0 @@
|
|
|
1
|
-
onmessage = (e) => {
|
|
2
|
-
let time_started = Date.now();
|
|
3
|
-
let strings = e.data.strings;
|
|
4
|
-
let args = e.data.args;
|
|
5
|
-
let js = "";
|
|
6
|
-
let l = e.data.location.split("/").slice(0, -1).join("/");
|
|
7
|
-
let result = "";
|
|
8
|
-
for (let i = 0; i < strings.length; i++) {
|
|
9
|
-
result += strings[i];
|
|
10
|
-
if (i < args.length) {
|
|
11
|
-
result += args[i];
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
let comments = result.match(/--([^>]*)--/gs);
|
|
16
|
-
/**
|
|
17
|
-
* @example
|
|
18
|
-
*
|
|
19
|
-
* -- This is a comment --
|
|
20
|
-
*/
|
|
21
|
-
if (comments) {
|
|
22
|
-
while (comments.length) {
|
|
23
|
-
let comment = comments.pop();
|
|
24
|
-
// @ts-ignore
|
|
25
|
-
result = result.replace(comment, "");
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
result = result.replace(/(#+)([^<>\n]*)(?![^<]*>)(?![^{]*})/g, (match, hashes, text) => {
|
|
30
|
-
let level = hashes.length;
|
|
31
|
-
return `<h${level} class="markdown_heading">${text}</h${level}>`;
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
// Convert bold (e.g., **Bold** => <b>Bold</b>)
|
|
36
|
-
result = result.replace(/\*\*(.*?)\*\*/g, (match, text) => {
|
|
37
|
-
return `<b class="markdown_bold">${text}</b>`;
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// Convert italic (e.g., *Italic* => <i>Italic</i>)
|
|
41
|
-
result = result.replace(/\*(.*?)\*/g, (match, text) => {
|
|
42
|
-
return `<i class="markdown_italic">${text}</i>`;
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
// Convert code (e.g., `code` => <code>code</code>)
|
|
46
|
-
result = result.replace(/`(.*?)`/g, (match, text) => {
|
|
47
|
-
return `<code>${text}</code>`;
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
// Convert links (e.g., [Text](URL) => <a href="URL">Text</a>)
|
|
51
|
-
result = result.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (match, text, url) => {
|
|
52
|
-
return `<a class="markdown_link" href="${url}">${text}</a>`;
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
// Convert images (e.g.,  => <img src="URL" alt="Alt" />)
|
|
56
|
-
result = result.replace(/!\[([^\]]+)\]\(([^)]+)\)/g, (match, alt, src) => {
|
|
57
|
-
return `<img class="markdown_image" src="${src}" alt="${alt}" />`;
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
// Convert unordered lists (e.g., * Item => <ul><li>Item</li></ul>)
|
|
61
|
-
result.split("\n").forEach((line, index, arr) => {
|
|
62
|
-
if (line.match(/^\s*-\s+(.*?)$/gm)) {
|
|
63
|
-
if (index === 0 || !arr[index - 1].match(/^\s*-\s+(.*?)$/gm)) {
|
|
64
|
-
result = result.replace(
|
|
65
|
-
line,
|
|
66
|
-
`<ul class="markdown_unordered" style="list-style-type:disc;list-style:inside"><li>${line.replace(
|
|
67
|
-
/^\s*-\s+(.*?)$/gm,
|
|
68
|
-
"$1"
|
|
69
|
-
)}</li>`
|
|
70
|
-
);
|
|
71
|
-
} else if (
|
|
72
|
-
index === arr.length - 1 ||
|
|
73
|
-
!arr[index + 1].match(/^\s*-\s+(.*?)$/gm)
|
|
74
|
-
) {
|
|
75
|
-
result = result.replace(
|
|
76
|
-
line,
|
|
77
|
-
`<li>${line.replace(/^\s*-\s+(.*?)$/gm, "$1")}</li></ul>`
|
|
78
|
-
);
|
|
79
|
-
} else {
|
|
80
|
-
result = result.replace(
|
|
81
|
-
line,
|
|
82
|
-
`<li>${line.replace(/^\s*-\s+(.*?)$/gm, "$1")}</li>`
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
// Convert ordered lists (e.g., 1. Item => <ol><li>Item</li></ol>) in order
|
|
89
|
-
|
|
90
|
-
result.split("\n").forEach((line, index, arr) => {
|
|
91
|
-
if (line.match(/^\s*\d+\.\s+(.*?)$/gm)) {
|
|
92
|
-
if (index === 0 || !arr[index - 1].match(/^\s*\d+\.\s+(.*?)$/gm)) {
|
|
93
|
-
result = result.replace(
|
|
94
|
-
line,
|
|
95
|
-
`<ol class="markdown_ordered" style="list-style-type:decimal;"><li>${line.replace(
|
|
96
|
-
/^\s*\d+\.\s+(.*?)$/gm,
|
|
97
|
-
"$1"
|
|
98
|
-
)}</li>`
|
|
99
|
-
);
|
|
100
|
-
} else if (
|
|
101
|
-
index === arr.length - 1 ||
|
|
102
|
-
!arr[index + 1].match(/^\s*\d+\.\s+(.*?)$/gm)
|
|
103
|
-
) {
|
|
104
|
-
result = result.replace(
|
|
105
|
-
line,
|
|
106
|
-
`<li>${line.replace(/^\s*\d+\.\s+(.*?)$/gm, "$1")}</li></ol>`
|
|
107
|
-
);
|
|
108
|
-
} else {
|
|
109
|
-
result = result.replace(
|
|
110
|
-
line,
|
|
111
|
-
`<li>${line.replace(/^\s*\d+\.\s+(.*?)$/gm, "$1")}</li>`
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
result = result.replace(/^\s*-\s+(.*?)$/gm, (match, text) => {
|
|
118
|
-
return `<li class="markdown_list_item">${text}</li>`;
|
|
119
|
-
});
|
|
120
|
-
result = result.replace(
|
|
121
|
-
/^\s*---\s*$/gm,
|
|
122
|
-
'<hr class="markdown_horizontal" />'
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
// Convert blockquotes (e.g., > Quote => <blockquote>Quote</blockquote>)
|
|
126
|
-
result = result.replace(/^\s*> (.*)$/gm, (match, text) => {
|
|
127
|
-
return `<blockquote class="markdown_blockquote">${text}</blockquote>`;
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
// Convert tables (e.g., | Header | Cell | => <table><thead><tr><th>Header</th><th>Cell</th></tr></thead></table>)
|
|
131
|
-
result = result.replace(
|
|
132
|
-
/((?: *\|.*?)+)\n((?: *\|.*?)+)/gm,
|
|
133
|
-
(match, header, cell) => {
|
|
134
|
-
const headerCells = header.split("|").slice(1, -1);
|
|
135
|
-
const cells = cell.split("|").slice(1, -1);
|
|
136
|
-
let table = '<table class="markdown_table">';
|
|
137
|
-
table +=
|
|
138
|
-
'<thead class="markdown_table_head"><tr class="markdown_table_row">';
|
|
139
|
-
headerCells.forEach((headerCell) => {
|
|
140
|
-
table += `<th class="markdown_table_header_cell">${headerCell}</th>`;
|
|
141
|
-
});
|
|
142
|
-
table +=
|
|
143
|
-
'</tr></thead><tbody class="markdown_table_body"><tr class="markdown_table_row">';
|
|
144
|
-
cells.forEach((cell) => {
|
|
145
|
-
table += `<td class="markdown_table_body_cell">${cell}</td>`;
|
|
146
|
-
});
|
|
147
|
-
table += "</tr></tbody></table>";
|
|
148
|
-
return table;
|
|
149
|
-
}
|
|
150
|
-
);
|
|
151
|
-
|
|
152
|
-
if (!result.includes("<body>")) {
|
|
153
|
-
throw new Error(
|
|
154
|
-
`Vader Error: You must enclose your html in a body tag for all components. \n\n${result}`
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* @type {string[]}
|
|
159
|
-
* @description - grabbing all className attributes and replace them with class
|
|
160
|
-
*/
|
|
161
|
-
// @ts-ignore
|
|
162
|
-
result = result.replace(/classname/g, "class");
|
|
163
|
-
/**
|
|
164
|
-
* @type {string[]}
|
|
165
|
-
* @description - grabbing all image tags and replace the src attribute with the absolute path
|
|
166
|
-
*/
|
|
167
|
-
// @ts-ignore
|
|
168
|
-
let images = result.match(/<img([^>]*)>/g);
|
|
169
|
-
if (images) {
|
|
170
|
-
for (let i = 0; i < images.length; i++) {
|
|
171
|
-
let image = images[i];
|
|
172
|
-
let src = image.match(/src="([^"]*)"/);
|
|
173
|
-
let alt = image.match(/alt="([^"]*)"/);
|
|
174
|
-
|
|
175
|
-
if (!alt && !result.includes("<!-- #vader-disable_accessibility -->")) {
|
|
176
|
-
throw new Error(
|
|
177
|
-
`Vader Error: You must include an alt attribute in the image tag \n\n${image} of class ${e.data.name}. `
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
if (src) {
|
|
181
|
-
src.forEach((s) => {
|
|
182
|
-
if (
|
|
183
|
-
!s.includes("http") &&
|
|
184
|
-
!result.includes("<!-- #vader-disable_relative-paths -->")
|
|
185
|
-
) {
|
|
186
|
-
result = result.replace(`src="${s}"`, `src="${l}/${s}"`);
|
|
187
|
-
} else if (
|
|
188
|
-
!s.includes("http") &&
|
|
189
|
-
s.startsWith(".") &&
|
|
190
|
-
!result.includes("<!-- #vader-disable_relative-paths -->")
|
|
191
|
-
) {
|
|
192
|
-
throw new Error(
|
|
193
|
-
`Vader Error: You cannot use absolute paths since relative paths are not disabled in ${e.data.file}. Use relative paths instead. \n\n${s}`
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
let href = result.match(/href="([^"]*)"/g);
|
|
202
|
-
if (href) {
|
|
203
|
-
while (href.length) {
|
|
204
|
-
let h = href.pop();
|
|
205
|
-
// @ts-ignore
|
|
206
|
-
h = h.replace('href="', "").replace('"', "");
|
|
207
|
-
if (
|
|
208
|
-
!h.includes("http") &&
|
|
209
|
-
!result.includes("<!-- #vader-disable_relative-paths -->")
|
|
210
|
-
) {
|
|
211
|
-
result = result.replace(`href="${h}"`, `href="#${h}"`);
|
|
212
|
-
} else if (
|
|
213
|
-
!h.includes("http") &&
|
|
214
|
-
h.startsWith(".") &&
|
|
215
|
-
!result.includes("<!-- #vader-disable_relative-paths -->")
|
|
216
|
-
) {
|
|
217
|
-
throw new Error(
|
|
218
|
-
`Vader Error: You cannot use absolute paths since relative paths are not disabled in ${e.data.file}. Use relative paths instead. \n\n${h}`
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
let time_ended = Date.now();
|
|
225
|
-
let time_taken = time_ended - time_started;
|
|
226
|
-
let hasran = false;
|
|
227
|
-
if (l.includes("localhost") || (l.includes("127.0.0.1") && !hasran)) {
|
|
228
|
-
hasran = true;
|
|
229
|
-
result += `\$\{console.log('%c${e.data.name} component rendered in ${time_taken}ms')\}`;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const d = result.split("<script>");
|
|
233
|
-
|
|
234
|
-
if (d) {
|
|
235
|
-
d.forEach((scriptTag, index) => {
|
|
236
|
-
if (index === 0) {
|
|
237
|
-
result = scriptTag;
|
|
238
|
-
} else {
|
|
239
|
-
if (scriptTag.includes("// <![CDATA[ <-- For SVG support")) {
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
let script = scriptTag.split("</script>")[0];
|
|
243
|
-
js += script;
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
let jstemplates = result.match(/(\$\(.*?\))/gs);
|
|
249
|
-
if (jstemplates) {
|
|
250
|
-
while (jstemplates.length) {
|
|
251
|
-
let jstemplate = jstemplates.pop();
|
|
252
|
-
// @ts-ignore
|
|
253
|
-
result = result.replace(
|
|
254
|
-
// @ts-ignore
|
|
255
|
-
jstemplate,
|
|
256
|
-
// @ts-ignore
|
|
257
|
-
`$\{${jstemplate.replace("$(", "").replace(")", "")}\}`
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
let title = result.match(/@title '([^>]*)';/);
|
|
263
|
-
if (title) {
|
|
264
|
-
let t = title[1];
|
|
265
|
-
let ti = `{document.title = "${t}", ""}`;
|
|
266
|
-
result = result.replace(title[0], "$" + ti);
|
|
267
|
-
}
|
|
268
|
-
// @ts-ignore
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
let styles = result.match(/@style{([^>]*)};/gs);
|
|
272
|
-
|
|
273
|
-
if (styles) {
|
|
274
|
-
for (let i = 0; i < styles.length; i++) {
|
|
275
|
-
// make sure its in a tag
|
|
276
|
-
|
|
277
|
-
if (!styles[i].includes("style")) {
|
|
278
|
-
continue;
|
|
279
|
-
}
|
|
280
|
-
let style = styles[i];
|
|
281
|
-
console.log(style)
|
|
282
|
-
|
|
283
|
-
let css = style.replace("@style{", "").replace("};", "");
|
|
284
|
-
// @ts-ignore
|
|
285
|
-
css = css.replaceAll(",", ";");
|
|
286
|
-
// @ts-ignore
|
|
287
|
-
css = css.replaceAll(/[A-Z]/g, (match) => {
|
|
288
|
-
return `-${match.toLowerCase()}`;
|
|
289
|
-
}
|
|
290
|
-
);
|
|
291
|
-
//@ts-ignore
|
|
292
|
-
css = css.replaceAll(/'/g, " ");
|
|
293
|
-
result = result.replace(style, `style="${css}"`);
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
let stylsheet = result.match(/@stylesheet{([^>]*)};/);
|
|
300
|
-
if (stylsheet) {
|
|
301
|
-
let styles = stylsheet[1];
|
|
302
|
-
/**
|
|
303
|
-
* @stylesheet{
|
|
304
|
-
* body:{
|
|
305
|
-
* backgroundColor: red;
|
|
306
|
-
*
|
|
307
|
-
* }
|
|
308
|
-
* }
|
|
309
|
-
*/
|
|
310
|
-
|
|
311
|
-
// @ts-ignore
|
|
312
|
-
let css = styles.replaceAll(" ", "");
|
|
313
|
-
css = css.replaceAll(",", ";");
|
|
314
|
-
css = css.replaceAll(/[A-Z]/g, (match) => {
|
|
315
|
-
return `-${match.toLowerCase()}`;
|
|
316
|
-
}
|
|
317
|
-
);
|
|
318
|
-
css = css.replaceAll(/'/g, " ");
|
|
319
|
-
|
|
320
|
-
result = result.replace(stylsheet[0], `<style>${css}</style>`);
|
|
321
|
-
}
|
|
322
|
-
postMessage({
|
|
323
|
-
template: `<div data-component=${e.data.name}>${result}</div>`,
|
|
324
|
-
js: js ? js : ""
|
|
325
|
-
});
|
|
326
|
-
};
|