vaderjs 1.4.2-kml56 → 1.4.2-npiml56

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/config/index.ts CHANGED
@@ -26,6 +26,11 @@
26
26
  * @param {string} [config.mode] - The mode for the configuration.
27
27
  * @param {Array} [config.plugins] - The plugins for the configuration.
28
28
  * @param {Object} [config.env] - The environment variables for the configuration.
29
+ * @param {Array} [config.Router] - The router configuration.
30
+ * @param {Object} [config.Router.tls] - The tls configuration - allows you to switch the server to https.
31
+ * @param {string} [config.Router.tls.cert] - The certificate for the tls configuration.
32
+ * @param {string} [config.Router.tls.key] - The key for the tls configuration.
33
+ * @param {Object} [config.Router.headers] - The headers for the router configuration.
29
34
  * @returns {Object} The configured object.
30
35
  */
31
36
  export const defineConfig = (config: {
@@ -46,10 +51,24 @@ export const defineConfig = (config: {
46
51
  outDir?: string,
47
52
  },
48
53
  mode?: string,
54
+ /**
55
+ * @type {any[]}
56
+ * @description Allows you to extend the functionality of vaderjs
57
+ */
49
58
  plugins?: any[]
50
59
  env?: {
51
60
  [key: string]: any
52
- }
61
+ },
62
+ Router?: {
63
+ tls?: {
64
+ cert?: string,
65
+ key?: string
66
+ },
67
+ headers?: {
68
+ [key: string]: string
69
+ }
70
+ },
71
+ [key: string]: any
53
72
  }) => {
54
73
  // add config.env to globalThis.env
55
74
  let env = {}
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "vaderjs",
3
3
  "description": "A reactive framework for building fast and scalable web applications",
4
- "version": "1.4.2-kml56",
5
- "main": "vader.js",
4
+ "version": "1.4.2-npiml56",
6
5
  "author": {
7
6
  "name": "Malikwhitten67",
8
7
  "email": "malikwhitterb@gmail.com"
@@ -14,7 +13,7 @@
14
13
  },
15
14
  "type": "module",
16
15
  "bin":{
17
- "vader":"./vader.js"
16
+ "vader":"./vader_dev.js"
18
17
  },
19
18
  "dependencies": {
20
19
  "ws": "latest"
@@ -8,6 +8,10 @@ const glob = new Glob("/**/*.{ts,tsx,js,jsx}", {
8
8
  */
9
9
  async function generate(){
10
10
  let config = await import(process.cwd() + '/vader.config.js').then((config) => { return config.default })
11
+ if(!config?.env || !config?.env.SSR){
12
+ console.error('\x1b[31m[CloudFlare Functions] \x1b[0m - Please add an SSR environment variable to your vader.config.js file')
13
+ return
14
+ }
11
15
  let start = Date.now()
12
16
  for(var i of glob.scanSync({cwd: process.cwd() + '/routes', absolute: true})){
13
17
  let data = await Bun.file(i).text()
@@ -10,10 +10,40 @@ export class DOMParser {
10
10
  */
11
11
  parseFromString(html) {
12
12
  let doc = new Document();
13
- return {
14
- error: "Not implemented",
15
- }
16
-
13
+ let t = new Bun.Transpiler({
14
+ loader: "tsx", // "js | "jsx" | "ts" | "tsx",
15
+ target: "browser",
16
+ define: {
17
+ "jsxDEV": "Element",
18
+ "jsx": "Element"
19
+ }
20
+ });
21
+
22
+ let el = t.transformSync(`
23
+
24
+ const html = ${html}
25
+ function Doc() {
26
+ return (
27
+ <html>
28
+ <body>${html}</body>
29
+ </html>
30
+ )
31
+ }
32
+ return Doc()
33
+ ` )
34
+ el = el.replaceAll(`jsxDEV`, `Element`)
35
+ let evaluated = eval(`(function(){${el}})()`)
36
+ evaluated.children.forEach((child) => {
37
+ child.outerHTML = child.toString()
38
+ })
39
+ doc.tree = evaluated.children
40
+ doc.body = evaluated.children[0]
41
+ doc.body.outerHTML = evaluated.children[0].toString()
42
+ doc.body.firstChild = evaluated.children[0].children[0]
43
+ doc.documentElement = evaluated
44
+ doc.documentElement.outerHTML = evaluated.children[0].toString()
45
+ this.tree = evaluated.children
46
+ return doc
17
47
  }
18
48
  /**
19
49
  * @description - Returns a string containing the HTML serialization of the element's descendants.
@@ -37,7 +67,7 @@ export class HTMLTextNode {
37
67
  }
38
68
 
39
69
  insertBefore(node) {
40
- this.nodeValue = `${node.toString()}${this.nodeValue}`;
70
+ this.nodeValue = `${node.nodeValue}${this.nodeValue}`;
41
71
  return this;
42
72
  }
43
73
  }
@@ -81,7 +111,7 @@ export class HTMLElement {
81
111
  if (key !== 'style' && key !== 'ref' && !key.startsWith('on')) {
82
112
  props += `${key}="${this.props[key]}" `
83
113
  }
84
- }
114
+ }
85
115
  let children = this.children
86
116
  .map((child) => {
87
117
  return child.toString();
@@ -123,7 +153,9 @@ export class HTMLElement {
123
153
  }
124
154
  })
125
155
  .join("");
126
- return string;
156
+ return string;
157
+
158
+
127
159
  default:
128
160
  break;
129
161
  }
@@ -150,8 +182,8 @@ export class HTMLElement {
150
182
  * @returns {HTMLElement}
151
183
  */
152
184
  setContent(content) {
153
- let textNode = new HTMLTextNode(content);
154
- this.children = [textNode];
185
+ let textNode = new HTMLTextNode(content)
186
+ this.children = [textNode];
155
187
  this.outerHTML = this.toString("outerHTML");
156
188
  this.innerHTML = this.toString("innerHTML");
157
189
  return this;
@@ -319,7 +351,7 @@ export class HTMLElement {
319
351
  this.textContent = this.toString("innerText");
320
352
  this.children.forEach((c) => {
321
353
  if (c.children) {
322
- child = c.children.find((child) => {
354
+ child = c.children.find((child) => {
323
355
  child.outerHTML = child.toString("outerHTML");
324
356
  child.innerHTML = child.toString("innerHTML");
325
357
  return child.tagName === selector;
@@ -407,6 +439,9 @@ export class Document {
407
439
  * @returns {HTMLElement}
408
440
  */
409
441
  createElement(nodeData) {
442
+ if(!nodeData){
443
+ return new HTMLElement("div", {}, [])
444
+ }
410
445
  if (typeof nodeData === 'string') {
411
446
  return new HTMLElement(nodeData, {}, [])
412
447
  }
@@ -526,7 +561,17 @@ function handleStyles(styles, nodeEl) {
526
561
  */
527
562
  export function Element(tag, props = {}, ...children) {
528
563
  if(typeof tag === 'function'){
529
- let el = tag(props, children)
564
+ let childObj = children.map((child) => {
565
+ if (child.tagName === "TEXT_ELEMENT") {
566
+ return new HTMLTextNode(child);
567
+ }
568
+ if (child instanceof HTMLElement) {
569
+ return child;
570
+ }
571
+ return new HTMLElement(child.tagName, child.props, child.children);
572
+ })
573
+ childObj = childObj[0]
574
+ let el = tag({...props, children: childObj})
530
575
  return el
531
576
  }
532
577
  if(props === null){
@@ -592,9 +637,12 @@ export function Element(tag, props = {}, ...children) {
592
637
 
593
638
  node.children = children
594
639
  delete props.children
595
- }
596
-
640
+ }
597
641
  for (var i = 0; i < children.length; i++) {
642
+ if(typeof children[i] === 'undefined'){
643
+ delete children[i]
644
+ continue;
645
+ }
598
646
  if (typeof children[i] === "string" || typeof children[i] === "number") {
599
647
  children[i] = {
600
648
  tagName: "TEXT_ELEMENT",
@@ -607,7 +655,7 @@ export function Element(tag, props = {}, ...children) {
607
655
  } else {
608
656
  if (children[i]) {
609
657
  children[i].parentNode = { tagName: tag, props: props, children: children };
610
- }
658
+ }
611
659
 
612
660
  children[i] = new HTMLElement(children[i].tagName, children[i].props, children[i].children)
613
661
  }