@firesmasher/velox.js 1.0.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.
package/bin/index.js ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import { run } from "../lib/cli.js";
3
+ run();
package/docs/GUIDE.md ADDED
@@ -0,0 +1,333 @@
1
+ # Velox.js — Practical Guide
2
+
3
+ ## 1. Setting up
4
+
5
+ Scaffold a new project:
6
+ ```bash
7
+ npx velox my-app
8
+ cd my-app
9
+ ```
10
+
11
+ Serve it locally (Velox uses `fetch()` internally, so you need a server — opening `index.html` directly as a `file://` URL won't work):
12
+ ```
13
+ npx serve .
14
+ ```
15
+ or use VS Code Live Server.
16
+
17
+ ---
18
+
19
+ ## 2. The basic connection: .vlx → HTML
20
+
21
+ This is the most important thing to understand. There are exactly three ways to connect Velox to your HTML.
22
+
23
+ ### Run a command at page load
24
+
25
+ Put a `<?velox >` tag anywhere in your HTML body. It runs when the page loads.
26
+
27
+ ```html
28
+ <div id="output"></div>
29
+
30
+ <?velox Dom.setText("Page is ready") $target="$id(output)" >
31
+
32
+ <script src="assets/scripts/velox/velox.js"></script>
33
+ ```
34
+
35
+ ### Run a .vlx file at page load
36
+
37
+ ```html
38
+ <div id="output"></div>
39
+
40
+ <?velox Velox.run("assets/scripts/velox/myscript.vlx") $target="$id(output)" >
41
+
42
+ <script src="assets/scripts/velox/velox.js"></script>
43
+ ```
44
+
45
+ ### Wire a button to a command or .vlx file
46
+
47
+ ```html
48
+ <button id="myBtn">Click me</button>
49
+ <div id="output"></div>
50
+
51
+ <!-- Inline command on click -->
52
+ <?velox $on click "$id(myBtn)": Dom.setText("Clicked!") $target="$id(output)" >
53
+
54
+ <!-- Or run a .vlx file on click -->
55
+ <?velox $on click "$id(myBtn)": Velox.run("myscript.vlx") $target="$id(output)" >
56
+
57
+ <script src="assets/scripts/velox/velox.js"></script>
58
+ ```
59
+
60
+ > `velox.js` must always be the **last script** before `</body>`. The `<?velox >` tags can go anywhere in the body — they're read as raw HTML text, not executed as JS.
61
+
62
+ ---
63
+
64
+ ## 3. Writing .vlx files
65
+
66
+ `.vlx` files live in `assets/scripts/velox/`. Each statement ends with `;`. Use `//` for comments.
67
+
68
+ ```vlx
69
+ // myscript.vlx
70
+
71
+ Dom.setText("Hello from the script") $target="$id(output)";
72
+ Dom.addClass("loaded") $target="$id(output)";
73
+ echo("Script ran");
74
+ ```
75
+
76
+ **Common mistakes:**
77
+
78
+ | Wrong | Right |
79
+ |---|---|
80
+ | `Dom.setText("Hi"), $target="..."` | `Dom.setText("Hi") $target="..."` |
81
+ | `Velox.run("path") { $target: "..." }` | `Velox.run("path") $target="..."` (in HTML tag) |
82
+ | `$if 0: echo("ok")` | `$if .: echo("ok")` (use `.` for "if succeeded") |
83
+ | Separating statements with `,` | Use `;` |
84
+
85
+ ---
86
+
87
+ ## 4. Targets
88
+
89
+ Every command needs to know which element to act on. You set this with `$target`.
90
+
91
+ ```
92
+ $target="$id(myId)" → <div id="myId">
93
+ $target="$class(myClass)" → first element with class "myClass"
94
+ $target="$query(.card > p)" → any CSS selector
95
+ $target="$tag(main)" → first <main> element
96
+ ```
97
+
98
+ In a `<?velox >` tag:
99
+ ```html
100
+ <?velox Dom.hide() $target="$id(sidebar)" >
101
+ ```
102
+
103
+ In a `.vlx` file:
104
+ ```vlx
105
+ Dom.hide() $target="$id(sidebar)";
106
+ ```
107
+
108
+ ---
109
+
110
+ ## 5. Event listeners
111
+
112
+ Wire any HTML element to any command using `$on` inside a `<?velox >` tag.
113
+
114
+ ```html
115
+ <!-- Click -->
116
+ <?velox $on click "$id(btn)": Dom.setText("Clicked") $target="$id(out)" >
117
+
118
+ <!-- Hover -->
119
+ <?velox $on hover "$id(card)": Anim.pulse("400") $target="$id(card)" >
120
+
121
+ <!-- Input (fires on every keystroke) -->
122
+ <?velox $on input "$id(searchBox)": Dom.getValue() $target="$id(searchBox)" >
123
+
124
+ <!-- Form submit (automatically calls preventDefault) -->
125
+ <?velox $on submit "$id(myForm)": Form.serialize("$id(myForm)") $target="$id(out)" >
126
+ ```
127
+
128
+ You can also put `$on` statements inside a `.vlx` file — useful when you want to set up multiple listeners from one script:
129
+
130
+ ```vlx
131
+ // setup.vlx
132
+ $on click "$id(btnA)": Dom.show() $target="$id(panelA)";
133
+ $on click "$id(btnB)": Dom.show() $target="$id(panelB)";
134
+ $on click "$id(closeBtn)": Dom.hide() $target="$id(modal)";
135
+ ```
136
+
137
+ ---
138
+
139
+ ## 6. Conditionals
140
+
141
+ Check whether a command succeeded and branch on the result.
142
+
143
+ ```vlx
144
+ Url.get("https://api.example.com/data") $target="$id(output)"
145
+ $if .: echo("Loaded!")
146
+ $else: echo.err("Failed to load");
147
+ ```
148
+
149
+ `$if .` means "if the command succeeded". You can also use `$if 1` (always true) or `$if 0` (always false).
150
+
151
+ Chain with `$if else`:
152
+ ```vlx
153
+ Store.get("theme") $target="$id(output)"
154
+ $if .: echo("Theme found")
155
+ $if else .: echo("Using default")
156
+ $else: echo.err("Storage error");
157
+ ```
158
+
159
+ ---
160
+
161
+ ## 7. Variables
162
+
163
+ In-memory variables (cleared on page reload):
164
+
165
+ ```vlx
166
+ Var.set("username:Alice");
167
+ Var.get("username") $target="$id(nameDisplay)";
168
+ Var.clear("username");
169
+ Var.clear("*");
170
+ ```
171
+
172
+ Persistent variables use Local Storage:
173
+
174
+ ```vlx
175
+ Store.set("theme:dark");
176
+ Store.get("theme") $target="$id(themeLabel)";
177
+ Store.remove("theme");
178
+ ```
179
+
180
+ ---
181
+
182
+ ## 8. Animations
183
+
184
+ All animation commands target an element with `$target`.
185
+
186
+ ```vlx
187
+ Anim.fadeIn("300") $target="$id(box)";
188
+ Anim.fadeOut("300") $target="$id(box)";
189
+ Anim.slide("down:400") $target="$id(menu)";
190
+ Anim.slide("up:400") $target="$id(menu)";
191
+ Anim.shake() $target="$id(errorMsg)";
192
+ Anim.pulse("600") $target="$id(badge)";
193
+ ```
194
+
195
+ A common pattern — show a hidden element with a fade:
196
+ ```html
197
+ <div id="modal" style="display:none;">Hello!</div>
198
+ <button id="openBtn">Open</button>
199
+
200
+ <?velox $on click "$id(openBtn)": Anim.fadeIn("300") $target="$id(modal)" >
201
+ ```
202
+
203
+ ---
204
+
205
+ ## 9. Network requests
206
+
207
+ Fetch text from a URL and put it in an element:
208
+ ```vlx
209
+ Url.get("https://api.example.com/message") $target="$id(output)"
210
+ $if .: echo("Loaded")
211
+ $else: echo.err("Request failed");
212
+ ```
213
+
214
+ Fetch JSON and display it:
215
+ ```vlx
216
+ Url.getJson("https://api.example.com/user") $target="$id(output)";
217
+ ```
218
+
219
+ POST a request:
220
+ ```vlx
221
+ Url.post("https://api.example.com/action")
222
+ $if .: Dom.setText("Saved!") $target="$id(status)"
223
+ $else: Dom.setText("Error") $target="$id(status)";
224
+ ```
225
+
226
+ Embed a URL in an iframe:
227
+ ```html
228
+ <div id="frameContainer"></div>
229
+
230
+ <?velox $on click "$id(loadBtn)": iframe.Url("https://example.com") $target="$id(frameContainer)" >
231
+ ```
232
+
233
+ ---
234
+
235
+ ## 10. Template rendering
236
+
237
+ Define a `<template>` tag in your HTML with `{{key}}` placeholders:
238
+
239
+ ```html
240
+ <template id="userCard">
241
+ <div class="card">
242
+ <h2>{{name}}</h2>
243
+ <p>{{role}}</p>
244
+ </div>
245
+ </template>
246
+
247
+ <div id="output"></div>
248
+ ```
249
+
250
+ Render it with JSON data:
251
+ ```vlx
252
+ Template.render("userCard:{\"name\":\"Alice\",\"role\":\"Admin\"}") $target="$id(output)";
253
+ ```
254
+
255
+ ---
256
+
257
+ ## 11. SPA Router
258
+
259
+ Define routes that each map to a `.vlx` file. The script runs inside the outlet element when the route is active.
260
+
261
+ ```html
262
+ <nav>
263
+ <a href="#/">Home</a>
264
+ <a href="#/about">About</a>
265
+ </nav>
266
+ <main id="app"></main>
267
+
268
+ <?velox
269
+ Router.define("/:/pages/home.vlx");
270
+ Router.define("/about:/pages/about.vlx");
271
+ Router.start() $target="$id(app)";
272
+ >
273
+ ```
274
+
275
+ Navigate programmatically from a `.vlx` file:
276
+ ```vlx
277
+ Router.go("/about");
278
+ ```
279
+
280
+ ---
281
+
282
+ ## 12. Path and @env
283
+
284
+ Paths in `.vlx` files can be absolute (`/assets/...`), relative to root (`../../` is automatically resolved to `/`), or use environment keys:
285
+
286
+ ```vlx
287
+ Url.get("@env:apiBase");
288
+ Script.load("@env:myLib");
289
+ ```
290
+
291
+ Keys are defined in `storage/env/quickPaths.json`:
292
+ ```json
293
+ {
294
+ "apiBase": "https://api.example.com",
295
+ "myLib": "/assets/scripts/javascript/lib.js"
296
+ }
297
+ ```
298
+
299
+ ---
300
+
301
+ ## 13. Delay and repeat
302
+
303
+ ```vlx
304
+ // Wait 1 second then show
305
+ Dom.show() $target="$id(toast)" $delay 1000;
306
+
307
+ // Flash 3 times, 500ms apart
308
+ Anim.pulse("200") $target="$id(alert)" $repeat 3 $delay 500;
309
+ ```
310
+
311
+ ---
312
+
313
+ ## 14. Loading external scripts and styles
314
+
315
+ ```vlx
316
+ Script.load("/assets/scripts/javascript/chart.js")
317
+ $if .: echo("Chart.js ready")
318
+ $else: echo.err("Failed to load chart");
319
+
320
+ Style.load("/assets/css/theme.css");
321
+ ```
322
+
323
+ ---
324
+
325
+ ## 15. Page utilities
326
+
327
+ ```vlx
328
+ Page.title("Dashboard");
329
+ Page.meta("description:My app description");
330
+ Page.scrollTop();
331
+ Page.redirect("https://example.com");
332
+ Page.reload();
333
+ ```
package/docs/README.md ADDED
@@ -0,0 +1,140 @@
1
+ # Velox.js
2
+
3
+ **The fast frontend framework with its own scripting language.**
4
+
5
+ Velox.js lets you control your HTML pages using `.vlx` script files and `<?velox >` tags — no build step, no bundler, no JSX. Just drop `velox.js` into your page and start writing scripts.
6
+
7
+ ---
8
+
9
+ ## Quick start
10
+
11
+ ```bash
12
+ npx velox my-app
13
+ cd my-app
14
+ ```
15
+
16
+ Open `public/index.html` in your browser (via a local server — e.g. VS Code Live Server, or `npx serve .`).
17
+
18
+ ---
19
+
20
+ ## How it works
21
+
22
+ The Velox runtime (`velox.js`) scans your HTML for `<?velox ... >` tags when the page loads. Each tag either runs a command directly or wires up an event listener.
23
+
24
+ **Run a command on page load:**
25
+ ```html
26
+ <?velox Dom.setText("Hello!") $target="$id(output)" >
27
+ ```
28
+
29
+ **Run a `.vlx` script file on page load:**
30
+ ```html
31
+ <?velox Velox.run("assets/scripts/velox/myscript.vlx") $target="$id(output)" >
32
+ ```
33
+
34
+ **Wire a button click to a command:**
35
+ ```html
36
+ <?velox $on click "$id(myBtn)": Dom.setText("Clicked!") $target="$id(output)" >
37
+ ```
38
+
39
+ **Wire a button click to a `.vlx` file:**
40
+ ```html
41
+ <?velox $on click "$id(myBtn)": Velox.run("myscript.vlx") $target="$id(output)" >
42
+ ```
43
+
44
+ The runtime must be loaded before `</body>`:
45
+ ```html
46
+ <script src="assets/scripts/velox/velox.js"></script>
47
+ ```
48
+
49
+ ---
50
+
51
+ ## .vlx scripts
52
+
53
+ `.vlx` files are plain text scripts with one statement per line, separated by `;`.
54
+
55
+ ```vlx
56
+ // myscript.vlx
57
+
58
+ Dom.setText("Loaded from script!") $target="$id(output)";
59
+ Dom.addClass("active") $target="$id(output)";
60
+ Anim.fadeIn("400") $target="$id(output)";
61
+
62
+ Var.set("user:Alice");
63
+ echo("Script finished");
64
+ ```
65
+
66
+ ---
67
+
68
+ ## Project structure
69
+
70
+ ```
71
+ my-app/
72
+ ├── public/
73
+ │ └── index.html
74
+ ├── assets/
75
+ │ ├── css/
76
+ │ │ └── style.css
77
+ │ └── scripts/
78
+ │ └── velox/
79
+ │ ├── velox.js ← runtime
80
+ │ └── myscript.vlx ← your scripts go here
81
+ ├── .velox/
82
+ │ └── conf/
83
+ │ └── config.jsonc
84
+ ├── storage/
85
+ │ ├── env/
86
+ │ │ └── quickPaths.json
87
+ │ └── variables/
88
+ │ └── normal.json
89
+ ├── tags/
90
+ │ └── json/
91
+ │ └── UrlS.json
92
+ └── velox.project.json
93
+ ```
94
+
95
+ ---
96
+
97
+ ## Selectors
98
+
99
+ | Syntax | Selects |
100
+ |---|---|
101
+ | `$id(myId)` | `#myId` |
102
+ | `$class(myClass)` | first `.myClass` |
103
+ | `$query(.card > p)` | any CSS selector |
104
+ | `$tag(div)` | first `<div>` |
105
+
106
+ ---
107
+
108
+ ## Command categories
109
+
110
+ | Category | Commands |
111
+ |---|---|
112
+ | DOM | `setText` `setHtml` `append` `prepend` `remove` `clear` `show` `hide` `toggle` `addClass` `removeClass` `toggleClass` `setAttr` `removeAttr` `setStyle` `focus` `click` `scrollTo` `getValue` `setValue` |
113
+ | Animation | `fadeIn` `fadeOut` `slide` `shake` `pulse` |
114
+ | Events | `$on click` `hover` `input` `change` `submit` `keydown` `load` |
115
+ | Form | `getValue` `setValue` `clear` `serialize` |
116
+ | Storage | `Store.set` `get` `remove` `clear` |
117
+ | Cookies | `Cookie.set` `get` `remove` |
118
+ | Variables | `Var.set` `get` `clear` |
119
+ | Network | `Url.get` `getJson` `post` `postJson` `fetch` · `iframe.Url` |
120
+ | File | `file.localFetch` |
121
+ | Page | `redirect` `reload` `title` `meta` `scrollTop` |
122
+ | Router | `Router.define` `go` `start` |
123
+ | Template | `Template.render` |
124
+ | Script/Style | `Script.load` · `Style.load` |
125
+ | Logging | `echo` `echo.warn` `echo.err` |
126
+
127
+ See [SYNTAXES.md](./SYNTAXES.md) for the full reference.
128
+
129
+ ---
130
+
131
+ ## Requirements
132
+
133
+ - Node.js >= 16 (for the CLI scaffolder)
134
+ - A local HTTP server to serve your project (required for `fetch()` to work)
135
+
136
+ ---
137
+
138
+ ## License
139
+
140
+ MIT