vaderjs 1.3.3-alpha-17 → 1.3.3-alpha-19

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/client/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  window.params = {};
3
3
  window.Vader = {
4
- version: "1.3.3",
4
+ version: "1.3.2",
5
5
  };
6
6
 
7
7
  let errors = {
@@ -42,12 +42,6 @@ let invokes = []
42
42
  let hasran = [];
43
43
  let states = {};
44
44
  let mounts = [];
45
- /**
46
- * @method strictMount
47
- * @description This method allows you to call a function only when a component has been mounted
48
- * @param {*} key
49
- * @param {*} callback
50
- */
51
45
  export const strictMount = (key, callback) => {
52
46
  let interval = setInterval(() => {
53
47
  if(mounts.find(mount => mount.key === key)
@@ -61,11 +55,54 @@ export const strictMount = (key, callback) => {
61
55
  },0);
62
56
  };
63
57
 
64
-
58
+ window.delegate = (event) => {
59
+ return event.detail.target
60
+ }
65
61
 
66
62
  let components = {};
67
63
 
68
-
64
+ let style = document.createElement("style");
65
+ document.head.appendChild(style);
66
+
67
+ const parseStyles = async (styles, className = '') => {
68
+ let css = await fetch(styles).then((res) => res.text());
69
+ let classes = css.split("}");
70
+ let parsedClasses = {};
71
+ classes.forEach((cls) => {
72
+
73
+ let name = cls.split(".")[1];
74
+ let value = cls.split("{")[1]
75
+ let keys = value.split(";");
76
+ let newKeys = [];
77
+ keys.forEach((key) => {
78
+ if (key.includes(":")) {
79
+ let newKey = key.split(":")[0].trim();
80
+ let newValue = key.split(":")[1].trim();
81
+ newKeys.push(`${newKey}: "${newValue}"`);
82
+ }
83
+ });
84
+ value = `{${newKeys.join(",")}}`;
85
+
86
+
87
+ parsedClasses[name] = JSON.stringify(value);
88
+ });
89
+ return parsedClasses;
90
+ };
91
+
92
+
93
+ export const stylis = {
94
+ /**
95
+ * @method create
96
+ * @param {*} styles
97
+ * @returns {Object} classes
98
+ * @description This method allows you to create css classes from an object
99
+ */
100
+ create: async (/**@type {string} */ styles) => {
101
+
102
+ return await parseStyles(styles);
103
+ },
104
+ };
105
+
69
106
  /**
70
107
  * @method mem
71
108
  * @param {Component} component
@@ -101,7 +138,18 @@ export const mem = (/**@type {Component}**/ component) => {
101
138
 
102
139
  let functions = {};
103
140
 
104
-
141
+ export const invoke = (func, params) => {
142
+ let name = func.name;
143
+
144
+ window[name] = function (params) {
145
+ return func(params);
146
+ }
147
+ window[name] = window[name].bind(this);
148
+
149
+
150
+ return `${name}(${params})`;
151
+
152
+ };
105
153
 
106
154
  /**
107
155
  * Represents a component in the Vader framework.
@@ -114,37 +162,15 @@ export class Component {
114
162
  this.state = {};
115
163
  this.key = null;
116
164
  this.components = {};
117
- this.mounted = false;
118
- /**
119
- * @private
120
- */
121
- this.checkIFMounted();
165
+ this.mounted = false;
122
166
  this.currenthtml = null;
123
- /**
124
- * @private
125
- */
126
167
  window.listeners = [];
127
- /**
128
- * @private
129
- */
130
168
  this.functionMap = new Map();
131
- /**
132
- * @private
133
- */
134
169
  this.freeMemoryFromFunctions();
135
- /**
136
- * @private
137
- */
138
170
  this.memoizes = []
139
171
  this.children = []
140
- /**
141
- * @property {Object} props - The component props.
142
- */
143
- this.props = {}
144
172
  }
145
- /**
146
- * @private
147
- */
173
+
148
174
  createComponent(/**@type {Component}**/component, props, children) {
149
175
 
150
176
  if (!component) {
@@ -154,7 +180,20 @@ export class Component {
154
180
  throw new Error('new components must have a key')
155
181
  }
156
182
  let comp = new component();
157
-
183
+ Object.keys(props).forEach((key) => {
184
+ // some props are this.bind inside of "" so we need to handle that
185
+ let newFunc = props[key].match(/this.bind\((.*)\)/gs);
186
+ if (newFunc) {
187
+ newFunc = newFunc[0].replace(/this.bind\((.*)\)/gs, "$1");
188
+ newFunc = newFunc.split('`')[1]
189
+ props[key] = this.bind(newFunc, { jsx: true, params: props[key], ref: props.ref });
190
+ return
191
+ }
192
+
193
+
194
+
195
+ props[key] = props[key].toString().replace('"', '').replace("'", '').replace('${', '').replace('}', '')
196
+ });
158
197
  comp['props'] = props;
159
198
  comp.children = children;
160
199
  comp.props.children = children.join('')
@@ -164,9 +203,6 @@ export class Component {
164
203
  this.children.push(comp)
165
204
  return this.components[props.key]
166
205
  }
167
- /**
168
- * @private
169
- */
170
206
  memoize(/**@type {Component}**/component){
171
207
  if(!component.key){
172
208
  throw new Error('Component must have a static key')
@@ -187,9 +223,6 @@ export class Component {
187
223
 
188
224
  return `<div key="${component.key}">${h}</div>`
189
225
  }
190
- /**
191
- * @private
192
- */
193
226
  parseStyle(styles){
194
227
  let css = ''
195
228
  Object.keys(styles).forEach((key) => {
@@ -199,9 +232,6 @@ export class Component {
199
232
  })
200
233
  return css
201
234
  }
202
- /**
203
- * @private
204
- */
205
235
  bindMount(){
206
236
  mounts.push(this)
207
237
  }
@@ -268,15 +298,13 @@ export class Component {
268
298
  * @param {string} p - The parameter.
269
299
  * @param {string} ref - The reference.
270
300
  * @returns {string} - A valid inline JS function call.
271
- * @private
272
301
  */
273
302
  bind(funcData, d) {
274
303
 
275
304
  const name = `func_${crypto ? crypto.getRandomValues(new Uint32Array(1))[0] : Math.random()}`;
276
305
 
277
306
  var dynamicFunction = (params) => {
278
- let func = new Function(`return (async (${params}) => {
279
- console.log('called')
307
+ let func = new Function(`return (async () => {
280
308
  ${funcData}
281
309
  })()`);
282
310
  func = func.bind(this);
@@ -324,7 +352,6 @@ export class Component {
324
352
  * Calls a function with the specified parameters. and dispatches an event.
325
353
  * @param {string} func - The function name.
326
354
  * @param {...*} params - The function parameters.
327
- * @private
328
355
  */
329
356
  callFunction(func, isInlineJsx, ...params) {
330
357
  if(!isInlineJsx && params[0] && params[0].detail){
@@ -342,7 +369,6 @@ export class Component {
342
369
  * @param {string} params - The function parameters.
343
370
  * @param {boolean} [isInlineJsx=false] - Indicates if the function is an inline JSX.
344
371
  * @returns {string} - The function call.
345
- * @private
346
372
  */
347
373
  useFunction(func, params, isInlineJsx = false) {
348
374
  const sanitizedFuncName = func.name.trim().replace(/\s+/g, '_');
@@ -514,20 +540,6 @@ export const useState = (initialState) => {
514
540
  return [value, (newValue) => {}];
515
541
  };
516
542
 
517
- export const useRef = (initialState) => {
518
- let value = initialState;
519
- return {
520
- /**
521
- * @property {Bind} bind - Bind the current ref key to the element
522
- */
523
- bind: key,
524
- /**
525
- * @property {Function} current - Get the current ref value - or the element with the ref key
526
- */
527
- current: () => document.querySelector(`[ref="${key}"]`) || value,
528
- }
529
- }
530
-
531
543
  const constants = {};
532
544
  let constantCounter = 0;
533
545
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "vaderjs",
3
3
  "description": "A Reactive library aimed to helping you build reactive applications inspired by react.js",
4
4
  "module": "vader.js",
5
- "version": "1.3.3-alpha-17",
5
+ "version": "1.3.3-alpha-19",
6
6
  "bin": {
7
7
  "vader": "./vader.js"
8
8
  },
@@ -5,7 +5,7 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
6
  <title>Vaderjs v1.3.3</title>
7
7
  <meta name="description" content="Vader.js is a modern web framework for building web applications.">
8
- <link rel="shortcut icon" href="https://raw.githubusercontent.com/Postr-Inc/Vader.js/vader1.3.3-beta/logo.png" type="image/x-icon">
8
+ <link rel="shortcut icon" href="https://raw.githubusercontent.com/Postr-Inc/Vader.js/main/logo.png" type="image/x-icon">
9
9
  </head>
10
10
  <body>
11
11
  <div id="root"></div>
package/runtime/router.js CHANGED
@@ -198,6 +198,9 @@ class VaderRouter{
198
198
  });
199
199
  }
200
200
  },
201
+ redirect: (path) => {
202
+ window.location.hash = path;
203
+ },
201
204
  render: async (/**@type {Component} */ Component, req, res) => {
202
205
 
203
206
  if(!Component.default || !Component.constructor){
package/runtime/vader.js CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  window.params = {};
3
3
  window.Vader = {
4
- version: "1.3.3",
4
+ version: "1.3.2",
5
5
  };
6
6
 
7
7
  let errors = {
@@ -42,12 +42,6 @@ let invokes = []
42
42
  let hasran = [];
43
43
  let states = {};
44
44
  let mounts = [];
45
- /**
46
- * @method strictMount
47
- * @description This method allows you to call a function only when a component has been mounted
48
- * @param {*} key
49
- * @param {*} callback
50
- */
51
45
  export const strictMount = (key, callback) => {
52
46
  let interval = setInterval(() => {
53
47
  if(mounts.find(mount => mount.key === key)
@@ -61,11 +55,54 @@ export const strictMount = (key, callback) => {
61
55
  },0);
62
56
  };
63
57
 
64
-
58
+ window.delegate = (event) => {
59
+ return event.detail.target
60
+ }
65
61
 
66
62
  let components = {};
67
63
 
68
-
64
+ let style = document.createElement("style");
65
+ document.head.appendChild(style);
66
+
67
+ const parseStyles = async (styles, className = '') => {
68
+ let css = await fetch(styles).then((res) => res.text());
69
+ let classes = css.split("}");
70
+ let parsedClasses = {};
71
+ classes.forEach((cls) => {
72
+
73
+ let name = cls.split(".")[1];
74
+ let value = cls.split("{")[1]
75
+ let keys = value.split(";");
76
+ let newKeys = [];
77
+ keys.forEach((key) => {
78
+ if (key.includes(":")) {
79
+ let newKey = key.split(":")[0].trim();
80
+ let newValue = key.split(":")[1].trim();
81
+ newKeys.push(`${newKey}: "${newValue}"`);
82
+ }
83
+ });
84
+ value = `{${newKeys.join(",")}}`;
85
+
86
+
87
+ parsedClasses[name] = JSON.stringify(value);
88
+ });
89
+ return parsedClasses;
90
+ };
91
+
92
+
93
+ export const stylis = {
94
+ /**
95
+ * @method create
96
+ * @param {*} styles
97
+ * @returns {Object} classes
98
+ * @description This method allows you to create css classes from an object
99
+ */
100
+ create: async (/**@type {string} */ styles) => {
101
+
102
+ return await parseStyles(styles);
103
+ },
104
+ };
105
+
69
106
  /**
70
107
  * @method mem
71
108
  * @param {Component} component
@@ -101,7 +138,18 @@ export const mem = (/**@type {Component}**/ component) => {
101
138
 
102
139
  let functions = {};
103
140
 
104
-
141
+ export const invoke = (func, params) => {
142
+ let name = func.name;
143
+
144
+ window[name] = function (params) {
145
+ return func(params);
146
+ }
147
+ window[name] = window[name].bind(this);
148
+
149
+
150
+ return `${name}(${params})`;
151
+
152
+ };
105
153
 
106
154
  /**
107
155
  * Represents a component in the Vader framework.
@@ -114,37 +162,15 @@ export class Component {
114
162
  this.state = {};
115
163
  this.key = null;
116
164
  this.components = {};
117
- this.mounted = false;
118
- /**
119
- * @private
120
- */
121
- this.checkIFMounted();
165
+ this.mounted = false;
122
166
  this.currenthtml = null;
123
- /**
124
- * @private
125
- */
126
167
  window.listeners = [];
127
- /**
128
- * @private
129
- */
130
168
  this.functionMap = new Map();
131
- /**
132
- * @private
133
- */
134
169
  this.freeMemoryFromFunctions();
135
- /**
136
- * @private
137
- */
138
170
  this.memoizes = []
139
171
  this.children = []
140
- /**
141
- * @property {Object} props - The component props.
142
- */
143
- this.props = {}
144
172
  }
145
- /**
146
- * @private
147
- */
173
+
148
174
  createComponent(/**@type {Component}**/component, props, children) {
149
175
 
150
176
  if (!component) {
@@ -154,7 +180,7 @@ export class Component {
154
180
  throw new Error('new components must have a key')
155
181
  }
156
182
  let comp = new component();
157
-
183
+
158
184
  comp['props'] = props;
159
185
  comp.children = children;
160
186
  comp.props.children = children.join('')
@@ -164,9 +190,6 @@ export class Component {
164
190
  this.children.push(comp)
165
191
  return this.components[props.key]
166
192
  }
167
- /**
168
- * @private
169
- */
170
193
  memoize(/**@type {Component}**/component){
171
194
  if(!component.key){
172
195
  throw new Error('Component must have a static key')
@@ -187,9 +210,6 @@ export class Component {
187
210
 
188
211
  return `<div key="${component.key}">${h}</div>`
189
212
  }
190
- /**
191
- * @private
192
- */
193
213
  parseStyle(styles){
194
214
  let css = ''
195
215
  Object.keys(styles).forEach((key) => {
@@ -199,9 +219,6 @@ export class Component {
199
219
  })
200
220
  return css
201
221
  }
202
- /**
203
- * @private
204
- */
205
222
  bindMount(){
206
223
  mounts.push(this)
207
224
  }
@@ -268,15 +285,14 @@ export class Component {
268
285
  * @param {string} p - The parameter.
269
286
  * @param {string} ref - The reference.
270
287
  * @returns {string} - A valid inline JS function call.
271
- * @private
272
288
  */
273
- bind(funcData, d) {
289
+ bind(funcData,jsx,ref, params) {
274
290
 
291
+ console.log(jsx)
275
292
  const name = `func_${crypto ? crypto.getRandomValues(new Uint32Array(1))[0] : Math.random()}`;
276
293
 
277
294
  var dynamicFunction = (params) => {
278
- let func = new Function(`return (async (${params}) => {
279
- console.log('called')
295
+ let func = new Function(`return (async () => {
280
296
  ${funcData}
281
297
  })()`);
282
298
  func = func.bind(this);
@@ -307,15 +323,15 @@ export class Component {
307
323
  };
308
324
 
309
325
  // Return a valid inline js function call
310
- return d.jsx ? dynamicFunction : `
326
+ return jsx ? dynamicFunction : `
311
327
  ((event) => {
312
- event.target.setAttribute('data-ref', '${d.ref}');
328
+ event.target.setAttribute('data-ref', '${ref}}');
313
329
  let reference = event.target.getAttribute('data-ref');
314
330
  event.target.eventData = event;
315
331
  let domquery = queryRef(reference);
316
332
  domquery.eventData = event;
317
333
  domquery.eventData.detail.target = domquery;
318
- call('${name}', {event:domquery.eventData}, '${d.params}')
334
+ call('${name}', {event:domquery.eventData}, '${params}')
319
335
  })(event)
320
336
  `;
321
337
  }
@@ -324,7 +340,6 @@ export class Component {
324
340
  * Calls a function with the specified parameters. and dispatches an event.
325
341
  * @param {string} func - The function name.
326
342
  * @param {...*} params - The function parameters.
327
- * @private
328
343
  */
329
344
  callFunction(func, isInlineJsx, ...params) {
330
345
  if(!isInlineJsx && params[0] && params[0].detail){
@@ -342,7 +357,6 @@ export class Component {
342
357
  * @param {string} params - The function parameters.
343
358
  * @param {boolean} [isInlineJsx=false] - Indicates if the function is an inline JSX.
344
359
  * @returns {string} - The function call.
345
- * @private
346
360
  */
347
361
  useFunction(func, params, isInlineJsx = false) {
348
362
  const sanitizedFuncName = func.name.trim().replace(/\s+/g, '_');
@@ -514,20 +528,6 @@ export const useState = (initialState) => {
514
528
  return [value, (newValue) => {}];
515
529
  };
516
530
 
517
- export const useRef = (initialState) => {
518
- let value = initialState;
519
- return {
520
- /**
521
- * @property {Bind} bind - Bind the current ref key to the element
522
- */
523
- bind: key,
524
- /**
525
- * @property {Function} current - Get the current ref value - or the element with the ref key
526
- */
527
- current: () => document.querySelector(`[ref="${key}"]`) || value,
528
- }
529
- }
530
-
531
531
  const constants = {};
532
532
  let constantCounter = 0;
533
533
 
package/vader.js CHANGED
@@ -25,18 +25,17 @@ function Compiler(func) {
25
25
  let savedfuncnames = [];
26
26
  let functions = string
27
27
  .match(
28
- /(?:const|let|var)?\s*([a-zA-Z0-9_-]+)\s*(?:=|function)\s*\(([^)]*)\)|function\s*([a-zA-Z0-9_-]+)\s*\(([^)]*)\)|(?:const|let|var)?\s*([a-zA-Z0-9_-]+)\s*=\s*\(([^)]*)\)/gs
28
+ /(?:const|let)\s*([a-zA-Z0-9_-]+)\s*=\s*function\s*\(([^)]*)\)|function\s*([a-zA-Z0-9_-]+)\s*\(([^)]*)\)/gs
29
29
  )
30
30
  ?.map((match) => match.trim());
31
31
 
32
-
33
32
  let functionNames = [];
34
33
 
35
34
  if (functions) {
36
35
  functions.forEach((func) => {
37
36
  if (
38
37
  !func.match(
39
- /(?:const|let|var)?\s*([a-zA-Z0-9_-]+)\s*(?:=|function)\s*\(([^)]*)\)|function\s*([a-zA-Z0-9_-]+)\s*\(([^)]*)\)|(?:const|let|var)?\s*([a-zA-Z0-9_-]+)\s*=\s*\(([^)]*)\)/gs
38
+ /(?:const|let)\s*([a-zA-Z0-9_-]+)\s*=\s*function\s*\(([^)]*)\)|function\s*([a-zA-Z0-9_-]+)\s*\(([^)]*)\)/gs
40
39
  )
41
40
  ) {
42
41
  return;
@@ -73,6 +72,7 @@ function Compiler(func) {
73
72
  let childs = [];
74
73
 
75
74
 
75
+
76
76
  function extractAttributes(code) {
77
77
  // Match elements with opening tags
78
78
  const elementRegex = /<([a-zA-Z0-9_-]+)([^>]*)>/gs;
@@ -134,12 +134,11 @@ function Compiler(func) {
134
134
  if (functionNames.length > 0) {
135
135
  functionNames.forEach((name) => {
136
136
  string.split("\n").forEach((line) => {
137
- if (line.includes(name) && line.includes("function") || line.includes(name) && line.includes("=>")) {
137
+ if (line.includes(name) && line.includes("function")) {
138
138
  line = line.trim();
139
139
  line = line.replace(/\s+/g, " ");
140
140
 
141
- let ps = line.split("(")[1].split(")")[0].trim();
142
-
141
+ let ps = line.split("(").slice(1).join("(").split(")")[0].trim();
143
142
 
144
143
  // remove comments
145
144
  ps = ps.match(/\/\*.*\*\//gs)
@@ -160,7 +159,6 @@ function Compiler(func) {
160
159
  let params = hasParams
161
160
  ? line.split("(")[1].split(")")[0].trim()
162
161
  : null;
163
-
164
162
 
165
163
  if (
166
164
  functionparams.length > 0 &&
@@ -187,9 +185,8 @@ function Compiler(func) {
187
185
  } ${params || null}${isJSXComponent ? "" : ","} true ${isJSXComponent ? "" : ","
188
186
  } '${ref}')`;
189
187
 
190
- console.log(replacement)
191
188
  newvalue = newvalue.replace(
192
- line,
189
+ hasParams ? `${name}(${params})` : name,
193
190
  `this.callFunction(\${${replacement}}, ${isJSXComponent ? true : false
194
191
  }, event,${params || null})`
195
192
  );
@@ -223,11 +220,11 @@ function Compiler(func) {
223
220
  otherdata["ref"] = ref;
224
221
 
225
222
  newvalue = newvalue.split('\n').map(line => line.trim() ? line.trim() + ';' : line).join('\n');
226
- newvalue = newvalue.replaceAll('"', "'")
227
- otherdata = JSON.stringify(otherdata).replaceAll('"', "'")
228
- let newatribute = `${attributeName}="\${this.bind(\`${newvalue}\`${isJSXComponent ? "" : ","}${otherdata} )}"`;
223
+
229
224
 
225
+ let newatribute = `${attributeName}="\${this.bind(\`${newvalue}\`, ${isJSXComponent ? true : false}, '${ref}', ${params || null})}"`
230
226
 
227
+
231
228
  attribute[attributeName] = {
232
229
  old: old,
233
230
  new: newatribute,
@@ -261,7 +258,7 @@ function Compiler(func) {
261
258
  otherdata["ref"] = ref;
262
259
  // since js is all in one line split it
263
260
  newvalue = newvalue.split('\n').map(line => line.trim() ? line.trim() + ';' : line).join('\n');
264
- let newattribute = `${attributeName}="\${this.bind(\`${newvalue}\` ${isJSXComponent ? "" : ","}${JSON.stringify(otherdata)} )}"`;
261
+ let newattribute = `${attributeName}="\${this.bind(\`${newvalue}\`, ${isJSXComponent ? true : false}, '${ref}', ${params || null})}"`
265
262
  newattribute = newattribute.replace(/\s+/g, " ")
266
263
  string = string.replace(old, newattribute);
267
264
  }
@@ -330,18 +327,19 @@ function Compiler(func) {
330
327
  value == "undefined" ? (value = '"') : (value = value);
331
328
  key == 'style' ? value = `{this.parseStyle({${value.split('{{')[1].split('}}')[0]}})}` : null
332
329
 
333
- value = `="\$${value}"`;
334
- string = string.replace(oldvalue, value);
330
+
331
+ value = `="\$${value}",`;
332
+ string = string.replaceAll(oldvalue, value);
335
333
 
336
334
  } else if (value && value.includes("`")) {
337
335
  value = value.replace("=", "");
338
336
 
339
- value = `"\$${value}"`;
337
+ value = `"\$${value}",`;
340
338
  string = string.replace(oldvalue, value);
341
339
 
342
340
  }
343
341
  } else if (value && value.new) {
344
- let newvalue = value.new;
342
+ let newvalue = value.new + ",";
345
343
  let old = value.old;
346
344
  string = string.replace(old, newvalue);
347
345
  }
@@ -477,8 +475,6 @@ function Compiler(func) {
477
475
  return array;
478
476
  };
479
477
 
480
- string = string.replaceAll('vaderjs/client', './vader.js')
481
-
482
478
  // capture <Component />, <Component></Component>, and <Component>content</Component>
483
479
 
484
480
  // Example usage
@@ -498,8 +494,9 @@ function Compiler(func) {
498
494
  let myChildrens = [];
499
495
 
500
496
  let name = component.split("<")[1].split(">")[0].split(" ")[0].replace("/", "");
501
- let props = component.split(`<${name}`)[1].split(">")[0].trim();
502
-
497
+ let props = component.split(`<${name}`)[1].split(">")[0].trim()
498
+ console.log(props)
499
+
503
500
  let savedname = name;
504
501
  let children = props
505
502
  ? component
@@ -534,18 +531,33 @@ function Compiler(func) {
534
531
  myChildrens.push(child.children);
535
532
  }
536
533
  });
534
+
535
+
537
536
 
538
-
539
- // turn props into object
540
- props = props.replaceAll('=', ':').replaceAll('/', '')
537
+
538
+ props = props
539
+ .replaceAll("=", ":")
540
+ .replaceAll('"', "'")
541
+ //fix key:'value' to key:'value', only if value ="value"
541
542
 
542
- // class="text-red-500" => class:"text-red-500", omit quotes if value is a variable
543
- props = props.replaceAll(/([a-zA-Z0-9_-]+)\s*:\s*("([^"\\]*(\\.[^"\\]*)*)"|'([^'\\]*(\\.[^'\\]*)*)')/gs, (match, p1, p2) => {
544
- return match + ','
545
- });
543
+ .replaceAll(",,", ',')
544
+ .replaceAll("className", "class")
545
+ .replaceAll("classname", "class")
546
+ .replaceAll("'${", "")
547
+ .replaceAll("}'", "")
548
+ .split("$:")
549
+ .join("")
550
+ .replace('/', '')
551
+ // remove trailing ,
552
+ .replace(/,\s*$/, "")
553
+ props = props.replace(/:('[^']*'|"[^"]*")/g, ':$1,');
554
+
555
+
556
+
557
+
546
558
  let replace = "";
547
559
  replace = isChild
548
- ? `this.memoize(this.createComponent(${savedname.replaceAll('/', '')}, {${props}}, [${myChildrens.length > 0 ? myChildrens.join(",") : ""
560
+ ? `this.memoize(this.createComponent(${savedname.replaceAll('/', '')}, ${props}, [${myChildrens.length > 0 ? myChildrens.join(",") : ""
549
561
  }])),`
550
562
  : `\${this.memoize(this.createComponent(${savedname.replaceAll('/', '')}, {${props}}, [${myChildrens.length > 0 ? myChildrens.join(",") : ""
551
563
  }]))}`;
@@ -558,6 +570,7 @@ function Compiler(func) {
558
570
 
559
571
 
560
572
 
573
+ string = string.replaceAll('vaderjs/client', './vader.js')
561
574
  string = string.replaceAll("<>", "`").replaceAll("</>", "`");
562
575
  string = parseComponents(string);
563
576
 
@@ -618,10 +631,8 @@ async function Build() {
618
631
 
619
632
  // Read and compile file content
620
633
  let data = await fs.readFileSync(origin, "utf8");
621
- data = Compiler(data);
622
-
623
- // Write compiled content to the 'dist/pages' directory
624
- console.log(`Compiling ${fileName} to ${obj.url}`)
634
+ data = Compiler(data);
635
+
625
636
  await writer(process.cwd() + "/dist/pages/" + fileName, data);
626
637
 
627
638
  // Generate routing logic
@@ -651,12 +662,13 @@ async function Build() {
651
662
  absolute: true,
652
663
  });
653
664
  scannedVaderFiles.forEach(async (file) => {
654
- file = file.replace(/\\/g, '/');
655
- if(file.includes('index.html') && fs.existsSync(process.cwd() + "/dist/index.html")){
656
- return
657
- }
658
-
665
+ file = file.replace(/\\/g, '/');
666
+
667
+
659
668
  let name = file.split( '/node_modules/vaderjs/runtime/')[1]
669
+ if(file.includes('index.html') && fs.existsSync(process.cwd() + "/dist/" + name)){
670
+ return
671
+ }
660
672
  let data = await reader(file)
661
673
  bundleSize += fs.statSync(file).size;
662
674
  await writer(process.cwd() + "/dist/" + name, data);
@@ -694,12 +706,18 @@ async function Build() {
694
706
  })
695
707
 
696
708
  if (!fs.existsSync(process.cwd() + "/dist/index.html")) {
709
+
697
710
  scannedFiles.forEach(async (file) => {
698
711
  file = file.split(process.cwd() + '/runtime/')[1]
699
712
 
700
713
  if (file === "app.js") {
701
714
  return
702
715
  }
716
+ console.log(`Compiling ${file} to /dist/${file}`)
717
+ if(file.includes('index.html') && fs.existsSync(process.cwd() + "/runtime/" + file)){
718
+ console.log(`Compiling ${file} to /dist/${file}`)
719
+ return
720
+ }
703
721
  bundleSize += fs.statSync(process.cwd() + "/runtime/" + file).size;
704
722
  let data = await reader(process.cwd() + "/runtime/" + file)
705
723
  await writer(process.cwd() + "/dist/" + file, data);
@@ -732,13 +750,17 @@ Vader.js v1.3.3
732
750
  }
733
751
  },
734
752
  );
735
- const watcher2 = watch( process.cwd() + '/src', { recursive: true }, (event, filename) => {
736
- if (event == 'change'
737
- && !globalThis.isBuilding
738
- ) {
739
- Build()
740
- }
741
- });
753
+ const watcher2 = watch(
754
+ process.cwd() + '/src',
755
+ { recursive: true },
756
+ (event, filename) => {
757
+ if (event == 'change'
758
+ && !globalThis.isBuilding
759
+ ) {
760
+ Build()
761
+ }
762
+ },
763
+ );
742
764
  watcher2.on('error', (err) => console.log(err))
743
765
  watcher.on('error', (err) => console.log(err))
744
766