juxscript 1.0.60 → 1.0.62

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/README.md CHANGED
@@ -1,4 +1,35 @@
1
- # The web needs a higher level of abstraction: Meet **JUX**
1
+ # JUX - JavaScript UX Authorship Platform
2
+
3
+ > Say goodbye to markup `</</>>>`. Build reactive UIs with pure JavaScript.
4
+
5
+ ## šŸš€ Quick Start
6
+
7
+ ### Option 1: Create New Project (Recommended)
8
+
9
+ ```bash
10
+ npx jux create my-app
11
+ cd my-app
12
+ npm run dev
13
+ ```
14
+
15
+ ### Option 2: Add to Existing Project
16
+
17
+ ```bash
18
+ # Install juxscript first
19
+ npm install juxscript
20
+
21
+ # Then initialize
22
+ npx jux init
23
+
24
+ # Start dev server
25
+ npx jux serve
26
+ ```
27
+
28
+ ## Why Install First?
29
+
30
+ JUX uses `esbuild`, `express`, and other tools that must be installed before the CLI can run. When you run `npm install juxscript`, these dependencies are automatically installed.
31
+
32
+ ## The web needs a higher level of abstraction: Meet **JUX**
2
33
 
3
34
 
4
35
  ```diff
package/bin/cli.js CHANGED
@@ -264,47 +264,24 @@ async function buildProject(isServe = false, wsPort = 3001) {
264
264
 
265
265
  // āœ… Bundle and get the generated filename
266
266
  const bundleStartTime = performance.now();
267
- const mainJsFilename = await bundleJuxFilesToRouter(PATHS.juxSource, PATHS.frontendDist, {
267
+ const bundleResult = await bundleJuxFilesToRouter(PATHS.juxSource, PATHS.frontendDist, {
268
268
  routePrefix: ''
269
269
  });
270
270
  const bundleTime = performance.now() - bundleStartTime;
271
271
 
272
- // Generate routes for index.html
273
- const routes = projectJuxFiles.map(juxFile => {
274
- const relativePath = path.relative(PATHS.juxSource, juxFile);
275
- const parsedPath = path.parse(relativePath);
276
-
277
- const rawFunctionName = parsedPath.dir
278
- ? `${parsedPath.dir.replace(/\//g, '_')}_${parsedPath.name}`
279
- : parsedPath.name;
280
-
281
- const functionName = rawFunctionName
282
- .replace(/[-_]/g, ' ')
283
- .split(' ')
284
- .map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
285
- .join('');
286
-
287
- const routePath = '/' + (parsedPath.dir ? `${parsedPath.dir}/` : '') + parsedPath.name;
288
-
289
- return {
290
- path: routePath.replace(/\/+/g, '/'),
291
- functionName
292
- };
293
- });
294
-
295
272
  // āœ… Generate unified index.html
296
273
  const indexStartTime = performance.now();
297
- generateIndexHtml(PATHS.frontendDist, routes, mainJsFilename);
274
+ generateIndexHtml(PATHS.frontendDist, bundleResult);
298
275
  const indexTime = performance.now() - indexStartTime;
299
276
 
300
277
  const totalBuildTime = performance.now() - buildStartTime;
301
278
 
302
- console.log(`\nāœ… Bundled ${projectJuxFiles.length} page(s) → ${PATHS.frontendDist}/${mainJsFilename}\n`);
279
+ // āœ… FIX: Use bundleResult.mainJsFilename instead of bare mainJsFilename
280
+ console.log(`\nāœ… Bundled ${projectJuxFiles.length} page(s) → ${PATHS.frontendDist}/${bundleResult.mainJsFilename}\n`);
303
281
 
304
282
  // āœ… Build summary with timing breakdown
305
283
  console.log(`šŸ“Š Build Summary:`);
306
284
  console.log(` ━━━━━━━━━━━━━━━━━━━━━━━━━━━━`);
307
- // console.log(` Documentation: ${docsTime.toFixed(0)}ms`);
308
285
  console.log(` Library copy: ${libTime.toFixed(0)}ms`);
309
286
  console.log(` Presets copy: ${presetsTime.toFixed(0)}ms`);
310
287
  console.log(` Assets copy: ${assetsTime.toFixed(0)}ms`);
