juxscript 1.1.2 → 1.1.4

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 (67) hide show
  1. package/machinery/build3.js +7 -91
  2. package/machinery/compiler3.js +3 -209
  3. package/machinery/config.js +93 -6
  4. package/machinery/serve.js +255 -0
  5. package/machinery/watcher.js +49 -161
  6. package/package.json +19 -5
  7. package/lib/components/alert.ts +0 -200
  8. package/lib/components/app.ts +0 -247
  9. package/lib/components/badge.ts +0 -101
  10. package/lib/components/base/BaseComponent.ts +0 -421
  11. package/lib/components/base/FormInput.ts +0 -227
  12. package/lib/components/button.ts +0 -178
  13. package/lib/components/card.ts +0 -173
  14. package/lib/components/chart.ts +0 -231
  15. package/lib/components/checkbox.ts +0 -242
  16. package/lib/components/code.ts +0 -123
  17. package/lib/components/container.ts +0 -140
  18. package/lib/components/data.ts +0 -135
  19. package/lib/components/datepicker.ts +0 -234
  20. package/lib/components/dialog.ts +0 -172
  21. package/lib/components/divider.ts +0 -100
  22. package/lib/components/dropdown.ts +0 -186
  23. package/lib/components/element.ts +0 -267
  24. package/lib/components/fileupload.ts +0 -309
  25. package/lib/components/grid.ts +0 -291
  26. package/lib/components/guard.ts +0 -92
  27. package/lib/components/heading.ts +0 -96
  28. package/lib/components/helpers.ts +0 -41
  29. package/lib/components/hero.ts +0 -224
  30. package/lib/components/icon.ts +0 -178
  31. package/lib/components/icons.ts +0 -464
  32. package/lib/components/include.ts +0 -410
  33. package/lib/components/input.ts +0 -457
  34. package/lib/components/list.ts +0 -419
  35. package/lib/components/loading.ts +0 -100
  36. package/lib/components/menu.ts +0 -275
  37. package/lib/components/modal.ts +0 -284
  38. package/lib/components/nav.ts +0 -257
  39. package/lib/components/paragraph.ts +0 -97
  40. package/lib/components/progress.ts +0 -159
  41. package/lib/components/radio.ts +0 -278
  42. package/lib/components/req.ts +0 -303
  43. package/lib/components/script.ts +0 -41
  44. package/lib/components/select.ts +0 -252
  45. package/lib/components/sidebar.ts +0 -275
  46. package/lib/components/style.ts +0 -41
  47. package/lib/components/switch.ts +0 -246
  48. package/lib/components/table.ts +0 -1249
  49. package/lib/components/tabs.ts +0 -250
  50. package/lib/components/theme-toggle.ts +0 -293
  51. package/lib/components/tooltip.ts +0 -144
  52. package/lib/components/view.ts +0 -190
  53. package/lib/components/write.ts +0 -272
  54. package/lib/layouts/default.css +0 -260
  55. package/lib/layouts/figma.css +0 -334
  56. package/lib/reactivity/state.ts +0 -78
  57. package/lib/utils/fetch.ts +0 -553
  58. package/machinery/ast.js +0 -347
  59. package/machinery/build.js +0 -466
  60. package/machinery/bundleAssets.js +0 -0
  61. package/machinery/bundleJux.js +0 -0
  62. package/machinery/bundleVendors.js +0 -0
  63. package/machinery/doc-generator.js +0 -136
  64. package/machinery/imports.js +0 -155
  65. package/machinery/server.js +0 -166
  66. package/machinery/ts-shim.js +0 -46
  67. package/machinery/validators/file-validator.js +0 -123
