vaderjs 1.4.1-ui7iuy47 → 1.4.2-jpbvml56

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.
Files changed (39) hide show
  1. package/.editorconfig +11 -0
  2. package/.vscode/c_cpp_properties.json +21 -0
  3. package/.vscode/settings.json +12 -0
  4. package/README.md +44 -197
  5. package/binaries/Kalix/index.js +677 -0
  6. package/binaries/compiler/main.js +502 -0
  7. package/binaries/vader.js +74 -0
  8. package/binaries/watcher/hmr.js +41 -0
  9. package/client/index.d.ts +226 -0
  10. package/client/runtime/index.js +1 -0
  11. package/client/runtime/router.js +1 -0
  12. package/config/index.ts +87 -0
  13. package/index.ts +344 -0
  14. package/package.json +13 -25
  15. package/plugins/cloudflare/functions/index.js +102 -0
  16. package/plugins/cloudflare/toCopy/@server/Kalix/index.js +673 -0
  17. package/plugins/cloudflare/toCopy/@server/cloudflare_ssr/index.js +85 -0
  18. package/plugins/cloudflare/toCopy/node_modules/vaderjs/server/index.js +99 -0
  19. package/plugins/cloudflare/toCopy/src/client.js +1 -0
  20. package/plugins/cloudflare/toCopy/src/router.js +1 -0
  21. package/plugins/ssg/index.js +197 -0
  22. package/plugins/tailwind/index.ts +102 -0
  23. package/plugins/vercel/functions/index.ts +8 -0
  24. package/router/index.ts +208 -0
  25. package/server/index.js +143 -0
  26. package/vader_dev.js +177 -0
  27. package/@integrations/ssg.js +0 -189
  28. package/LICENSE +0 -21
  29. package/binaries/IPC/index.js +0 -277
  30. package/binaries/main.js +0 -1464
  31. package/binaries/readme.md +0 -4
  32. package/binaries/watcher.js +0 -74
  33. package/binaries/win32/check.ps1 +0 -7
  34. package/client/index.js +0 -426
  35. package/config/index.js +0 -36
  36. package/logo.png +0 -0
  37. package/runtime/router.js +0 -1
  38. package/runtime/vader.js +0 -1
  39. package/vader.js +0 -230