@@ -322,7 +299,8 @@ async function buildProject(isServe = false, wsPort = 3001) {
322
299
  console.log(` FastAPI: app.mount("/", StaticFiles(directory="jux-dist"), name="static")`);
323
300
  console.log('');
324
301
  console.log('šŸ“ Available routes:');
325
- routes.forEach(r => {
302
+ // āœ… FIX: Use bundleResult.routes instead of local routes variable
303
+ bundleResult.routes.forEach(r => {
326
304
  console.log(` ${r.path}`);
327
305
  });
328
306
  console.log('');
@@ -0,0 +1,231 @@
1
+ import { BaseComponent } from './base/BaseComponent.js';
2
+ import { Chart, ChartConfiguration, ChartType, ChartOptions, ChartData } from 'chart.js/auto';
3
+
4
+ // filepath: /Users/timkerr/newprojects2025/compile-sqljs/packages/jux/lib/components/chart.ts
5
+
6
+ export interface ChartState {
7
+ type: ChartType;
8
+ data: ChartData;
9
+ options: ChartOptions;
10
+ style?: string;
11
+ class?: string;
12
+ visible?: boolean;
13
+ disabled?: boolean;
14
+ loading?: boolean;
15
+ }
16
+
17
+ /**
18
+ * Chart component using Chart.js
19
+ * Provides fluent API for creating and configuring charts
20
+ */
21
+ export class ChartComponent extends BaseComponent<ChartState> {
22
+ private static readonly TRIGGER_EVENTS: readonly string[] = [];
23
+ private static readonly CALLBACK_EVENTS: readonly string[] = ['render', 'update', 'destroy'];
24
+ private chartInstance: Chart | null = null;
25
+
26
+ constructor(id: string, type: ChartType = 'bar', options?: Partial<ChartState>) {
27
+ super(id, {
28
+ type,
29
+ data: { datasets: [] },
30
+ options: {},
31
+ ...options
32
+ });
33
+ }
34
+
35
+ protected getTriggerEvents(): readonly string[] {
36
+ return ChartComponent.TRIGGER_EVENTS;
37
+ }
38
+
39
+ protected getCallbackEvents(): readonly string[] {
40
+ return ChartComponent.CALLBACK_EVENTS;
41
+ }
42
+
43
+ /* ═════════════════════════════════════════════════════════════════
44
+ * CHART TYPE
45
+ * ═════════════════════════════════════════════════════════════════ */
46
+
47
+ type(value: ChartType): this {
48
+ this.state.type = value;
49
+ if (this.chartInstance) {
50
+ // Destroy and recreate chart with new type
51
+ const canvas = this.chartInstance.canvas;
52
+ this.chartInstance.destroy();
53
+ const config: ChartConfiguration = {
54
+ type: this.state.type,
55
+ data: this.state.data,
56
+ options: this.state.options
57
+ };
58
+ this.chartInstance = new Chart(canvas, config);
59
+ }
60
+ return this;
61
+ }
62
+
63
+ /* ═════════════════════════════════════════════════════════════════
64
+ * DATA CONFIGURATION
65
+ * ═════════════════════════════════════════════════════════════════ */
66
+
67
+ data(value: ChartData): this {
68
+ this.state.data = value;
69
+ if (this.chartInstance) {
70
+ this.chartInstance.data = value;
71
+ this.chartInstance.update();
72
+ }
73
+ return this;
74
+ }
75
+
76
+ labels(value: string[]): this {
77
+ this.state.data.labels = value;
78
+ if (this.chartInstance) {
79
+ this.chartInstance.data.labels = value;
80
+ this.chartInstance.update();
81
+ }
82
+ return this;
83
+ }
84
+
85
+ datasets(value: any[]): this {
86
+ this.state.data.datasets = value;
87
+ if (this.chartInstance) {
88
+ this.chartInstance.data.datasets = value;
89
+ this.chartInstance.update();
90
+ }
91
+ return this;
92
+ }
93
+
94
+ addDataset(dataset: any): this {
95
+ this.state.data.datasets.push(dataset);
96
+ if (this.chartInstance) {
97
+ this.chartInstance.data.datasets.push(dataset);
98
+ this.chartInstance.update();
99
+ }
100
+ return this;
101
+ }
102
+
103
+ /* ═════════════════════════════════════════════════════════════════
104
+ * OPTIONS CONFIGURATION
105
+ * ═════════════════════════════════════════════════════════════════ */
106
+
107
+ options(value: ChartOptions): this {
108
+ this.state.options = { ...this.state.options, ...value };
109
+ if (this.chartInstance) {
110
+ this.chartInstance.options = this.state.options;
111
+ this.chartInstance.update();
112
+ }
113
+ return this;
114
+ }
115
+
116
+ responsive(value: boolean = true): this {
117
+ return this.options({ responsive: value });
118
+ }
119
+
120
+ maintainAspectRatio(value: boolean = true): this {
121
+ return this.options({ maintainAspectRatio: value });
122
+ }
123
+
124
+ title(text: string, display: boolean = true): this {
125
+ return this.options({
126
+ plugins: {
127
+ ...this.state.options.plugins,
128
+ title: { display, text }
129
+ }
130
+ });
131
+ }
132
+
133
+ legend(display: boolean = true, position: 'top' | 'bottom' | 'left' | 'right' = 'top'): this {
134
+ return this.options({
135
+ plugins: {
136
+ ...this.state.options.plugins,
137
+ legend: { display, position }
138
+ }
139
+ });
140
+ }
141
+
142
+ tooltip(enabled: boolean = true): this {
143
+ return this.options({
144
+ plugins: {
145
+ ...this.state.options.plugins,
146
+ tooltip: { enabled }
147
+ }
148
+ });
149
+ }
150
+
151
+ /* ═════════════════════════════════════════════════════════════════
152
+ * CHART OPERATIONS
153
+ * ═════════════════════════════════════════════════════════════════ */
154
+
155
+ update(mode?: 'resize' | 'reset' | 'none' | 'hide' | 'show' | 'default'): this {
156
+ if (this.chartInstance) {
157
+ this.chartInstance.update(mode);
158
+ this._triggerCallback('update', this.chartInstance);
159
+ }
160
+ return this;
161
+ }
162
+
163
+ reset(): this {
164
+ if (this.chartInstance) {
165
+ this.chartInstance.reset();
166
+ }
167
+ return this;
168
+ }
169
+
170
+ destroy(): this {
171
+ if (this.chartInstance) {
172
+ this.chartInstance.destroy();
173
+ this.chartInstance = null;
174
+ this._triggerCallback('destroy');
175
+ }
176
+ return this;
177
+ }
178
+
179
+ getChart(): Chart | null {
180
+ return this.chartInstance;
181
+ }
182
+
183
+ /* ═════════════════════════════════════════════════════════════════
184
+ * RENDER
185
+ * ═════════════════════════════════════════════════════════════════ */
186
+
187
+ render(targetId?: string): this {
188
+ const container = this._setupContainer(targetId);
189
+
190
+ // Destroy existing chart
191
+ if (this.chartInstance) {
192
+ this.chartInstance.destroy();
193
+ }
194
+
195
+ // Clear container and create canvas
196
+ container.innerHTML = '';
197
+ const canvas = document.createElement('canvas');
198
+ canvas.id = `${this._id}-canvas`;
199
+
200
+ // Apply styles and classes
201
+ if (this.state.style) container.setAttribute('style', this.state.style);
202
+ if (this.state.class) container.className = this.state.class;
203
+ if (this.state.visible === false) container.style.display = 'none';
204
+
205
+ container.appendChild(canvas);
206
+
207
+ // Create Chart.js instance
208
+ const config: ChartConfiguration = {
209
+ type: this.state.type,
210
+ data: this.state.data,
211
+ options: this.state.options
212
+ };
213
+
214
+ this.chartInstance = new Chart(canvas, config);
215
+
216
+ // Wire events and syncs
217
+ this._wireStandardEvents(container);
218
+ this._wireAllSyncs();
219
+
220
+ this._triggerCallback('render', this.chartInstance);
221
+
222
+ return this;
223
+ }
224
+ }
225
+
226
+ /**
227
+ * Factory function for creating chart components
228
+ */
229
+ export function chart(id: string, type: ChartType = 'bar', options?: Partial<ChartState>): ChartComponent {
230
+ return new ChartComponent(id, type, options);
231
+ }
@@ -0,0 +1,347 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import * as acorn from 'acorn';
4
+ import { simple } from 'acorn-walk';
5
+ import { glob } from 'glob';
6
+ import { loadAndStripTypes, isTypeScript } from './ts-shim.js';
7
+
8
+ const vendors = new Set();
9
+ const processedFiles = new Set();
10
+ const rels = new Map();
11
+ const allFiles = new Set();
12
+ const cssFiles = new Set();
13
+ const assetFiles = new Set();
14
+
15
+ // āœ… Define asset extensions to track
16
+ const ASSET_EXTENSIONS = [
17
+ '.png', '.jpg', '.jpeg', '.gif', '.svg', '.webp', '.bmp', '.ico',
18
+ '.mp4', '.mov', '.avi', '.webm', '.ogv',
19
+ '.mp3', '.wav', '.ogg', '.m4a',
20
+ '.woff', '.woff2', '.ttf', '.otf', '.eot',
21
+ '.json', '.xml', '.csv', '.txt',
22
+ '.pdf', '.doc', '.docx', '.zip'
23
+ ];
24
+
25
+ function countAllSourceFiles(directories) {
26
+ const allFiles = new Set();
27
+
28
+ for (const dir of directories) {
29
+ const dirPath = path.resolve(dir);
30
+ if (!fs.existsSync(dirPath)) {
31
+ console.warn(`āš ļø Directory not found: ${dirPath}`);
32
+ continue;
33
+ }
34
+
35
+ const files = findSourceFiles(dirPath);
36
+ files.forEach(f => allFiles.add(f));
37
+ }
38
+
39
+ return allFiles;
40
+ }
41
+
42
+ function findSourceFiles(dir, fileList = []) {
43
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
44
+
45
+ for (const entry of entries) {
46
+ const fullPath = path.join(dir, entry.name);
47
+
48
+ if (entry.isDirectory()) {
49
+ if (!entry.name.startsWith('.') && entry.name !== 'node_modules') {
50
+ findSourceFiles(fullPath, fileList);
51
+ }
52
+ } else if (entry.isFile() && (entry.name.endsWith('.jux') || entry.name.endsWith('.js') || entry.name.endsWith('.ts'))) {
53
+ fileList.push(fullPath);
54
+ }
55
+ }
56
+
57
+ return fileList;
58
+ }
59
+
60
+ const getAllCode = (srcDir) => {
61
+ const pattern = path.join(srcDir, '**/*.{js,jux,ts}');
62
+ const files = glob.sync(pattern);
63
+ const codeMap = {};
64
+
65
+ files.forEach(filePath => {
66
+ const rawCode = fs.readFileSync(filePath, 'utf-8');
67
+ const code = loadAndStripTypes(filePath, rawCode);
68
+ codeMap[filePath] = code;
69
+ });
70
+
71
+ return codeMap;
72
+ };
73
+
74
+ const findAllRels = (code, sourceFile) => {
75
+ try {
76
+ const ast = acorn.parse(code, {
77
+ ecmaVersion: 'latest',
78
+ sourceType: 'module'
79
+ });
80
+
81
+ simple(ast, {
82
+ ImportDeclaration(node) {
83
+ const { value } = node.source;
84
+ if (/^[./]/.test(value)) {
85
+ if (!rels.has(sourceFile)) {
86
+ rels.set(sourceFile, new Set());
87
+ }
88
+ rels.get(sourceFile).add(value);
89
+ }
90
+ },
91
+ CallExpression(node) {
92
+ if (node.callee.type === 'MemberExpression' &&
93
+ node.callee.object.name === 'jux' &&
94
+ node.callee.property.name === 'include' &&
95
+ node.arguments.length > 0 &&
96
+ node.arguments[0].type === 'Literal') {
97
+
98
+ const includePath = node.arguments[0].value;
99
+
100
+ if (!rels.has(sourceFile)) {
101
+ rels.set(sourceFile, new Set());
102
+ }
103
+ rels.get(sourceFile).add(includePath);
104
+ }
105
+ },
106
+ Literal(node) {
107
+ if (typeof node.value === 'string') {
108
+ const val = node.value;
109
+
110
+ if (/^[./]/.test(val)) {
111
+ const ext = path.extname(val).toLowerCase();
112
+
113
+ if (ASSET_EXTENSIONS.includes(ext)) {
114
+ if (!rels.has(sourceFile)) {
115
+ rels.set(sourceFile, new Set());
116
+ }
117
+ rels.get(sourceFile).add(val);
118
+ }
119
+ }
120
+ }
121
+ }
122
+ });
123
+ } catch (err) {
124
+ // Silent fail
125
+ }
126
+ };
127
+
128
+ const findVendors = (code) => {
129
+ try {
130
+ const ast = acorn.parse(code, {
131
+ ecmaVersion: 'latest',
132
+ sourceType: 'module'
133
+ });
134
+
135
+ simple(ast, {
136
+ ImportDeclaration(node) {
137
+ const { value } = node.source;
138
+ if (!/^[./]/.test(value)) {
139
+ vendors.add(value);
140
+ }
141
+ }
142
+ });
143
+ } catch (err) {
144
+ // Silent fail
145
+ }
146
+ };
147
+
148
+ function processCodeDirs(directories) {
149
+ const allCodeMaps = {};
150
+ for (const dir of directories) {
151
+ const codeMap = getAllCode(dir);
152
+ Object.assign(allCodeMaps, codeMap);
153
+ }
154
+
155
+ Object.keys(allCodeMaps).forEach(filePath => {
156
+ allFiles.add(path.resolve(filePath));
157
+ });
158
+
159
+ for (const filePath in allCodeMaps) {
160
+ if (!processedFiles.has(filePath)) {
161
+ const code = allCodeMaps[filePath];
162
+ findVendors(code);
163
+ findAllRels(code, filePath);
164
+ processedFiles.add(filePath);
165
+ }
166
+ }
167
+
168
+ resolveAllRelativeImports();
169
+ }
170
+
171
+ function resolveAllRelativeImports() {
172
+ const visited = new Set();
173
+ const toProcess = Array.from(rels.keys());
174
+
175
+ while (toProcess.length > 0) {
176
+ const currentFile = toProcess.shift();
177
+
178
+ if (visited.has(currentFile)) continue;
179
+ visited.add(currentFile);
180
+
181
+ allFiles.add(currentFile);
182
+
183
+ const imports = rels.get(currentFile);
184
+ if (!imports) continue;
185
+
186
+ const sourceDir = path.dirname(currentFile);
187
+
188
+ imports.forEach(relImport => {
189
+ const basePath = path.resolve(sourceDir, relImport);
190
+
191
+ const ext = path.extname(relImport).toLowerCase();
192
+
193
+ if (ext === '.css') {
194
+ if (fs.existsSync(basePath)) {
195
+ const absolutePath = path.resolve(basePath);
196
+ allFiles.add(absolutePath);
197
+ cssFiles.add(absolutePath);
198
+ }
199
+ return;
200
+ }
201
+
202
+ if (ASSET_EXTENSIONS.includes(ext)) {
203
+ if (fs.existsSync(basePath)) {
204
+ const absolutePath = path.resolve(basePath);
205
+ allFiles.add(absolutePath);
206
+ assetFiles.add(absolutePath);
207
+ }
208
+ return;
209
+ }
210
+
211
+ const extensions = ['', '.js', '.jux', '.ts'];
212
+
213
+ for (const extSuffix of extensions) {
214
+ const fullPath = basePath + extSuffix;
215
+
216
+ if (fs.existsSync(fullPath)) {
217
+ const absolutePath = path.resolve(fullPath);
218
+ allFiles.add(absolutePath);
219
+
220
+ if (!visited.has(fullPath) && !processedFiles.has(fullPath)) {
221
+ try {
222
+ const content = fs.readFileSync(fullPath, 'utf-8');
223
+ const code = loadAndStripTypes(fullPath, content);
224
+
225
+ findVendors(code);
226
+ findAllRels(code, fullPath);
227
+ processedFiles.add(fullPath);
228
+
229
+ if (rels.has(fullPath)) {
230
+ toProcess.push(fullPath);
231
+ }
232
+ } catch (err) {
233
+ // Silent fail
234
+ }
235
+ }
236
+
237
+ break;
238
+ }
239
+ }
240
+ });
241
+ }
242
+ }
243
+
244
+ // āœ… LEGACY EXPORTS (for backward compatibility)
245
+ export const analyzeVendors = (files) => {
246
+ vendors.clear();
247
+ for (const filePath in files) {
248
+ if (filePath.endsWith('.js') || filePath.endsWith('.jux') || filePath.endsWith('.ts')) {
249
+ const rawCode = files[filePath];
250
+ const code = loadAndStripTypes(filePath, rawCode);
251
+ findVendors(code);
252
+ }
253
+ }
254
+ return Array.from(vendors);
255
+ }
256
+
257
+ export const clearVendors = () => {
258
+ vendors.clear();
259
+ }
260
+
261
+ export const getVendors = () => {
262
+ return Array.from(vendors);
263
+ }
264
+
265
+ // āœ… NEW: Main analysis function that returns everything
266
+ export function analyzeProject(directories = ['./jux', './lib']) {
267
+ // Clear previous state
268
+ vendors.clear();
269
+ processedFiles.clear();
270
+ rels.clear();
271
+ allFiles.clear();
272
+ cssFiles.clear();
273
+ assetFiles.clear();
274
+
275
+ // Run analysis
276
+ processCodeDirs(directories);
277
+
278
+ // Return comprehensive analysis results
279
+ return {
280
+ vendors: Array.from(vendors),
281
+ allFiles: Array.from(allFiles),
282
+ cssFiles: Array.from(cssFiles),
283
+ assetFiles: Array.from(assetFiles),
284
+ relativeImports: rels,
285
+
286
+ // Categorized files
287
+ juxFiles: Array.from(allFiles).filter(f => f.endsWith('.jux')),
288
+ jsFiles: Array.from(allFiles).filter(f => f.endsWith('.js')),
289
+ tsFiles: Array.from(allFiles).filter(f => f.endsWith('.ts')),
290
+
291
+ // Asset breakdown
292
+ assets: {
293
+ images: Array.from(assetFiles).filter(f => {
294
+ const ext = path.extname(f).toLowerCase();
295
+ return ['.png', '.jpg', '.jpeg', '.gif', '.svg', '.webp', '.bmp', '.ico'].includes(ext);
296
+ }),
297
+ videos: Array.from(assetFiles).filter(f => {
298
+ const ext = path.extname(f).toLowerCase();
299
+ return ['.mp4', '.mov', '.avi', '.webm', '.ogv'].includes(ext);
300
+ }),
301
+ audio: Array.from(assetFiles).filter(f => {
302
+ const ext = path.extname(f).toLowerCase();
303
+ return ['.mp3', '.wav', '.ogg', '.m4a'].includes(ext);
304
+ }),
305
+ fonts: Array.from(assetFiles).filter(f => {
306
+ const ext = path.extname(f).toLowerCase();
307
+ return ['.woff', '.woff2', '.ttf', '.otf', '.eot'].includes(ext);
308
+ }),
309
+ data: Array.from(assetFiles).filter(f => {
310
+ const ext = path.extname(f).toLowerCase();
311
+ return ['.json', '.xml', '.csv', '.txt'].includes(ext);
312
+ })
313
+ },
314
+
315
+ // Summary stats
316
+ stats: {
317
+ totalFiles: allFiles.size,
318
+ totalVendors: vendors.size,
319
+ totalCSS: cssFiles.size,
320
+ totalAssets: assetFiles.size,
321
+ filesWithImports: rels.size
322
+ }
323
+ };
324
+ }
325
+
326
+ // āœ… Export constants
327
+ export { ASSET_EXTENSIONS };
328
+
329
+ export default {
330
+ analyzeProject,
331
+ analyzeVendors,
332
+ clearVendors,
333
+ getVendors,
334
+ ASSET_EXTENSIONS
335
+ };
336
+
337
+ function main() {
338
+ const analysis = analyzeProject(['./jux', './lib']);
339
+
340
+ console.log('External vendors:', analysis.vendors);
341
+ console.log('Total files:', analysis.stats.totalFiles);
342
+ }
343
+
344
+ // Only run main if executed directly
345
+ if (import.meta.url === `file://${process.argv[1]}`) {
346
+ main();
347
+ }
File without changes
File without changes
File without changes