@@ -1,155 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import { fileURLToPath } from 'url';
4
-
5
- const __filename = fileURLToPath(import.meta.url);
6
- const __dirname = path.dirname(__filename);
7
- const REGISTRY_PATH = path.join(__dirname, '../lib/registry/packages.json');
8
-
9
- /**
10
- * Load package registry
11
- */
12
- function loadRegistry() {
13
- if (!fs.existsSync(REGISTRY_PATH)) {
14
- return {};
15
- }
16
- return JSON.parse(fs.readFileSync(REGISTRY_PATH, 'utf-8'));
17
- }
18
-
19
- /**
20
- * Parse @import directives from Jux code
21
- */
22
- export function parseImports(juxCode) {
23
- const imports = [];
24
- const lines = juxCode.split('\n');
25
-
26
- for (let i = 0; i < lines.length; i++) {
27
- const line = lines[i].trim();
28
-
29
- // Stop parsing when we hit actual code (non-directive, non-comment)
30
- if (line && !line.startsWith('@') && !line.startsWith('//') && !line.startsWith('/*')) {
31
- break;
32
- }
33
-
34
- // Match @import directive
35
- const importMatch = line.match(/^@import\s+(.+)$/);
36
- if (importMatch) {
37
- const importSpec = importMatch[1].trim();
38
- imports.push({
39
- line: i + 1,
40
- raw: importSpec,
41
- resolved: resolveImport(importSpec)
42
- });
43
-
44
- if (process.env.JUX_VERBOSE) {
45
- console.log(` [Line ${i + 1}] Found @import: ${importSpec}`);
46
- }
47
- }
48
- }
49
-
50
- return imports;
51
- }
52
-
53
- /**
54
- * Resolve import specification to URL/path
55
- */
56
- export function resolveImport(importSpec) {
57
- // Remove quotes if present
58
- const cleaned = importSpec.replace(/^['"]|['"]$/g, '');
59
-
60
- // Direct URL (starts with http:// or https://)
61
- if (cleaned.startsWith('http://') || cleaned.startsWith('https://')) {
62
- return {
63
- type: 'cdn',
64
- url: cleaned,
65
- source: 'direct'
66
- };
67
- }
68
-
69
- // Local file (starts with ./ or ../ or /)
70
- if (cleaned.startsWith('./') || cleaned.startsWith('../') || cleaned.startsWith('/')) {
71
- return {
72
- type: 'local',
73
- path: cleaned,
74
- source: 'file'
75
- };
76
- }
77
-
78
- // Unknown/unsupported
79
- return {
80
- type: 'unknown',
81
- name: cleaned,
82
- error: `Import "${cleaned}" must be a URL (https://...) or relative path (./...)`
83
- };
84
- }
85
-
86
- /**
87
- * Auto-detect component dependencies
88
- */
89
- function detectComponentDependencies(usedComponents) {
90
- const componentDeps = {
91
- 'chart': 'chart.js'
92
- // Add more mappings as needed
93
- };
94
-
95
- const deps = new Set();
96
-
97
- usedComponents.forEach(comp => {
98
- if (componentDeps[comp]) {
99
- deps.add(componentDeps[comp]);
100
- }
101
- });
102
-
103
- return Array.from(deps).map(pkg => ({
104
- auto: true,
105
- resolved: resolveImport(pkg)
106
- }));
107
- }
108
-
109
- /**
110
- * Generate HTML script tags from resolved imports
111
- */
112
- export function generateImportTags(imports) {
113
- const tags = [];
114
- const seen = new Set();
115
-
116
- for (const imp of imports) {
117
- const resolved = imp.resolved;
118
-
119
- if (resolved.type === 'unknown') {
120
- tags.push(`<!-- ERROR: ${resolved.error} -->`);
121
- continue;
122
- }
123
-
124
- const key = resolved.url || resolved.path;
125
- if (seen.has(key)) continue;
126
- seen.add(key);
127
-
128
- if (resolved.type === 'cdn') {
129
- tags.push(` <script src="${resolved.url}"></script>`);
130
- } else if (resolved.type === 'local') {
131
- tags.push(` <script type="module" src="${resolved.path}"></script>`);
132
- }
133
- }
134
-
135
- return tags.join('\n');
136
- }
137
-
138
- /**
139
- * Validate all imports are resolvable
140
- */
141
- export function validateImports(imports) {
142
- const errors = [];
143
-
144
- imports.forEach(imp => {
145
- if (imp.resolved.type === 'unknown') {
146
- errors.push({
147
- line: imp.line,
148
- message: imp.resolved.error,
149
- raw: imp.raw
150
- });
151
- }
152
- });
153
-
154
- return errors;
155
- }
@@ -1,166 +0,0 @@
1
- import express from 'express';
2
- import http from 'http';
3
- import path from 'path';
4
- import fs from 'fs';
5
- import { fileURLToPath } from 'url';
6
- import { startWatcher } from './watcher.js';
7
- import { WebSocketServer } from 'ws';
8
-
9
- const __filename = fileURLToPath(import.meta.url);
10
- const __dirname = path.dirname(__filename);
11
-
12
- /**
13
- * Try to start a server on a port, with fallback to next port if busy
14
- * Returns the actual port that was successfully allocated
15
- */
16
- async function tryPort(startPort, maxAttempts = 5, reservedPorts = []) {
17
- for (let attempt = 0; attempt < maxAttempts; attempt++) {
18
- const port = startPort + attempt;
19
-
20
- // Skip if this port is already reserved
21
- if (reservedPorts.includes(port)) {
22
- continue;
23
- }
24
-
25
- try {
26
- // Test if port is available
27
- await new Promise((resolve, reject) => {
28
- const testServer = http.createServer();
29
- testServer.once('error', reject);
30
- testServer.once('listening', () => {
31
- testServer.close();
32
- resolve(port);
33
- });
34
- testServer.listen(port);
35
- });
36
- return port;
37
- } catch (err) {
38
- if (err.code === 'EADDRINUSE') {
39
- if (attempt < maxAttempts - 1) {
40
- console.log(` Port ${port} in use, trying ${port + 1}...`);
41
- }
42
- continue;
43
- }
44
- throw err;
45
- }
46
- }
47
- throw new Error(`Could not find available port after ${maxAttempts} attempts starting from ${startPort}`);
48
- }
49
-
50
- async function serve(httpPort = 3000, wsPort = 3001, distDir = './.jux-dist') {
51
- const app = express();
52
- const absoluteDistDir = path.resolve(distDir);
53
- const projectRoot = path.resolve('.');
54
-
55
- app.use(express.json());
56
-
57
- if (!fs.existsSync(absoluteDistDir)) {
58
- console.error(`❌ Error: ${path.basename(distDir)}/ directory not found at ${absoluteDistDir}`);
59
- console.error(' Run: npx jux build\n');
60
- process.exit(1);
61
- }
62
-
63
- // Strong cache prevention
64
- app.use((req, res, next) => {
65
- res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0');
66
- res.setHeader('Pragma', 'no-cache');
67
- res.setHeader('Expires', '0');
68
- res.setHeader('ETag', 'W/"' + Date.now() + '"');
69
- next();
70
- });
71
-
72
- // ✅ ADD: Explicit MIME type for JavaScript files
73
- app.use((req, res, next) => {
74
- if (req.path.endsWith('.js')) {
75
- res.setHeader('Content-Type', 'application/javascript; charset=utf-8');
76
- }
77
- next();
78
- });
79
-
80
- // Serve static files
81
- app.use(express.static(absoluteDistDir));
82
-
83
- // ✅ FIX: Only apply SPA fallback to routes, not static files
84
- app.use((req, res, next) => {
85
- // Skip SPA fallback for file extensions (static assets)
86
- if (/\.[a-zA-Z0-9]+$/.test(req.path)) {
87
- return res.status(404).send('File not found');
88
- }
89
-
90
- // SPA fallback for routes only
91
- if (req.accepts('html')) {
92
- const indexPath = path.join(absoluteDistDir, 'index.html');
93
- if (fs.existsSync(indexPath)) {
94
- res.sendFile(indexPath);
95
- } else {
96
- res.status(404).send('index.html not found. Run `npx jux build` first.');
97
- }
98
- } else {
99
- res.status(404).send('Not found');
100
- }
101
- });
102
-
103
- // Find available ports sequentially to avoid collision
104
- console.log('🔍 Finding available ports...');
105
-
106
- // First, find HTTP port
107
- const availableHttpPort = await tryPort(httpPort);
108
-
109
- // Then find WS port, excluding the HTTP port we just allocated
110
- const availableWsPort = await tryPort(wsPort, 5, [availableHttpPort]);
111
-
112
- // Create HTTP server
113
- const server = http.createServer(app);
114
-
115
- // WebSocket server for hot reload
116
- const wss = new WebSocketServer({ port: availableWsPort });
117
- const clients = [];
118
-
119
- wss.on('connection', (ws) => {
120
- clients.push(ws);
121
- console.log('🔌 WebSocket client connected');
122
-
123
- ws.on('close', () => {
124
- console.log('🔌 WebSocket client disconnected');
125
- const index = clients.indexOf(ws);
126
- if (index > -1) clients.splice(index, 1);
127
- });
128
-
129
- ws.on('error', (error) => {
130
- console.error('WebSocket error:', error);
131
- });
132
- });
133
-
134
- console.log(`🔌 WebSocket server running at ws://localhost:${availableWsPort}`);
135
-
136
- // Start HTTP server
137
- server.listen(availableHttpPort, () => {
138
- console.log(`🚀 JUX dev server running at http://localhost:${availableHttpPort}`);
139
- console.log(` Serving: ${absoluteDistDir}`);
140
- console.log(` Press Ctrl+C to stop\n`);
141
- });
142
-
143
- // Start file watcher
144
- const juxSource = path.join(projectRoot, 'jux');
145
- if (fs.existsSync(juxSource)) {
146
- console.log(`👀 Watching: ${juxSource}\n`);
147
- startWatcher(juxSource, absoluteDistDir, clients);
148
- }
149
-
150
- // Graceful shutdown
151
- const shutdown = async () => {
152
- console.log('\n\n👋 Shutting down server...');
153
- wss.close();
154
- server.close();
155
- process.exit(0);
156
- };
157
-
158
- process.on('SIGINT', shutdown);
159
- process.on('SIGTERM', shutdown);
160
-
161
- return { server, httpPort: availableHttpPort, wsPort: availableWsPort };
162
- }
163
-
164
- export async function start(httpPort = 3000, wsPort = 3001, distDir = './.jux-dist') {
165
- return serve(httpPort, wsPort, distDir);
166
- }
@@ -1,46 +0,0 @@
1
- import esbuild from 'esbuild';
2
-
3
- /**
4
- * TypeScript Shim - Strips type annotations using esbuild
5
- * This is rock-solid and handles ALL TypeScript syntax correctly
6
- */
7
-
8
- /**
9
- * Strip TypeScript type annotations from code using esbuild
10
- *
11
- * @param {string} code - TypeScript source code
12
- * @returns {string} - JavaScript code with types removed
13
- */
14
- export function stripTypes(code) {
15
- try {
16
- // ✅ Use esbuild to transform TypeScript → JavaScript
17
- const result = esbuild.transformSync(code, {
18
- loader: 'ts',
19
- format: 'esm',
20
- target: 'es2020'
21
- });
22
-
23
- return result.code;
24
- } catch (err) {
25
- console.error('❌ Failed to strip TypeScript:', err.message);
26
- // Return original code if transformation fails
27
- return code;
28
- }
29
- }
30
-
31
- /**
32
- * Check if a file is TypeScript based on extension
33
- */
34
- export function isTypeScript(filePath) {
35
- return filePath.endsWith('.ts') || filePath.endsWith('.tsx');
36
- }
37
-
38
- /**
39
- * Load and parse a file, automatically stripping types if it's TypeScript
40
- */
41
- export function loadAndStripTypes(filePath, fileContent) {
42
- if (isTypeScript(filePath)) {
43
- return stripTypes(fileContent);
44
- }
45
- return fileContent;
46
- }
@@ -1,123 +0,0 @@
1
- /**
2
- * File validation utilities for Jux compiler
3
- * Validates file types and content security
4
- */
5
- export class FileValidator {
6
- constructor() {
7
- this.cssExtensions = /\.(css|scss|sass|less)$/i;
8
- this.jsExtensions = /\.(js|mjs|ts|tsx|jsx)$/i;
9
- this.imageExtensions = /\.(png|jpg|jpeg|gif|svg|webp|ico|bmp)$/i;
10
- }
11
-
12
- /**
13
- * Check if file is a CSS file
14
- */
15
- isCSSFile(filepath) {
16
- return this.cssExtensions.test(filepath);
17
- }
18
-
19
- /**
20
- * Check if file is a JavaScript file
21
- */
22
- isJavaScriptFile(filepath) {
23
- return this.jsExtensions.test(filepath);
24
- }
25
-
26
- /**
27
- * Check if file is an image file
28
- */
29
- isImageFile(filepath) {
30
- return this.imageExtensions.test(filepath);
31
- }
32
-
33
- /**
34
- * Validate CSS content for security issues
35
- * Detects <script> tags that could be injected
36
- */
37
- validateStyleContent(content, source = 'unknown') {
38
- if (/<script/i.test(content)) {
39
- throw new Error(
40
- `🚨 Security Error: <script> tag detected in ${source}\n` +
41
- `CSS content must not contain script tags.`
42
- );
43
- }
44
-
45
- if (/<\/script/i.test(content)) {
46
- throw new Error(
47
- `🚨 Security Error: </script> tag detected in ${source}\n` +
48
- `CSS content must not contain script tags.`
49
- );
50
- }
51
-
52
- return content;
53
- }
54
-
55
- /**
56
- * Determine import type based on file extension
57
- * Returns: 'css' | 'js' | 'image' | 'unknown'
58
- */
59
- validateImportPath(importPath) {
60
- // Handle URLs
61
- if (importPath.startsWith('http://') || importPath.startsWith('https://')) {
62
- // Try to infer from URL
63
- if (this.isCSSFile(importPath)) return { type: 'css', path: importPath };
64
- if (this.isJavaScriptFile(importPath)) return { type: 'js', path: importPath };
65
- if (this.isImageFile(importPath)) return { type: 'image', path: importPath };
66
-
67
- // Default to unknown for CDN URLs without clear extensions
68
- return { type: 'unknown', path: importPath };
69
- }
70
-
71
- // Local files
72
- if (this.isCSSFile(importPath)) {
73
- return { type: 'css', path: importPath };
74
- }
75
-
76
- if (this.isJavaScriptFile(importPath)) {
77
- return { type: 'js', path: importPath };
78
- }
79
-
80
- if (this.isImageFile(importPath)) {
81
- return { type: 'image', path: importPath };
82
- }
83
-
84
- return { type: 'unknown', path: importPath };
85
- }
86
-
87
- /**
88
- * Validate array of imports and categorize them
89
- * Returns categorized imports with warnings
90
- */
91
- categorizeImports(imports) {
92
- const categorized = {
93
- css: [],
94
- js: [],
95
- images: [],
96
- unknown: []
97
- };
98
-
99
- const warnings = [];
100
-
101
- for (const importPath of imports) {
102
- const result = this.validateImportPath(importPath);
103
-
104
- if (result.type === 'unknown') {
105
- warnings.push(
106
- `⚠️ Unknown import type: ${importPath}\n` +
107
- ` Supported: .css/.scss/.sass, .js/.ts, .png/.jpg/.svg`
108
- );
109
- }
110
-
111
- categorized[result.type === 'unknown' ? 'unknown' : result.type].push(result.path);
112
- }
113
-
114
- return { categorized, warnings };
115
- }
116
-
117
- /**
118
- * Check if inline style content is empty or whitespace-only
119
- */
120
- isEmptyStyle(styleContent) {
121
- return !styleContent || styleContent.trim().length === 0;
122
- }
123
- }