@@ -0,0 +1,226 @@
1
+ //@ts-nocheck
2
+ declare namespace Vader{
3
+ export let useState: <T>(initialState: T) => [T, (newState: T) => void];
4
+ export let useReducer: <T>(reducer: (state: T, action: any) => T, initialState: T) => [T, (newState: T) => void];
5
+ export const useRef: <T>(initialValue: T | null) => { current: T | null };
6
+ export const Mounted: (fn: () => void) => void;
7
+ }
8
+ declare global {
9
+ /**
10
+ * @type {boolean}
11
+ * @description A boolean value that returns true if the current environment is a server
12
+ */
13
+ const isServer: boolean
14
+ /**
15
+ * @type {boolean}
16
+ * @description Default(true) - A boolean value that lets you opt out of prerendering (Only applies towards using the vaderjs serverside )
17
+ */
18
+ var preRender: boolean
19
+
20
+
21
+ /**
22
+ * @description HTMLTextNode is a global interface that represents a text node
23
+ */
24
+
25
+ interface HTMLTextNode {
26
+ nodeValue: string;
27
+ nodeType: number;
28
+ tagName: string;
29
+ props:{nodeValue: string};
30
+ toString: () => string;
31
+ insertBefore: (child: HTMLTextNode, ref: HTMLTextNode) => void;
32
+ }
33
+ /**
34
+ * @description HTMLElement is a global interface that represents an HTML element
35
+ */
36
+ interface HTMLElement{
37
+ tagName: string;
38
+ id: string;
39
+ nodeType: number;
40
+ classList:{
41
+ add: (className: string) => void;
42
+ remove: (className: string) => void;
43
+ toggle: (className: string) => void;
44
+ contains: (className: string) => boolean;
45
+ }
46
+ props: {
47
+ [key: string]: string;
48
+ }
49
+ children: HTMLElement[];
50
+ outerHTML: string;
51
+ innerHTML: string;
52
+ textContent: string;
53
+ firstChild: HTMLElement | HTMLTextNode | null;
54
+ style?: {
55
+
56
+ display: string;
57
+ position: string;
58
+ top: string;
59
+ left: string;
60
+ right: string;
61
+ bottom: string;
62
+ width: string;
63
+ height: string;
64
+ maxWidth: string;
65
+ maxHeight: string;
66
+ minWidth: string;
67
+ minHeight: string;
68
+ margin: string;
69
+ marginTop: string;
70
+ marginRight: string;
71
+ marginBottom: string;
72
+ marginLeft: string;
73
+ padding: string;
74
+ paddingTop: string;
75
+ paddingRight: string;
76
+ paddingBottom: string;
77
+ paddingLeft: string;
78
+ overflow: string;
79
+ zIndex: string;
80
+ cursor: string;
81
+ textAlign: string;
82
+ fontSize: string;
83
+ fontWeight: string;
84
+ fontStyle: string;
85
+ textDecoration: string;
86
+ lineHeight: string;
87
+ letterSpacing: string;
88
+ textTransform: string;
89
+ backgroundColor: string;
90
+ backgroundImage: string;
91
+ backgroundSize: string;
92
+ backgroundPosition: string;
93
+ backgroundRepeat: string;
94
+ backgroundAttachment: string;
95
+ backgroundClip: string;
96
+ backgroundOrigin: string;
97
+ backgroundBlendMode: string;
98
+ boxShadow: string;
99
+ transition: string;
100
+ transform: string;
101
+ transformOrigin: string;
102
+ transformStyle: string;
103
+ perspective: string;
104
+ perspectiveOrigin: string;
105
+ backfaceVisibility: string;
106
+ filter: string;
107
+ backdropFilter: string;
108
+ mixBlendMode: string;
109
+ border: string;
110
+ borderTop: string;
111
+ borderRight: string;
112
+ borderBottom: string;
113
+ borderLeft: string;
114
+ borderStyle: string;
115
+ borderTopStyle: string;
116
+ borderRightStyle: string;
117
+ borderBottomStyle: string;
118
+ borderLeftStyle: string;
119
+ borderColor: string;
120
+ borderTopColor: string;
121
+ borderRightColor: string;
122
+ borderBottomColor: string;
123
+ borderLeftColor: string;
124
+ borderRadius: string;
125
+ borderTopLeftRadius: string;
126
+ borderTopRightRadius: string;
127
+ borderBottomRightRadius: string;
128
+ borderBottomLeftRadius: string;
129
+ borderWidth: string;
130
+ borderTopWidth: string;
131
+ borderRightWidth: string;
132
+ borderBottomWidth: string;
133
+ borderLeftWidth: string;
134
+
135
+ [key: string]: string;
136
+ }
137
+ attributes: {
138
+ [key: string]: string;
139
+ };
140
+ events: [];
141
+ toString: () => string;
142
+ getAttribute: (attr: string) => string | null;
143
+ appendChild: (child: HTMLElement) => void;
144
+ prepend: (child: HTMLElement) => void;
145
+ append: (...child: HTMLElement[]) => void;
146
+ insertBefore: (node1: HTMLElement, node2: HTMLElement) => void;
147
+ removeChild: (child: HTMLElement) => void;
148
+ querySelector: (selector: string) => HTMLElement | null;
149
+ querySelectorAll: (selector: string) => HTMLElement[];
150
+ }
151
+ }
152
+ interface LastModified {
153
+ date: string;
154
+ time: string;
155
+ parsed: string;
156
+ }
157
+ /**
158
+ * @type {Object}
159
+ * @description The file object
160
+ * @property {string} name - The name of the file
161
+ * @property {string} filetype - The type of the file
162
+ * @property {string} dataUrl - The data url of the file
163
+ * @property {string} text - The text content of the file
164
+ * @property {string} fileUrl - The file url
165
+ * @property {number} filesize - The file size
166
+ * @property {Blob} blob - The file blob
167
+ * @property {LastModified} lastModified - The last modified date
168
+ * @property {string} mimetype - The file mimetype
169
+ */
170
+ interface File {
171
+ name: string;
172
+ filetype: string;
173
+ dataUrl: string;
174
+ fileUrl: string;
175
+ filesize: number;
176
+ lastModified: LastModified;
177
+ mimetype: string;
178
+ }
179
+
180
+ /**
181
+ * @description Returns a stateful value, and a function to update it.
182
+ * @template T
183
+ * @param {T} initialState - The initial state value.
184
+ * @returns {[T, (newState: T) => void]} - A tuple containing the current state value and a function to update the state.
185
+ * @see https://react.dev/reference/react/useState
186
+ */
187
+
188
+ declare const useState: <T>(initialState: T) => [T, (newState: T) => void];
189
+
190
+ /**
191
+ * An alternative to `useState`.
192
+ *
193
+ * `useReducer` is usually preferable to `useState` when you have complex state logic that involves
194
+ * multiple sub-values. It also lets you optimize performance for components that trigger deep
195
+ * updates because you can pass `dispatch` down instead of callbacks.
196
+ *
197
+ * @see https://react.dev/reference/react/useReducer
198
+ */
199
+
200
+ declare const useReducer: <T>(reducer: (state: T, action: any) => T, initialState: T) => [T, (newState: T) => void];
201
+ /**
202
+ * `useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument
203
+ * (`initialValue`). The returned object will persist for the full lifetime of the component.
204
+ *
205
+ * Note that `useRef()` is useful for more than the `ref` attribute. It’s handy for keeping any mutable
206
+ * value around similar to how you’d use instance fields in classes.
207
+ *
208
+ * @see https://react.dev/reference/react/useRef
209
+ */
210
+ declare const useRef: <T>(initialValue: T | null) => {
211
+ current: T extends null ? HTMLElement : T;
212
+ };
213
+
214
+ /**
215
+ * Accepts a function that contains imperative, possibly effectful code.
216
+ *
217
+ * @param {Function} fn Imperative function that can be ran once the component is mounted - (does not apply when running on the server)
218
+ * @returns {void}
219
+ */
220
+
221
+ declare function Mounted(fn: Function): void;
222
+ export { useState, useReducer, useRef, useFile, Mounted, require }
223
+
224
+
225
+
226
+
@@ -0,0 +1 @@
1
+ window.vader={version:"1.0.0"},globalThis.isServer=!1,globalThis.preRender=!1,window.hasRan=[],globalThis.memoizedFunctions=[];const memoizedRefs=[];function calculateDiff(e,t){if(void 0===e||void 0===t)return[];let n=[];if(e?.children.length>0){for(var r=0;r<e.children.length;r++)n.push(...calculateDiff(e.children[r],t.children[r]));return n}if(!e?._isRoot)if(3===e.nodeType&&e.nodeValue!==t.nodeValue)n.push({type:"REPLACE",oldNode:e,newNode:t});else if(1===e.nodeType&&e.innerHTML!==t.innerHTML)n.push({type:"REPLACE",oldNode:e,newNode:t});else if(1===e.nodeType&&e.tagName===t.tagName)for(r=0;r<e.attributes.length;r++)e.attributes[r].value!==t.attributes[r].value&&n.push({type:"PROPS",oldNode:e,newNode:t});return n}function generateJSX(e,t,...n){let r={state:{},mainFunction:e,_key:e.name||Math.random().toString(36).substring(7),$$typeof:"JSX_CHILD",firstChild:null,children:n,_name:e.name},o=new Component({$$key:r._key,...t});return e=e.bind(o),o.render=()=>{let r=(n=n.flat(1/0)).map((e=>"function"==typeof e?generateJSX(e,t,e.props.children):e));return Object.keys(t).map((e=>{"className"===e&&(t.class=t[e],delete t[e])})),e({...t,children:r[0]||r})},r.firstChild=o.render(),r.firstChild.htmlNode._key=r._key,r.firstChild.htmlRoot=r,r.firstChild.htmlNode._isRoot=!0,r.firstChild.props=t||{},r.firstChild._isRoot=!0,r.firstChild._key=r._key,r.firstChild.props.key=r._key,r.firstChild}function handleStyles(e,t){for(let n in e)"object"==typeof e[n]&&handleStyles(e[n],t),t.style[n]=e[n]}let hasBeenCalled=[];function Element(e,t,...n){if(!t&&(t={}),t?.$$key||(t.$$key=e.name||Math.random().toString(36).substring(7)),"function"==typeof e)return generateJSX(e,t,n);let r={tag:e,props:t,children:n,_key:t.$$key,events:[],staticEl:document.createElement(e),parentNode:null};for(var o=0;o<n.length;o++)"string"==typeof n[o]||"number"==typeof n[o]?n[o]={tag:"TEXT_ELEMENT",props:{nodeValue:n[o]},_key:t.$$key,parentNode:{tag:e,props:t,children:n,_key:t.$$key},children:[]}:n[o]&&(n[o].parentNode={tag:e,props:t,children:n});let i="TEXT_ELEMENT"===r.tag?document.createTextNode(""):document.createElement(r.tag);for(var l in r.staticEl=i,t)l.toLowerCase().startsWith("on")?(i.addEventListener(l.substring(2).toLowerCase(),t[l]),r.events.push({type:l.substring(2).toLowerCase(),listener:t[l]})):"$$key"!==l||i._key||1!==i.nodeType?i&&1===i.nodeType&&i.setAttribute(l,t[l]):Object.defineProperty(i,"_key",{value:t[l],writable:!0});if(t.className&&(i.className=t.className),t.style&&handleStyles(t.style,i),t.id&&(i.id=t.id),t.ref)switch(!0){case Array.isArray(t.ref.current):t.ref.current.find((e=>e===i))||t.ref.current.push(i);break;case t.ref.current===HTMLElement:case null===t.ref.current:t.ref.current=i;break;case"function"==typeof t.ref&&!window.hasRan.includes(t.ref):window.hasRan.push(t.ref),t.ref(i),setTimeout((()=>{window.hasRan.filter((e=>e!==t.ref))}),0);break;default:t.ref.current=i}if(r.htmlNode=i,1===i.nodeType)for(o=0;o<n.length;o++)n[o]&&("TEXT_ELEMENT"===n[o].tag&&i.appendChild(document.createTextNode(n[o].props.nodeValue)),i.appendChild(Element(n[o].tag,n[o].props,...n[o].children).htmlNode));return r}function handleDiff(e){for(var t=0;t<e.length;t++)switch(!0){case"REPLACE"===e[t].type&&!e[t].oldNode._isRoot:e[t].oldNode.parentNode;e[t].oldNode.parentNode.replaceChild(e[t].newNode,e[t].oldNode);case"PROPS"===e[t].type:}return e}let states={};export const useState=(e,t)=>{};export function useRef(e,t){let n=t;memoizedRefs.find((t=>t.name===e))||memoizedRefs.push({name:e,ref:n});return{current:memoizedRefs.find((t=>t.name===e)).ref,name:e}}export function Mounted(e,t){Array.from(document.querySelectorAll("*")).find((e=>e._key===memoizedFunctions.find((e=>e.mainFunction===t))._key))&&!hasBeenCalled.find((e=>e===t))?(e(),hasBeenCalled.push(t)):setTimeout((()=>{Mounted(e,t)}),0)}let effects=[];export function useEffect(e,t){if(effects.find((t=>t.fn.toString()===e.toString()))){let n=effects.find((t=>t.fn.toString()===e.toString()));n.deps.toString()!==t.toString()&&(n.deps=t,n.fn())}else effects.push({fn:e,deps:t});return()=>{effects=effects.filter((t=>t.fn!==e))}}export function useReducer(e,t,n,r){let[o,i]=void 0;return[o,e=>{let n=t(o,e);i(n)}]}class Component{constructor(e){this.props=e,this._key=e.$$key||Math.random().toString(36).substring(7),this.state={},this.htmlNode=null,this.firstChild=null,this.Element=Element,this.passiveProps={}}setState(e){this.state=e}Element=Element;handleDiff(e){for(var t=0;t<e.length;t++)switch(!0){case"REPLACE"===e[t].type&&!e[t].oldNode._isRoot:e[t].oldNode.parentNode;e[t].oldNode.parentNode.replaceChild(e[t].newNode,e[t].oldNode);case"PROPS"===e[t].type:}}calculateDiff(e,t){if(void 0===e||void 0===t)return[];let n=[];if(e?.children.length>0){for(var r=0;r<e.children.length;r++)n.push(...this.calculateDiff(e.children[r],t.children[r]));return n}if(!e?._isRoot)if(3===e.nodeType&&e.nodeValue!==t.nodeValue)n.push({type:"REPLACE",oldNode:e,newNode:t});else if(1===e.nodeType&&e.innerHTML!==t.innerHTML)n.push({type:"REPLACE",oldNode:e,newNode:t});else if(1===e.nodeType&&e.tagName===t.tagName)for(r=0;r<e.attributes.length;r++)e.attributes[r].value!==t.attributes[r].value&&n.push({type:"PROPS",oldNode:e,newNode:t});return n}useState(e,t){this.state[e]||(this.state[e]=t);return[()=>this.state[e],t=>{this.state[e]=t,handleDiff(calculateDiff(Array.from(document.querySelectorAll("*")).find((e=>e._key===this.firstChild.htmlNode._key)),this.render(this.passiveProps).htmlNode))}]}useEffect=useEffect;useReducer(e,t,n){let[r,o]=this.useState(e,n);return[r,e=>{let n=t(r(),e);o(n)}]}render(){return null}}export async function render(e,t,...n){if(!e)throw new Error("No vnode was provided");let r=new Component({$$key:e.name||Math.random().toString(36).substring(7)});if(e=e.bind(r),n.length>0&&(n={req:n[0],res:n[1]},r.passiveProps=n),r.render=()=>e(r.passiveProps),r.firstChild=r.render(),"html"===r.firstChild.tag.toLowerCase()){let n=r.firstChild.children.find((e=>"body"===e.tag));if(!n)throw new Error("If you are rendering an HTML element, you must have a body tag enclosing the content");for(var o=0;o<n.children.length;o++){let e=n.children[o];"TEXT_ELEMENT"===e.tag?n.children[o]=Element("div",{nodeValue:e.props.nodeValue},...e.children):n.children[o]=Element(e.tag,e.props,...e.children)}n=new Element("div",{id:"root",_key:r._key},...n.children),n.htmlNode._isRoot=!0,n.htmlNode._key=r._key,t.innerHTML="",r.firstChild=n,r.firstChild.htmlNode=n.htmlNode,r.render=()=>{let t=e(r.passiveProps);if("html"===t.tag.toLowerCase()){let e=t.children.find((e=>"body"===e.tag));if(!e)throw new Error("If you are rendering an HTML element, you must have a body tag enclosing the content");for(var n=0;n<e.children.length;n++){let t=e.children[n];"TEXT_ELEMENT"===t.tag?e.children[n]=Element("div",{nodeValue:t.props.nodeValue},...t.children):e.children[n]=Element(t.tag,t.props,...t.children)}return e=new Element("div",{id:"root",_key:r._key},...e.children),e.htmlNode._isRoot=!0,e.htmlNode._key=r._key,e}},t.replaceWith(n.htmlNode)}else t.innerHTML="",t.replaceWith(r.firstChild.htmlNode)}export default Element;
@@ -0,0 +1 @@
1
+ export class Kuai{constructor(t={container:"#app"}){this.routes=[],this.middleware=[],this.container=t.container?t.container:document.getElementById("app"),this.renderPlugins=[]}res={text:t=>{this.container.innerHTML=t},html:t=>{switch(typeof t){case"function":if(this.renderPlugins.length>0)return void this.renderPlugins.forEach((e=>{"html"===e.for&&(console.log("Plugin",e),e.plugin(t,this.container))}));this.container.innerHTML=t();break;case"string":this.container.innerHTML=t}},json:t=>{this.container.innerHTML=`<Oject data=${JSON.stringify(t)}></Object>`}};req={navigate:t=>{window.history.pushState({},"",t);let e=this.match(window.location.pathname.replace("/index.html",""));e&&(this.currentRoute=e.path,e.callback(this.res,e.params,this.extractQueryParams(window.location.search)))},back:()=>{window.history.back()},forward:()=>{window.history.forward()},url:window.location};extractQueryParams(t){let e=new URLSearchParams(t),i={};for(let t of e)i[t[0]]=t[1];return i}extractParams(t,e){const i=t.split("/").filter((t=>""!==t)),r=e.split("/").filter((t=>""!==t)),a={};return i.forEach(((t,e)=>{if(t.startsWith(":")){const i=t.slice(1);a[i]=r[e]}else if(t.startsWith("*")){r.slice(e).forEach(((t,e)=>{a[e]=t}))}})),a}use(t,e){this.middleware.push({path:t,middleware:e})}usePlugin(t,e){this.renderPlugins.push({plugin:t,for:e})}match(t){(t=t.endsWith("/")?t.slice(0,-1):t).includes("index.html")&&(t=t.replace("index.html","")),t.includes("?")&&(t=t.split("?")[0]);let e=this.routes.find((e=>{if(e.path===t)return!0;if(""===t&&"/"===e.path)return!0;if(e.path.includes("*")||e.path.includes(":")){const i=e.path.split("/").filter((t=>""!==t)),r=t.split("/").filter((t=>""!==t));if(this.basePath&&r.shift(),i.length!==r.length&&!e.path.endsWith("*"))return!1;for(let t=0;t<i.length;t++){const e=i[t],a=r[t];if(!e.startsWith(":")&&!e.startsWith("*")&&e!==a)return!1}return!0}}));if(e){let i=this.extractParams(e.path,t);return{...e,params:i}}return null}get(t,e){this.routes.push({path:t,callback:e})}listen(){let t=this.match(window.location.pathname.replace("/index.html",""));if(t){this.middleware.forEach((e=>{e.path===t.path&&e.middleware()})),this.currentRoute=t.path;let e={...this.res,res:this.res,req:{...this.req,params:e=>t.params[e]}};t.callback(e)}window.onpopstate=()=>{let t=this.match(window.location.pathname.replace("/index.html",""));t&&(this.currentRoute=t.path,t.callback(this.res,t.params,this.extractQueryParams(window.location.search)))}}}export default Kuai;
@@ -0,0 +1,87 @@
1
+ /**
2
+ * @description Instruct the compiler to use the provided configuration
3
+ * @typedef {Object} Config
4
+ * @property {string} target - The target environment
5
+ * @property {Object} host - The host object
6
+ * @property {string} host.hostname - The hostname of the application
7
+ * @property {string} host.provider - The provider of the application
8
+ * @property {Object} compilerOptions - The compiler options
9
+ * @property {string} compilerOptions.outDir - The output directory
10
+ * @property {string} compilerOptions.target - The target of the compiler
11
+ * @property {any[]} plugins - The plugins to be used in the application
12
+ * @property {string} mode - The mode of the application
13
+ * @param config - The configuration object
14
+ * @returns
15
+ */
16
+ /**
17
+ * Defines the configuration options for VaderJS.
18
+ * @param {Object} config - The configuration object.
19
+ * @param {string} config.target - The target platform for the code ('web' or 'bun').
20
+ * @param {Object} [config.host] - The host configuration.
21
+ * @param {string} [config.host.hostname] - The hostname for the host.
22
+ * @param {('vercel','netlify')} [config.host.provider] - The provider for the host ('vercel', 'netlify', 'aws', 'azure', 'gcp').
23
+ * @param {number} [config.host.port] - The port number for the host.
24
+ * @param {Object} [config.compilerOptions] - The compiler options.
25
+ * @param {string} [config.compilerOptions.outDir] - The output directory for the compiled code.
26
+ * @param {string} [config.mode] - The mode for the configuration.
27
+ * @param {Array} [config.plugins] - The plugins for the configuration.
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.
34
+ * @returns {Object} The configured object.
35
+ */
36
+ export const defineConfig = (config: {
37
+ /**
38
+ * @type {string}
39
+ * @param {('web'|'bun')} target
40
+ */
41
+ target:string,
42
+ host?: {
43
+ hostname?: string,
44
+ /**
45
+ * @param {('vercel', 'netlify', 'aws', 'azure', 'gcp')} provider
46
+ */
47
+ provider?: string,
48
+ port?: number
49
+ },
50
+ compilerOptions?: {
51
+ outDir?: string,
52
+ },
53
+ mode?: string,
54
+ /**
55
+ * @type {any[]}
56
+ * @description Allows you to extend the functionality of vaderjs
57
+ */
58
+ plugins?: any[]
59
+ env?: {
60
+ [key: string]: any
61
+ },
62
+ Router?: {
63
+ tls?: {
64
+ cert?: string,
65
+ key?: string
66
+ },
67
+ headers?: {
68
+ [key: string]: string
69
+ }
70
+ },
71
+ [key: string]: any
72
+ }) => {
73
+ // add config.env to globalThis.env
74
+ let env = {}
75
+ if(config.env){
76
+ for(let key in config.env){
77
+ env[key] = config.env[key]
78
+ }
79
+ for(let key in globalThis.env){
80
+ env[key] = globalThis.env[key]
81
+ }
82
+ }
83
+
84
+ //@ts-ignore
85
+ globalThis.env = env
86
+ return config
87
+ }
package/index.ts ADDED
@@ -0,0 +1,344 @@
1
+ //@ts-nocheck
2
+ import {Element} from 'vaderjs/binaries/Kalix'
3
+ import React from 'react'
4
+ export const Vader = {
5
+ version: "0.0.1",
6
+ }
7
+
8
+ declare global {
9
+ /**
10
+ * @type {boolean}
11
+ * @description A boolean value that returns true if the current environment is a server
12
+ */
13
+ const isServer: boolean;
14
+ var location: {
15
+ href: string,
16
+ pathname: string,
17
+ search: string,
18
+ hash: string,
19
+ host: string,
20
+ hostname: string,
21
+ port: string,
22
+ protocol: string,
23
+ origin: string,
24
+ reload: () => void,
25
+ }
26
+ /**
27
+ * @description The env object - refers to the env variable either set in config or through the process.env
28
+ * @type {Object} [env]
29
+ */
30
+ var env:{
31
+ [key: string]: any
32
+ }
33
+ var history: {
34
+ pushState: (state: any, title: string, url: string) => void,
35
+ replaceState: (state: any, title: string, url: string) => void,
36
+ go: (delta: number) => void,
37
+ back: () => void,
38
+ forward: () => void,
39
+ }
40
+ var localStorage: {
41
+ getItem: (key: string) => string,
42
+ setItem: (key: string, value: string) => void,
43
+ removeItem: (key: string) => void,
44
+ clear: () => void,
45
+ }
46
+ /**
47
+ * @description The window object - used to manipulate the browser window
48
+ * @property {string} location.href - The URL of the current page
49
+ * @property {string} location.pathname - The path of the current page
50
+ * @property {string} location.search - The query string of the current page
51
+ * @property {string} location.hash - The hash of the current page
52
+ * @property {string} location.host - The host of the current page
53
+ * @property {string} location.hostname - The hostname of the current page
54
+ * @property {string} location.port - The port of the current page
55
+ * @property {string} location.protocol - The protocol of the current page
56
+ * @property {string} location.origin - The origin of the current page
57
+ * @property {Function} location.reload - Reloads the current page
58
+ * @property {Object} history - The history object
59
+ * @property {Function} history.pushState - Pushes a new state to the history object
60
+ */
61
+ var window: {
62
+ location: {
63
+ href: string,
64
+ /**
65
+ * @property {string} location.pathname - The path of the current page
66
+ */
67
+ pathname: string,
68
+ search: string,
69
+ hash: string,
70
+ host: string,
71
+ hostname: string,
72
+ port: string,
73
+ protocol: string,
74
+ origin: string,
75
+ reload: () => void,
76
+ },
77
+ history: {
78
+ pushState: (state: any, title: string, url: string) => void,
79
+ replaceState: (state: any, title: string, url: string) => void,
80
+ go: (delta: number) => void,
81
+ back: () => void,
82
+ forward: () => void,
83
+ },
84
+ localStorage: {
85
+ getItem: (key: string) => string,
86
+ setItem: (key: string, value: string) => void,
87
+ removeItem: (key: string) => void,
88
+ clear: () => void,
89
+ },
90
+
91
+ };
92
+ var preRender: boolean;
93
+ /**
94
+ * @type {Object}
95
+ * @description The file object
96
+ * @property {string} name - The name of the file
97
+ * @property {string} filetype - The type of the file
98
+ * @property {string} dataUrl - The data url of the file
99
+ * @property {string} text - The text content of the file
100
+ * @property {string} fileUrl - The file url
101
+ * @property {number} filesize - The file size
102
+ * @property {Blob} blob - The file blob
103
+ * @property {number} lastModified - The last modified date
104
+ * @property {string} mimetype - The file mimetype
105
+ */
106
+
107
+ const requirePath: (path: string) => any;
108
+
109
+ const useFile: (file: string) => {
110
+ name: string,
111
+ type: string,
112
+ lastModified:{
113
+ date: string,
114
+ time: string,
115
+ parsed: string,
116
+ },
117
+ size: number,
118
+ fileContent: string,
119
+ }
120
+ /**
121
+ * @description HTMLTextNode is a global interface that represents a text node
122
+ */
123
+
124
+ interface HTMLTextNode{
125
+ nodeType: number,
126
+ textContent: string,
127
+ toString: () => string,
128
+ }
129
+ /**
130
+ * @description HTMLElement is a global interface that represents an HTML element
131
+ */
132
+ interface HTMLElement{
133
+ tagName: string,
134
+ id: string,
135
+ nodeType: number,
136
+ classList:{
137
+ add: (className: string) => void,
138
+ remove: (className: string) => void,
139
+ toggle: (className: string) => void,
140
+ contains: (className: string) => boolean,
141
+ }
142
+ props: {
143
+ [key: string]: string,
144
+ }
145
+ children: HTMLElement[],
146
+ outerHTML: string,
147
+ innerHTML: string,
148
+ textContent: string,
149
+ firstChild: HTMLElement | HTMLTextNode | null,
150
+ style?: {
151
+
152
+ display: string,
153
+ position: string,
154
+ top: string,
155
+ left: string,
156
+ right: string,
157
+ bottom: string,
158
+ width: string,
159
+ height: string,
160
+ maxWidth: string,
161
+ maxHeight: string,
162
+ minWidth: string,
163
+ minHeight: string,
164
+ margin: string,
165
+ marginTop: string,
166
+ marginRight: string,
167
+ marginBottom: string,
168
+ marginLeft: string,
169
+ padding: string,
170
+ paddingTop: string,
171
+ paddingRight: string,
172
+ paddingBottom: string,
173
+ paddingLeft: string,
174
+ overflow: string,
175
+ zIndex: string,
176
+ cursor: string,
177
+ textAlign: string,
178
+ fontSize: string,
179
+ fontWeight: string,
180
+ fontStyle: string,
181
+ textDecoration: string,
182
+ lineHeight: string,
183
+ letterSpacing: string,
184
+ textTransform: string,
185
+ backgroundColor: string,
186
+ backgroundImage: string,
187
+ backgroundSize: string,
188
+ backgroundPosition: string,
189
+ backgroundRepeat: string,
190
+ backgroundAttachment: string,
191
+ backgroundClip: string,
192
+ backgroundOrigin: string,
193
+ backgroundBlendMode: string,
194
+ boxShadow: string,
195
+ transition: string,
196
+ transform: string,
197
+ transformOrigin: string,
198
+ transformStyle: string,
199
+ perspective: string,
200
+ perspectiveOrigin: string,
201
+ backfaceVisibility: string,
202
+ filter: string,
203
+ backdropFilter: string,
204
+ mixBlendMode: string,
205
+ border: string,
206
+ borderTop: string,
207
+ borderRight: string,
208
+ borderBottom: string,
209
+ borderLeft: string,
210
+ borderStyle: string,
211
+ borderTopStyle: string,
212
+ borderRightStyle: string,
213
+ borderBottomStyle: string,
214
+ borderLeftStyle: string,
215
+ borderColor: string,
216
+ borderTopColor: string,
217
+ borderRightColor: string,
218
+ borderBottomColor: string,
219
+ borderLeftColor: string,
220
+ borderRadius: string,
221
+ borderTopLeftRadius: string,
222
+ borderTopRightRadius: string,
223
+ borderBottomRightRadius: string,
224
+ borderBottomLeftRadius: string,
225
+ borderWidth: string,
226
+ borderTopWidth: string,
227
+ borderRightWidth: string,
228
+ borderBottomWidth: string,
229
+ borderLeftWidth: string,
230
+
231
+ [key: string]: string,
232
+ }
233
+ attributes: {
234
+ [key: string]: string,
235
+ },
236
+ events: [],
237
+ toString: () => string,
238
+ getAttribute: (attr: string) => string | null,
239
+ setAttribute: (attr: string, value: string) => void,
240
+ appendChild: (child: HTMLElement) => void,
241
+ prepend: (child: HTMLElement) => void,
242
+ append: (...child: HTMLElement[]) => void,
243
+ insertBefore: (node1: HTMLElement, node2: HTMLElement) => void,
244
+ removeChild: (child: HTMLElement) => void,
245
+ querySelector: (selector: string) => HTMLElement | null,
246
+ querySelectorAll: (selector: string) => HTMLElement[],
247
+ }
248
+ }
249
+ let states = []
250
+
251
+ export const useState = (initialState: any) => {
252
+ let state = initialState
253
+ let setState = (newState: any) => {
254
+ state = newState
255
+ }
256
+ states.push({state, setState})
257
+ return [state, setState]
258
+ }
259
+
260
+ export const useReducer = (reducer: any, initialState: any) => {
261
+ let state = initialState
262
+ let dispatch = (action: any) => {
263
+ state = reducer(state, action)
264
+ }
265
+ states.push({state, dispatch})
266
+ return [state, dispatch]
267
+ }
268
+ let refs = []
269
+
270
+
271
+ export const useRef = <T>(defaultValue: T) => {
272
+ if(!globalThis.isNotFirstRun) {
273
+ console.warn(`⚠️ Note: useRef in the server environment will not work like it does in the client, you cannot store the reference in a variable within mounted!
274
+ `)
275
+ }
276
+ let refKey = "${Math.random().toString(36).substring(7).replace('.', '').replace('\d', '')}"
277
+ let ref = {name: refKey, current: defaultValue}
278
+ refs.push(ref)
279
+ return ref
280
+ }
281
+
282
+ /**
283
+ * @description The mounted function is called when the component is mounted based on pregenerated keys
284
+ * @param callback {Function}
285
+ * @param parent {Function}
286
+ */
287
+ export const Mounted = (callback: Function, parent: Function) => {
288
+ callback()
289
+ }
290
+
291
+ let effects = []
292
+ /**
293
+ * Use this to perform DOM mutations. This is the primary method you use to update the user interface in response to event handlers and server responses.
294
+ * Prefer the standard `useEffect` when possible to avoid blocking visual updates.
295
+ */
296
+
297
+ export const useEffect = (callback: Function, dependencies: any[]) => {
298
+ if(!effects.includes(callback)){
299
+ effects.push({callback, dependencies})
300
+ }
301
+ let deps = effects.find((effect: any) => effect.callback === callback).dependencies
302
+ if(deps){
303
+ deps.forEach((dep: any) => {
304
+ if(dep !== dependencies[0]){
305
+ callback()
306
+ }
307
+ })
308
+ }else{
309
+ callback()
310
+ }
311
+ }
312
+
313
+ globalThis.window = {
314
+ location: {
315
+ href: '',
316
+ pathname: '',
317
+ search: '',
318
+ hash: '',
319
+ host: '',
320
+ hostname: '',
321
+ port: '',
322
+ protocol: '',
323
+ origin: '',
324
+ reload: () => {}
325
+ },
326
+ history: {
327
+ pushState: (state: any, title: string, url: string) => {},
328
+ replaceState: (state: any, title: string, url: string) => {},
329
+ go: (delta: number) => {},
330
+ back: () => {},
331
+ forward: () => {},
332
+ },
333
+ localStorage: {
334
+ getItem: (key: string) => '',
335
+ setItem: (key: string, value: string) => {},
336
+ removeItem: (key: string) => {},
337
+ clear: () => {},
338
+ }
339
+ }
340
+
341
+ export const render = (element: any, container: any) => {
342
+ container.appendChild(element)
343
+ }
344
+ export default Element