vaderjs 1.3.7 → 1.4.0

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.
@@ -0,0 +1,426 @@
1
+ /**
2
+ * @file Vader.js - A lightweight, modern, and fast front-end framework for building web applications.
3
+ * @copyright - Malikwhitten67
4
+ * @license MIT
5
+ */
6
+
7
+
8
+ /**
9
+ * @class Component
10
+ * @description Base class for all components - functional and class components
11
+ * @example
12
+ * class App extends Component {
13
+ * constructor(props){
14
+ * super(props)
15
+ * this.state = {
16
+ * count: 0
17
+ * }
18
+ * }
19
+ *
20
+ * render(){
21
+ * return <div>
22
+ * <h1>Count is {this.state.count}</h1>
23
+ * <button onClick={()=> this.setState({count: this.state.count + 1})}>Click me</button>
24
+ * </div>
25
+ * }
26
+ * }
27
+ *
28
+ */
29
+ export class Component {
30
+ /**
31
+ * @constructor
32
+ * @param {object} props - Component props
33
+ * @param {string} props.key - Unique identifier for the component
34
+ * @param {object} props.children - Content to be displayed inside the component
35
+ */
36
+ constructor() {
37
+ this.state = {};
38
+ this.props = {};
39
+ this.key = Math.random();
40
+ this.__internalInstance = {};
41
+ }
42
+
43
+ /**
44
+ * @function
45
+ * @description This method allows you to update the state of a component
46
+ */
47
+ render() {}
48
+ /**
49
+ * @function
50
+ * @description This method allows you to update the state of a component
51
+ * **/
52
+ onMount() {}
53
+
54
+ /**
55
+ * @function
56
+ * @description This method allows you to update the state of a component
57
+ * @param {any} initialValue
58
+ * @returns {[any, Function]}
59
+ */
60
+
61
+ useState(initialValue) {
62
+ if (!this.state[key]) this.state[key] = initialValue;
63
+ let state = this.state[key];
64
+ const setState = (newState) => {
65
+ state = newState;
66
+ this.state[key] = newState;
67
+ this.updateInstance(this.__internalInstance);
68
+ };
69
+ const getUpdatedState = () => {
70
+ return this.state[key] || initialValue;
71
+ }
72
+ state = getUpdatedState();
73
+ return [state, setState];
74
+
75
+ }
76
+
77
+ /**
78
+ * @function useRef
79
+ * @description This method allows you to create a reference to a DOM element
80
+ * @param {string} key
81
+ * @param {any} initialValue
82
+ * @returns {current: any}
83
+ */
84
+ useRef(initialValue) {
85
+ return {current: initialValue}
86
+ }
87
+
88
+ /**
89
+ * @function useReducer
90
+ * @description This method allows you to use a reducer to manage state
91
+ * @param {function} reducer
92
+ * @param {any} initialState
93
+ */
94
+ useReducer(reducer, initialState) {
95
+ if (!this.state[key]) this.state[key] = initialState;
96
+ let state = this.state[key];
97
+ const setState = (newState) => {
98
+ state = newState;
99
+ this.state[key] = newState;
100
+ this.updateInstance(this.__internalInstance);
101
+ };
102
+ const getUpdatedState = () => {
103
+ return this.state[key] || initialState;
104
+ }
105
+ state = getUpdatedState();
106
+ return [state, setState];
107
+ }
108
+
109
+ }
110
+
111
+ /**
112
+ * @method Mounted
113
+ * @description This method allows you to await until the component is mounted before running a callback
114
+ *
115
+ * @param {function} callback - Function to be called when the component is mounted
116
+ * @param {Component} component - Component to be determined mounted
117
+ * @param {boolean} runOnlyOnce - Run the callback only once - default: true
118
+ */
119
+ export const Mounted = (callback, /**@type {Component} */ component, runOnlyOnce = true) => {
120
+
121
+ };
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+ /**
134
+ * @class Link
135
+ * @description Allows you to seamlessly navigate to different pages in your application
136
+ * @extends Component
137
+ * @example
138
+ * <Link href="/some-path" class="custom-link" style="color: blue;">Click me!</Link>
139
+ */
140
+ export class Link extends Component {
141
+ /**
142
+ * @constructor
143
+ * @param {object} props - Component props
144
+ * @param {string} props.href - URL for the link
145
+ * @param {string} props.action - Action to be performed when the link is clicked - can be function or string
146
+ * @param {string} [props.class] - CSS class for the link
147
+ * @param {string} [props.style] - Inline CSS style for the link
148
+ * @param {string} [props.children] - Content to be displayed inside the link
149
+ */
150
+ constructor(props) {
151
+ super(props);
152
+ /**
153
+ * @type {object}
154
+ * @property {string} href - URL for the link
155
+ * @property {string} [action] - Action to be performed when the link is clicked
156
+ * @property {string} [class] - CSS class for the link
157
+ * @property {string} [style] - Inline CSS style for the link
158
+ * @property {string} [children] - Content to be displayed inside the link
159
+ */
160
+ this.props = {
161
+ href: props.href,
162
+ /**
163
+ * @type {string|function}
164
+ * @param {string} [action='outside'] - Action to be performed when the link is clicked
165
+ */
166
+ action: props.action || 'outside',
167
+ class: props.class,
168
+ style: props.style,
169
+ }
170
+
171
+ /**
172
+ * @type {HTMLAnchorElement}
173
+ */
174
+ this.link = document.createElement('a');
175
+
176
+ /**
177
+ * @type {string}
178
+ */
179
+ this.key = props.href + Math.random();
180
+ }
181
+
182
+ /**
183
+ * @function
184
+ * @returns {string} - Rendered HTML for the Link component
185
+ */
186
+ render() {
187
+
188
+ return this.link.outerHTML;
189
+ }
190
+ }
191
+
192
+
193
+
194
+ /**
195
+ * @class Image
196
+ * @description Image component
197
+ * @extends Component
198
+ * @example
199
+ * <Image src="https://via.placeholder.com/150" alt="image" />
200
+ */
201
+ export class Image extends Component {
202
+ /**
203
+ * @constructor
204
+ * @param {object} props - Component props
205
+ * @param {string} props.src - Image source URL
206
+ * @param {string} props.class - CSS class for the image
207
+ * @param {string} props.style - Inline CSS style for the image
208
+ * @param {number} props.blur - Blur value for the image (optional)
209
+ * @param {number} props.width - Width of the image (optional)
210
+ * @param {number} props.height - Height of the image (optional)
211
+ * @param {boolean} props.optimize - Optimize the image (optional, default: true)
212
+ * @param {boolean} props.loader - Show a placeholder loader (optional, default: true)
213
+ * @param {string} props.alt - Alt text for the image (optional, default: 'image')
214
+ */
215
+ constructor(props) {
216
+ super(props);
217
+
218
+ /**
219
+ * @type {object}
220
+ * @property {string} src - Image source URL
221
+ * @property {string} [class] - CSS class for the image
222
+ * @property {string} [style] - Inline CSS style for the image
223
+ * @property {number} [blur] - Blur value for the image (optional)
224
+ * @property {number} [width] - Width of the image (optional)
225
+ * @property {number} [height] - Height of the image (optional)
226
+ * @property {boolean} [optimize] - Optimize the image (optional, default: true)
227
+ * @property {boolean} [loader] - Show a placeholder loader (optional, default: true)
228
+ * @property {string} [alt] - Alt text for the image (optional, default: 'image')
229
+ * @property {string} [children] - Content to be displayed inside the image
230
+ * @property {string} [key] - Unique identifier for the image
231
+ * @property {string} [onLoad] - Function to be called when the image is loaded
232
+ */
233
+ this.props = {
234
+ src: props.src,
235
+ class: props.class,
236
+ style: props.style,
237
+ blur: props.blur,
238
+ width: props.width,
239
+ height: props.height,
240
+ optimize: props.optimize || true,
241
+ loader: props.loader || true,
242
+ alt: props.alt || 'image',
243
+ };
244
+
245
+ /**
246
+ * @type {string}
247
+ */
248
+ this.key = props.src + Math.random();
249
+
250
+ /**
251
+ * @type {HTMLImageElement}
252
+ * @private
253
+ */
254
+ this.img = document.createElement('img');
255
+
256
+ /**
257
+ * @type {HTMLDivElement}
258
+ * @private
259
+ */
260
+ this.placeholder = document.createElement('div');
261
+ }
262
+
263
+ /**
264
+ * @function
265
+ * @returns {string} - Rendered JSX for the Image component
266
+ */
267
+ render() {
268
+ // adjust width and height to the user's screen size
269
+
270
+
271
+ return this.img.outerHTML;
272
+ }
273
+ }
274
+
275
+ export class Head extends Component {
276
+ /**
277
+ * @constructor
278
+ * @param {object} props - Component props
279
+ * @param {boolean} props.updateOnReload - update metadata and title when rerendered
280
+ * @param {string} props.children - Content to be displayed inside the head
281
+ */
282
+ constructor(props) {
283
+ super(props);
284
+ /**
285
+ * @type {object}
286
+ * @param {object} props - Component props
287
+ * @param {boolean} props.updateOnReload - update metadata and title when rerendered
288
+ * @param {string} props.children - Content to be displayed inside the head
289
+ */
290
+ this.props = {
291
+ children: props.children,
292
+ updateOnReload: props.updateOnReload
293
+ }
294
+ this.key = 'head';
295
+ this.head = document.createElement('head');
296
+ }
297
+
298
+
299
+
300
+ render() {
301
+ this.head.innerHTML = this.props.children;
302
+ return this.head.outerHTML;
303
+ }
304
+
305
+ onMount() {
306
+ document.head.innerHTML = this.head.innerHTML;
307
+ document.body.querySelector(`[key="${this.key}"]`).remove();
308
+ }
309
+ }
310
+
311
+ export class Script extends Component {
312
+ /**
313
+ * @constructor
314
+ * @param {object} props - Component props
315
+ * @param {string} props.children - Content to be displayed inside the script
316
+ */
317
+ constructor(props) {
318
+ super(props);
319
+ this.props = {
320
+ children: props.children,
321
+ }
322
+ this.key = 'script';
323
+ this.script = document.createElement('script');
324
+ }
325
+
326
+
327
+
328
+ render() {
329
+ this.script.innerHTML = this.props.children.split('\n').join(';\n');
330
+ return this.script.outerHTML;
331
+ }
332
+
333
+ onMount() {
334
+ document.head.appendChild(this.script);
335
+ document.body.querySelector(`[key="${this.key}"]`).remove();
336
+ }
337
+
338
+ }
339
+
340
+ /**
341
+ * @class HTML
342
+ * @description HTML component
343
+ * @extends Component
344
+ */
345
+ export class Html extends Component {
346
+ /**
347
+ * @constructor
348
+ * @param {object} props - Component props
349
+ * @param {string} props.key - Identifier which is used to check if the component has been mounted
350
+ * @param {string} props.children - Content to be displayed inside the HTML
351
+ * @param {string} props.lang - Language for the HTML
352
+ */
353
+ constructor(props) {
354
+ super(props);
355
+ /**
356
+ * @type {object}
357
+ * @property {string} children - Content to be displayed inside the HTML
358
+ * @property {string} lang - Language for the HTML
359
+ * @property {object} attributes - Attributes for the HTML
360
+ */
361
+ this.props = {
362
+ children: props.children,
363
+ lang: props.lang || 'en',
364
+ attributes: props.attributes || {},
365
+ }
366
+ this.key = props.key || 'html';
367
+ this.html = document.createElement('html');
368
+ }
369
+
370
+ render() {
371
+ this.html.innerHTML = this.props.children;
372
+ return this.html.outerHTML;
373
+ }
374
+
375
+ onMount() {
376
+ if (window.isServer) {
377
+ document.documentElement.innerHTML = this.html.outerHTML;
378
+ }
379
+ console.log('Document Has Been Mounted')
380
+ }
381
+
382
+ }
383
+ /**
384
+ * @function useRef
385
+ * @description This method allows you to create a reference to a DOM element
386
+ * @param {any} initialValue
387
+ * @returns
388
+ */
389
+ export const useRef = (initialValue) => {
390
+ return {
391
+ current: initialValue
392
+ }
393
+ }
394
+
395
+ /**
396
+ * @function useState
397
+ * @description This method allows you to use to bind state to a component and update on changes
398
+ * @param {any} initialValue
399
+ * @returns {[any, Function]}
400
+ */
401
+ export const useState = (initialValue) => {
402
+ return [initialValue, () => {}]
403
+ }
404
+ /**
405
+ * @function useReducer
406
+ * @description This method allows you to use a reducer to manage state
407
+ * @param {function} reducer
408
+ * @param {any} initialState
409
+ * @returns
410
+ */
411
+
412
+ export const useReducer = (reducer, initialState) => {
413
+ return [initialState, () => {}]
414
+ }
415
+ export default {
416
+ Component,
417
+ useRef,
418
+ useReducer,
419
+ useState,
420
+ strictMount,
421
+ Link,
422
+ Image,
423
+ Head,
424
+ Html,
425
+
426
+ }
package/logo.png CHANGED
File without changes
package/package.json CHANGED
@@ -2,20 +2,36 @@
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.7",
5
+ "version": "1.4.0",
6
6
  "bin": {
7
- "vader": "./vader"
8
- },
9
- "scripts": {
10
- "build": "bunx vader --build",
11
- "watch": "bun run vader --watch",
12
- "help": "bunx vader"
7
+ "vader": "./vader.js"
13
8
  },
9
+ "keywords": [
10
+ "react",
11
+ "reactive",
12
+ "nextjs",
13
+ "pages router",
14
+ "bun.js",
15
+ "spa",
16
+ "vanillajs",
17
+ "vanilla js"
18
+ ],
14
19
  "type": "module",
15
- "devDependencies": {
16
- "@types/bun": "latest"
20
+ "license": "MIT",
21
+ "homepage": "https://vader-js.pages.dev",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/Postr-Inc/Vader.js"
25
+ },
26
+ "author": {
27
+ "name": "Malik Whitten",
28
+ "email": "malikwhitterb@gmail.com"
17
29
  },
18
- "peerDependencies": {
19
- "typescript": "^5.0.0"
30
+ "dependencies": {
31
+ "puppeteer":"latest",
32
+ "dotenv":"latest",
33
+ "prettier": "latest",
34
+ "source-map": "latest"
35
+
20
36
  }
21
- }
37
+ }