vaderjs 1.3.1 → 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/worker.js DELETED
@@ -1,223 +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
- // 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
- }
75
- }
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
- }
89
- }
90
- });
91
-
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
-
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
- });
102
-
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;
118
- });
119
-
120
-
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}`)
124
- }
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
- */
135
- // @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
-
154
- // @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
- }
170
-
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
203
- }
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(')','')}\}`)
216
- }
217
- }
218
- postMessage({
219
- template: `<div data-component=${e.data.name}>${result}</div>`,
220
- js: js ? js : ''
221
- })
222
-
223
- }