htmlxify 1.0.0__py3-none-any.whl

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.
htmlxify/__init__.py ADDED
File without changes
htmlxify/cli.py ADDED
@@ -0,0 +1,153 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ htmlxify Compiler - Command Line Interface
4
+ Usage: htmlxify input.htmlxify [output-dir]
5
+ """
6
+
7
+ import sys
8
+ import argparse
9
+ from pathlib import Path
10
+
11
+ from htmlxify.parser.ast_builder import ASTBuilder
12
+ from htmlxify.parser.indent_processor import IndentationProcessor
13
+ from htmlxify.validator.semantic import SemanticValidator
14
+ from htmlxify.generators.html_gen import HTMLGenerator
15
+ from htmlxify.generators.css_gen import CSSGenerator
16
+ from htmlxify.generators.js_gen import JSGenerator
17
+
18
+
19
+ def main():
20
+ """Main entry point"""
21
+ parser = argparse.ArgumentParser(
22
+ description='htmlxify Compiler',
23
+ epilog='Example: htmlxify index.htmlxify dist/'
24
+ )
25
+
26
+ parser.add_argument(
27
+ 'input',
28
+ help='Input .htmlxify file to compile'
29
+ )
30
+
31
+ parser.add_argument(
32
+ 'output',
33
+ nargs='?',
34
+ default='dist',
35
+ help='Output directory (default: dist)'
36
+ )
37
+
38
+ parser.add_argument(
39
+ '--version',
40
+ action='version',
41
+ version='htmlxify Compiler 1.0.0'
42
+ )
43
+
44
+ parser.add_argument(
45
+ '--verbose', '-v',
46
+ action='store_true',
47
+ help='Verbose output'
48
+ )
49
+
50
+ args = parser.parse_args()
51
+
52
+ # Validate input file
53
+ input_path = Path(args.input)
54
+ if not input_path.exists():
55
+ print(f"ERROR: File '{args.input}' not found")
56
+ sys.exit(1)
57
+
58
+ if input_path.suffix not in ['.htmlxify']:
59
+ print(f"⚠️ Warning: File extension should be .htmlxify")
60
+
61
+ # Read source
62
+ try:
63
+ source = input_path.read_text(encoding='utf-8')
64
+ except Exception as e:
65
+ print(f"ERROR: reading file: {e}")
66
+ sys.exit(1)
67
+
68
+ print(f"\nCompiling {input_path.name}...\n")
69
+
70
+ try:
71
+ # Step 1: Parse
72
+ if args.verbose:
73
+ print("Step 1/6: Parsing...")
74
+
75
+ ast_builder = ASTBuilder(source, input_path.name)
76
+ ast = ast_builder.parse()
77
+ print("OK - Parsing complete")
78
+
79
+ # Step 2: Process indentation
80
+ if args.verbose:
81
+ print("Step 2/6: Processing indentation...")
82
+
83
+ indent_processor = IndentationProcessor()
84
+ ast = indent_processor.process(ast)
85
+ print("OK - Indentation processed")
86
+
87
+ # Step 3: Validate
88
+ if args.verbose:
89
+ print("Step 3/6: Validating...")
90
+
91
+ validator = SemanticValidator(ast, input_path.name)
92
+ if not validator.validate():
93
+ sys.exit(1)
94
+ print("OK - Validation complete")
95
+
96
+ # Step 4: Create output directory
97
+ output_dir = Path(args.output)
98
+ output_dir.mkdir(exist_ok=True, parents=True)
99
+
100
+ # Step 5: Generate HTML
101
+ if args.verbose:
102
+ print("Step 4/6: Generating HTML...")
103
+
104
+ html_gen = HTMLGenerator(ast, input_path.name)
105
+ html, source_map = html_gen.generate()
106
+
107
+ html_path = output_dir / input_path.name.replace('.htmlxify', '.html')
108
+ html_path.write_text(html, encoding='utf-8')
109
+
110
+ # Write source map
111
+ source_map_path = output_dir / (input_path.name.replace('.htmlxify', '.html') + '.map')
112
+ source_map_path.write_text(source_map, encoding='utf-8')
113
+
114
+ print(f"OK - Generated {html_path}")
115
+
116
+ # Step 6: Generate CSS
117
+ if args.verbose:
118
+ print("Step 5/6: Generating CSS...")
119
+
120
+ css_gen = CSSGenerator(ast)
121
+ css = css_gen.generate()
122
+
123
+ css_path = output_dir / input_path.name.replace('.htmlxify', '.css')
124
+ css_path.write_text(css, encoding='utf-8')
125
+ print(f"OK - Generated {css_path}")
126
+
127
+ # Step 7: Generate JavaScript
128
+ if args.verbose:
129
+ print("Step 6/6: Generating JavaScript...")
130
+
131
+ js_gen = JSGenerator(ast)
132
+ js = js_gen.generate()
133
+
134
+ js_path = output_dir / input_path.name.replace('.htmlxify', '.js')
135
+ js_path.write_text(js, encoding='utf-8')
136
+ print(f"OK - Generated {js_path}")
137
+
138
+ print("\nCompilation successful!\n")
139
+
140
+ except KeyboardInterrupt:
141
+ print("\n\nCompilation cancelled by user")
142
+ sys.exit(1)
143
+
144
+ except Exception as e:
145
+ print(f"\nCompilation failed: {e}")
146
+ if args.verbose:
147
+ import traceback
148
+ traceback.print_exc()
149
+ sys.exit(1)
150
+
151
+
152
+ if __name__ == '__main__':
153
+ main()
File without changes
@@ -0,0 +1,574 @@
1
+ """
2
+ CSS Generator - Creates GPU-optimized CSS with default styles
3
+ """
4
+
5
+ import tinycss2
6
+ import cssbeautifier
7
+ from typing import Dict, Any, List, Set
8
+
9
+
10
+ class CSSGenerator:
11
+ """
12
+ Generates CSS with:
13
+ - Default semantic HTML styling
14
+ - GPU-accelerated animations
15
+ - Class-based styling
16
+ - Responsive design
17
+ """
18
+
19
+ # Default colors and spacing
20
+ DEFAULT_STYLES = """
21
+ /* Reset and Base Styles */
22
+ * {
23
+ margin: 0;
24
+ padding: 0;
25
+ box-sizing: border-box;
26
+ }
27
+
28
+ html {
29
+ font-size: 16px;
30
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
31
+ line-height: 1.6;
32
+ color: #333;
33
+ }
34
+
35
+ body {
36
+ background-color: #fff;
37
+ color: #333;
38
+ }
39
+
40
+ /* Typography */
41
+ h1, h2, h3, h4, h5, h6 {
42
+ font-weight: 600;
43
+ line-height: 1.3;
44
+ margin-bottom: 0.5em;
45
+ }
46
+
47
+ h1 { font-size: 2.5rem; }
48
+ h2 { font-size: 2rem; }
49
+ h3 { font-size: 1.5rem; }
50
+ h4 { font-size: 1.25rem; }
51
+ h5 { font-size: 1.1rem; }
52
+ h6 { font-size: 1rem; }
53
+
54
+ p { margin-bottom: 1em; }
55
+ a { color: #0066cc; text-decoration: none; }
56
+ a:hover { text-decoration: underline; }
57
+
58
+ /* Lists */
59
+ ul, ol {
60
+ margin-bottom: 1em;
61
+ margin-left: 2em;
62
+ }
63
+
64
+ li { margin-bottom: 0.5em; }
65
+
66
+ /* Tables */
67
+ table {
68
+ width: 100%;
69
+ border-collapse: collapse;
70
+ margin-bottom: 1em;
71
+ }
72
+
73
+ th, td {
74
+ padding: 0.75em;
75
+ text-align: left;
76
+ border-bottom: 1px solid #ddd;
77
+ }
78
+
79
+ th {
80
+ background-color: #f5f5f5;
81
+ font-weight: 600;
82
+ }
83
+
84
+ tr:hover { background-color: #f9f9f9; }
85
+
86
+ /* Forms */
87
+ input, textarea, select {
88
+ padding: 0.5em;
89
+ border: 1px solid #ddd;
90
+ border-radius: 4px;
91
+ font-family: inherit;
92
+ font-size: inherit;
93
+ }
94
+
95
+ input:focus, textarea:focus, select:focus {
96
+ outline: none;
97
+ border-color: #0066cc;
98
+ box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
99
+ }
100
+
101
+ button {
102
+ padding: 0.5em 1em;
103
+ background-color: #0066cc;
104
+ color: white;
105
+ border: none;
106
+ border-radius: 4px;
107
+ cursor: pointer;
108
+ font-weight: 600;
109
+ transition: background-color 0.2s;
110
+ }
111
+
112
+ button:hover {
113
+ background-color: #0052a3;
114
+ }
115
+
116
+ button:active {
117
+ transform: scale(0.98);
118
+ }
119
+
120
+ /* Interactive Elements */
121
+ details {
122
+ padding: 1em;
123
+ border: 1px solid #ddd;
124
+ border-radius: 4px;
125
+ margin-bottom: 1em;
126
+ }
127
+
128
+ summary {
129
+ cursor: pointer;
130
+ font-weight: 600;
131
+ user-select: none;
132
+ }
133
+
134
+ summary:hover {
135
+ color: #0066cc;
136
+ }
137
+
138
+ progress {
139
+ width: 100%;
140
+ height: 8px;
141
+ border-radius: 4px;
142
+ overflow: hidden;
143
+ }
144
+
145
+ progress::-webkit-progress-bar {
146
+ background-color: #ddd;
147
+ }
148
+
149
+ progress::-webkit-progress-value {
150
+ background-color: #0066cc;
151
+ }
152
+
153
+ meter {
154
+ width: 100%;
155
+ height: 8px;
156
+ }
157
+
158
+ /* Common Layout Classes */
159
+ .container {
160
+ max-width: 1200px;
161
+ margin: 0 auto;
162
+ padding: 0 1em;
163
+ }
164
+
165
+ .navbar {
166
+ background-color: #f8f9fa;
167
+ border-bottom: 1px solid #ddd;
168
+ padding: 1em 0;
169
+ position: sticky;
170
+ top: 0;
171
+ z-index: 100;
172
+ }
173
+
174
+ .navbar a {
175
+ color: #333;
176
+ margin: 0 1em;
177
+ }
178
+
179
+ .navbar a:hover {
180
+ color: #0066cc;
181
+ text-decoration: none;
182
+ }
183
+
184
+ .app-container {
185
+ min-height: 100vh;
186
+ display: flex;
187
+ flex-direction: column;
188
+ }
189
+
190
+ .hero {
191
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
192
+ color: white;
193
+ padding: 4em 1em;
194
+ text-align: center;
195
+ }
196
+
197
+ .hero-title {
198
+ font-size: 3rem;
199
+ margin-bottom: 0.5em;
200
+ }
201
+
202
+ .hero-subtitle {
203
+ font-size: 1.25rem;
204
+ margin-bottom: 2em;
205
+ opacity: 0.9;
206
+ }
207
+
208
+ .cta-button {
209
+ background-color: white;
210
+ color: #667eea;
211
+ padding: 0.75em 2em;
212
+ font-size: 1.1rem;
213
+ margin-top: 1em;
214
+ }
215
+
216
+ .cta-button:hover {
217
+ background-color: #f0f0f0;
218
+ }
219
+
220
+ /* Feature Grid */
221
+ .feature-grid {
222
+ display: grid;
223
+ grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
224
+ gap: 2em;
225
+ margin: 2em 0;
226
+ }
227
+
228
+ .feature-card {
229
+ padding: 2em;
230
+ border: 1px solid #ddd;
231
+ border-radius: 8px;
232
+ transition: transform 0.2s, box-shadow 0.2s;
233
+ }
234
+
235
+ .feature-card:hover {
236
+ transform: translateY(-4px);
237
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
238
+ }
239
+
240
+ .feature-badge {
241
+ display: inline-block;
242
+ padding: 0.25em 0.75em;
243
+ background-color: #e8f4f8;
244
+ color: #0066cc;
245
+ border-radius: 20px;
246
+ font-size: 0.9em;
247
+ margin-top: 1em;
248
+ }
249
+
250
+ /* Statistics */
251
+ .statistics {
252
+ padding: 3em 1em;
253
+ background-color: #f5f5f5;
254
+ }
255
+
256
+ .stats-container {
257
+ display: grid;
258
+ grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
259
+ gap: 2em;
260
+ max-width: 1200px;
261
+ margin: 0 auto;
262
+ }
263
+
264
+ .stat-item {
265
+ text-align: center;
266
+ padding: 1em;
267
+ }
268
+
269
+ .stat-item h4 {
270
+ font-size: 2em;
271
+ color: #0066cc;
272
+ margin-bottom: 0.5em;
273
+ }
274
+
275
+ /* Pricing Cards */
276
+ .pricing {
277
+ display: grid;
278
+ grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
279
+ gap: 2em;
280
+ padding: 2em 0;
281
+ }
282
+
283
+ .pricing-card {
284
+ padding: 2em;
285
+ border: 2px solid #ddd;
286
+ border-radius: 8px;
287
+ text-align: center;
288
+ transition: all 0.2s;
289
+ }
290
+
291
+ .pricing-card.featured {
292
+ border-color: #0066cc;
293
+ background-color: #f0f7ff;
294
+ transform: scale(1.05);
295
+ }
296
+
297
+ .pricing-card:hover {
298
+ box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
299
+ }
300
+
301
+ .badge {
302
+ display: inline-block;
303
+ background-color: #0066cc;
304
+ color: white;
305
+ padding: 0.25em 0.75em;
306
+ border-radius: 20px;
307
+ font-size: 0.85em;
308
+ margin-bottom: 1em;
309
+ }
310
+
311
+ .price {
312
+ font-size: 1.75em;
313
+ color: #0066cc;
314
+ font-weight: 600;
315
+ margin: 1em 0;
316
+ }
317
+
318
+ .features-list {
319
+ list-style: none;
320
+ margin: 1em 0;
321
+ }
322
+
323
+ .features-list li {
324
+ padding: 0.5em 0;
325
+ border-bottom: 1px solid #ddd;
326
+ }
327
+
328
+ /* Comparison Table */
329
+ .comparison {
330
+ width: 100%;
331
+ border-collapse: collapse;
332
+ }
333
+
334
+ .comparison th,
335
+ .comparison td {
336
+ padding: 1em;
337
+ border: 1px solid #ddd;
338
+ }
339
+
340
+ .comparison th {
341
+ background-color: #667eea;
342
+ color: white;
343
+ font-weight: 600;
344
+ }
345
+
346
+ .comparison tbody tr:nth-child(odd) {
347
+ background-color: #f9f9f9;
348
+ }
349
+
350
+ .comparison tbody tr:hover {
351
+ background-color: #f0f7ff;
352
+ }
353
+
354
+ /* Interactive Section */
355
+ .interactive-section {
356
+ padding: 2em 1em;
357
+ }
358
+
359
+ .faq-content {
360
+ padding: 1em 0;
361
+ }
362
+
363
+ /* Footer */
364
+ footer {
365
+ background-color: #333;
366
+ color: white;
367
+ padding: 2em 1em;
368
+ margin-top: auto;
369
+ }
370
+
371
+ .footer-content {
372
+ display: grid;
373
+ grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
374
+ gap: 2em;
375
+ max-width: 1200px;
376
+ margin: 0 auto;
377
+ margin-bottom: 2em;
378
+ }
379
+
380
+ .footer-column h4 {
381
+ color: white;
382
+ margin-bottom: 1em;
383
+ }
384
+
385
+ .footer-column ul {
386
+ list-style: none;
387
+ margin: 0;
388
+ }
389
+
390
+ .footer-column li {
391
+ margin-bottom: 0.5em;
392
+ }
393
+
394
+ .footer-column a {
395
+ color: #aaa;
396
+ }
397
+
398
+ .footer-column a:hover {
399
+ color: white;
400
+ }
401
+
402
+ .copyright {
403
+ text-align: center;
404
+ border-top: 1px solid #555;
405
+ padding-top: 1em;
406
+ margin-bottom: 0;
407
+ color: #aaa;
408
+ }
409
+
410
+ /* Animations */
411
+ @keyframes fade {
412
+ 0% { opacity: 0; transform: translateY(10px); }
413
+ 100% { opacity: 1; transform: translateY(0); }
414
+ }
415
+
416
+ @keyframes slide {
417
+ 0% { transform: translateX(-100%); }
418
+ 100% { transform: translateX(0); }
419
+ }
420
+
421
+ @keyframes bounce {
422
+ 0%, 100% { transform: translateY(0); }
423
+ 50% { transform: translateY(-10px); }
424
+ }
425
+
426
+ /* Responsive */
427
+ @media (max-width: 768px) {
428
+ h1 { font-size: 1.75rem; }
429
+ h2 { font-size: 1.5rem; }
430
+
431
+ .hero-title { font-size: 1.75rem; }
432
+ .feature-grid { grid-template-columns: 1fr; }
433
+ .stats-container { grid-template-columns: 1fr; }
434
+ .pricing { grid-template-columns: 1fr; }
435
+ .pricing-card.featured { transform: scale(1); }
436
+ .footer-content { grid-template-columns: repeat(2, 1fr); }
437
+ }
438
+
439
+ @media (max-width: 480px) {
440
+ body { font-size: 14px; }
441
+ .hero { padding: 2em 1em; }
442
+ .hero-title { font-size: 1.25rem; }
443
+ .footer-content { grid-template-columns: 1fr; }
444
+ }
445
+ """
446
+
447
+ def __init__(self, ast: Dict[str, Any]):
448
+ self.ast = ast
449
+ self.used_classes: Set[str] = set()
450
+ self.styles: List[str] = []
451
+ self.keyframes: List[str] = []
452
+
453
+ def generate(self) -> str:
454
+ """Generate CSS from AST"""
455
+ # Start with default styles
456
+ css = self.DEFAULT_STYLES
457
+
458
+ # Extract any custom styles
459
+ self._extract_styles(self.ast)
460
+
461
+ # Add extracted custom styles
462
+ if self.styles:
463
+ css += '\n\n/* Custom Styles */\n'
464
+ css += '\n\n'.join(self.styles)
465
+
466
+ # Add keyframes
467
+ if self.keyframes:
468
+ css += '\n\n/* Custom Keyframes */\n'
469
+ css += '\n\n'.join(self.keyframes)
470
+
471
+ return css
472
+
473
+ def _extract_styles(self, node: Any):
474
+ """Recursively extract styles from AST"""
475
+ if not isinstance(node, dict):
476
+ return
477
+
478
+ if node.get('type') == 'Element':
479
+ self._process_element_styles(node)
480
+
481
+ # Recurse
482
+ for child in node.get('children', []):
483
+ self._extract_styles(child)
484
+
485
+ def _process_element_styles(self, node: Dict[str, Any]):
486
+ """Process styles for single element"""
487
+ attrs = node.get('attributes', {})
488
+
489
+ # Track classes
490
+ for cls in node.get('classes', []):
491
+ self.used_classes.add(cls)
492
+
493
+ # Inline style attribute
494
+ if 'style' in attrs:
495
+ selector = self._build_selector(node)
496
+ style_rules = self._parse_style(attrs['style'])
497
+ if style_rules:
498
+ css_rule = f"{selector} {{\n " + "\n ".join(style_rules) + "\n}"
499
+ self.styles.append(css_rule)
500
+
501
+ # Animation (GPU-optimized)
502
+ if 'animate' in attrs:
503
+ selector = self._build_selector(node)
504
+ anim_name, anim_rules = self._generate_animation(
505
+ attrs['animate'], selector
506
+ )
507
+ rules = ['will-change: transform, opacity;', f'animation: {anim_name};']
508
+ css_rule = f"{selector} {{\n " + "\n ".join(rules) + "\n}"
509
+ self.styles.append(css_rule)
510
+
511
+ def _build_selector(self, node: Dict[str, Any]) -> str:
512
+ """Build CSS selector from node"""
513
+ parts = [node.get('tag', 'div')]
514
+
515
+ if node.get('id'):
516
+ parts.append(f"#{node['id']}")
517
+
518
+ if node.get('classes'):
519
+ parts.extend(f".{cls}" for cls in node['classes'])
520
+
521
+ return ''.join(parts)
522
+
523
+ def _parse_style(self, style_obj: Any) -> List[str]:
524
+ """Parse style object to CSS rules"""
525
+ rules = []
526
+
527
+ if isinstance(style_obj, dict):
528
+ for key, value in style_obj.items():
529
+ rules.append(f"{key}: {value};")
530
+ elif isinstance(style_obj, str):
531
+ rules.append(style_obj)
532
+
533
+ return rules
534
+
535
+ def _generate_animation(
536
+ self, anim_def: Any, selector: str
537
+ ) -> tuple:
538
+ """Generate GPU-optimized animation"""
539
+ if isinstance(anim_def, str):
540
+ parts = anim_def.split()
541
+ else:
542
+ parts = [str(anim_def)]
543
+
544
+ name = parts[0] if parts else 'anim'
545
+ duration = parts[1] if len(parts) > 1 else '1s'
546
+ timing = parts[2] if len(parts) > 2 else 'ease'
547
+
548
+ return f"{name} {duration} {timing}", []
549
+
550
+
551
+ # Test
552
+ if __name__ == '__main__':
553
+ test_ast = {
554
+ 'type': 'Document',
555
+ 'children': [
556
+ {
557
+ 'type': 'Element',
558
+ 'tag': 'div',
559
+ 'id': 'hero',
560
+ 'classes': ['main'],
561
+ 'attributes': {
562
+ 'style': {'bg': '#FF0000', 'pad': '20px'},
563
+ 'animate': 'fade 2s ease-in'
564
+ },
565
+ 'children': []
566
+ }
567
+ ]
568
+ }
569
+
570
+ gen = CSSGenerator(test_ast)
571
+ css = gen.generate()
572
+
573
+ print("Generated CSS:")
574
+ print(css)