vaderjs 1.3.2 → 1.3.3-122198a8b18b-hotfix
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 +247 -0
- package/client/index.js +705 -0
- package/package.json +28 -20
- package/runtime/index.html +20 -0
- package/runtime/router.js +1 -0
- package/runtime/vader.js +1 -0
- package/vader.js +1342 -1233
- package/.vscode/settings.json +0 -5
- package/.vscode/vaderjs.autosense.json +0 -5
- package/index.js +0 -12
- package/jsconfig.json +0 -17
- package/readme.md +0 -262
- package/tsconfig.json +0 -18
- package/vader-min.js +0 -1
- package/vaderRouter.js +0 -231
- package/worker-min.js +0 -1
- package/worker.js +0 -226
package/worker.js
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
|
|
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
|
-
}
|
|
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
|
-
}
|
|
25
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
});
|
|
46
|
-
|
|
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.,  => <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>`);
|
|
76
|
-
}
|
|
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>`);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
});
|
|
104
|
-
|
|
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>`;
|
|
113
|
-
});
|
|
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
|
-
|
|
122
|
-
|
|
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]}`)
|
|
151
|
-
}
|
|
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
|
-
|
|
157
|
-
// @ts-ignore
|
|
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{
|
|
168
|
-
// @ts-ignore
|
|
169
|
-
console.log('already cached', caches.match(`${l}/${src[1]}`))
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
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}`)
|
|
184
|
-
}
|
|
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
|
|
206
|
-
}
|
|
207
|
-
let script = scriptTag.split('</script>')[0];
|
|
208
|
-
js += script;
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
|
|
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
|
-
}
|