@stacksjs/stx 0.0.10 → 0.1.7

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 (50) hide show
  1. package/README.md +69 -21
  2. package/dist/a11y.d.ts +40 -0
  3. package/dist/analyzer.d.ts +64 -0
  4. package/dist/animation.d.ts +64 -0
  5. package/dist/assets.d.ts +19 -0
  6. package/dist/auth.d.ts +11 -0
  7. package/dist/bin/cli.js +2821 -154
  8. package/dist/caching.d.ts +18 -6
  9. package/dist/chunk-2ndtnc0t.js +9822 -0
  10. package/dist/{chunk-ywm063e4.js → chunk-e11q5a3p.js} +2 -2
  11. package/dist/chunk-vsbm352h.js +670 -0
  12. package/dist/client.d.ts +19 -35
  13. package/dist/components.d.ts +6 -0
  14. package/dist/conditionals.d.ts +17 -1
  15. package/dist/config.d.ts +6 -2
  16. package/dist/csrf.d.ts +28 -0
  17. package/dist/custom-directives.d.ts +5 -6
  18. package/dist/dev-server.d.ts +21 -0
  19. package/dist/docs.d.ts +39 -3
  20. package/dist/error-handling.d.ts +101 -0
  21. package/dist/expressions.d.ts +43 -4
  22. package/dist/formatter.d.ts +16 -0
  23. package/dist/forms.d.ts +15 -25
  24. package/dist/i18n.d.ts +17 -20
  25. package/dist/includes.d.ts +21 -18
  26. package/dist/index.d.ts +30 -24
  27. package/dist/init.d.ts +9 -0
  28. package/dist/js-ts.d.ts +10 -0
  29. package/dist/loops.d.ts +4 -3
  30. package/dist/markdown.d.ts +8 -0
  31. package/dist/method-spoofing.d.ts +13 -0
  32. package/dist/middleware.d.ts +9 -1
  33. package/dist/performance-utils.d.ts +58 -0
  34. package/dist/plugin.d.ts +2 -0
  35. package/dist/process.d.ts +9 -7
  36. package/dist/release.d.ts +1 -0
  37. package/dist/routes.d.ts +36 -0
  38. package/dist/safe-evaluator.d.ts +16 -0
  39. package/dist/seo.d.ts +33 -0
  40. package/dist/serve.d.ts +35 -0
  41. package/dist/src/index.js +2893 -135
  42. package/dist/streaming.d.ts +30 -14
  43. package/dist/types.d.ts +214 -48
  44. package/dist/utils.d.ts +21 -3
  45. package/dist/view-composers.d.ts +26 -0
  46. package/dist/web-components.d.ts +7 -14
  47. package/package.json +18 -9
  48. package/dist/chunk-04bqmpzb.js +0 -7069
  49. package/dist/chunk-8ehp5m3y.js +0 -4279
  50. package/dist/chunk-9ynf73q9.js +0 -2502
package/README.md CHANGED
@@ -112,9 +112,9 @@ export default {
112
112
  }
113
113
  ```
114
114
 
115
- ## STX Template Syntax
115
+ ## stx Template Syntax
116
116
 
117
- STX templates use a syntax inspired by Laravel Blade. Templates can contain HTML with special directives for rendering dynamic content.
117
+ stx templates use a syntax inspired by Laravel Blade. Templates can contain HTML with special directives for rendering dynamic content.
118
118
 
119
119
  ### Basic Example
120
120
 
@@ -122,7 +122,7 @@ STX templates use a syntax inspired by Laravel Blade. Templates can contain HTML
122
122
  <!DOCTYPE html>
123
123
  <html>
124
124
  <head>
125
- <title>STX Example</title>
125
+ <title>stx Example</title>
126
126
  <script>
127
127
  // Define your data as an ESM export
128
128
  export const title = "Hello World";
@@ -148,7 +148,7 @@ STX templates use a syntax inspired by Laravel Blade. Templates can contain HTML
148
148
 
149
149
  ### Data Export Options
150
150
 
151
- There are two ways to expose data in your STX templates:
151
+ There are two ways to expose data in your stx templates:
152
152
 
153
153
  #### 1. ESM exports (recommended)
154
154
 
@@ -188,7 +188,7 @@ There are two ways to expose data in your STX templates:
188
188
 
189
189
  #### Custom Directives
190
190
 
191
- STX supports defining your own custom directives for template processing:
191
+ stx supports defining your own custom directives for template processing:
192
192
 
193
193
  ```ts
194
194
  import type { CustomDirective } from 'bun-plugin-stx'
@@ -298,7 +298,7 @@ Output unescaped HTML content:
298
298
 
299
299
  #### Markdown Support
300
300
 
301
- STX supports rendering Markdown content directly in your templates using the `@markdown` directive:
301
+ stx supports rendering Markdown content directly in your templates using the `@markdown` directive:
302
302
 
303
303
  ```html
304
304
  <div class="content">
@@ -339,7 +339,7 @@ Content here
339
339
 
340
340
  ### Internationalization (i18n)
341
341
 
342
- STX supports internationalization to help you build multilingual applications. Translation files are stored in YAML format (JSON also supported) and support nested keys and parameter replacements.
342
+ stx supports internationalization to help you build multilingual applications. Translation files are stored in YAML format (JSON also supported) and support nested keys and parameter replacements.
343
343
 
344
344
  #### Configuration
345
345
 
@@ -371,7 +371,7 @@ Create translation files in your translationsDir:
371
371
 
372
372
  ```yaml
373
373
  # translations/en.yaml
374
- welcome: Welcome to STX
374
+ welcome: Welcome to stx
375
375
  greeting: Hello, :name!
376
376
  nav:
377
377
  home: Home
@@ -381,7 +381,7 @@ nav:
381
381
 
382
382
  ```yaml
383
383
  # translations/de.yaml
384
- welcome: Willkommen bei STX
384
+ welcome: Willkommen bei stx
385
385
  greeting: Hallo, :name!
386
386
  nav:
387
387
  home: Startseite
@@ -391,7 +391,7 @@ nav:
391
391
 
392
392
  #### Using Translations
393
393
 
394
- STX provides multiple ways to use translations in your templates:
394
+ stx provides multiple ways to use translations in your templates:
395
395
 
396
396
  1. **@translate Directive**
397
397
 
@@ -438,7 +438,7 @@ Then in your template:
438
438
 
439
439
  ### Web Components Integration
440
440
 
441
- STX now provides seamless integration with Web Components, allowing you to automatically build and use custom elements from your STX components.
441
+ stx now provides seamless integration with Web Components, allowing you to automatically build and use custom elements from your stx components.
442
442
 
443
443
  #### Configuration
444
444
 
@@ -461,7 +461,7 @@ await build({
461
461
  {
462
462
  name: 'MyButton', // Class name for the component
463
463
  tag: 'my-button', // HTML tag name (must contain a hyphen)
464
- file: 'components/button.stx', // Path to the STX component
464
+ file: 'components/button.stx', // Path to the stx component
465
465
  attributes: ['type', 'text', 'disabled'] // Observed attributes
466
466
  },
467
467
  {
@@ -507,9 +507,9 @@ Include web components in your templates with the `@webcomponent` directive:
507
507
  </html>
508
508
  ```
509
509
 
510
- #### Source STX Components
510
+ #### Source stx Components
511
511
 
512
- The original STX components can be simple:
512
+ The original stx components can be simple:
513
513
 
514
514
  ```html
515
515
  <!-- components/button.stx -->
@@ -539,9 +539,9 @@ Web components support several configuration options:
539
539
 
540
540
  ## TypeScript Support
541
541
 
542
- STX includes TypeScript declarations for importing .stx files. Make sure your `tsconfig.json` includes the necessary configuration:
542
+ stx includes TypeScript declarations for importing .stx files. Make sure your `tsconfig.json` includes the necessary configuration:
543
543
 
544
- ```json
544
+ ```jsonc
545
545
  {
546
546
  "compilerOptions": {
547
547
  // ... your other options
@@ -561,7 +561,7 @@ declare module '*.stx';
561
561
 
562
562
  ## Example Server
563
563
 
564
- Run a development server with your STX templates:
564
+ Run a development server with your stx templates:
565
565
 
566
566
  ```ts
567
567
  // serve.ts
@@ -615,6 +615,54 @@ The plugin works by:
615
615
  bun test
616
616
  ```
617
617
 
618
+ ## CSS Generation with Headwind
619
+
620
+ stx uses [Headwind](https://headwind.stacksjs.org) for utility-first CSS generation. Headwind is a blazingly fast CSS framework built with Bun that generates only the CSS you need.
621
+
622
+ ### Building CSS
623
+
624
+ ```bash
625
+ # Build CSS from your .stx templates
626
+ bun run build:css
627
+
628
+ # The CSS will be generated at ./examples/dist/styles.css
629
+ ```
630
+
631
+ ### Headwind Configuration
632
+
633
+ Headwind is configured via `headwind.config.ts`:
634
+
635
+ ```typescript
636
+ import type { HeadwindConfig } from 'headwind'
637
+ import path from 'node:path'
638
+
639
+ const config: Partial<HeadwindConfig> = {
640
+ content: [
641
+ './examples/**/*.stx',
642
+ './examples/**/*.{html,js,ts,jsx,tsx}',
643
+ ],
644
+ output: './examples/dist/styles.css',
645
+ minify: false,
646
+ }
647
+
648
+ export default config
649
+ ```
650
+
651
+ ### Using Utility Classes
652
+
653
+ stx templates support all Headwind/Tailwind-compatible utility classes:
654
+
655
+ ```html
656
+ <div class="flex items-center justify-between p-4 bg-white rounded-lg shadow-md hover:shadow-lg">
657
+ <h1 class="text-2xl font-bold text-gray-900">Hello World</h1>
658
+ <button class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600 transition">
659
+ Click Me
660
+ </button>
661
+ </div>
662
+ ```
663
+
664
+ The build process automatically scans all your `.stx` files and generates only the CSS classes you actually use. For more information, visit the [Headwind documentation](https://headwind.stacksjs.org).
665
+
618
666
  ## Changelog
619
667
 
620
668
  Please see our [releases](https://github.com/stacksjs/stx/releases) page for more information on what has changed recently.
@@ -674,7 +722,7 @@ Made with 💙
674
722
 
675
723
  ## Documentation Generation
676
724
 
677
- STX can automatically generate documentation for your components, templates, and directives. This helps developers understand your UI components and how to use them.
725
+ stx can automatically generate documentation for your components, templates, and directives. This helps developers understand your UI components and how to use them.
678
726
 
679
727
  ### Command Line
680
728
 
@@ -718,12 +766,12 @@ export default {
718
766
  directives: true,
719
767
  extraContent: '## Getting Started\n\nThis is additional content to include in the documentation.',
720
768
  },
721
- };
769
+ }
722
770
  ```
723
771
 
724
772
  ### Component Documentation
725
773
 
726
- STX can extract component metadata from JSDoc comments in your component files:
774
+ stx can extract component metadata from JSDoc comments in your component files:
727
775
 
728
776
  ```html
729
777
  <!--
@@ -769,7 +817,7 @@ This component will be documented with all its properties, types, default values
769
817
 
770
818
  ### Web Component Documentation
771
819
 
772
- STX will automatically document web components defined in your configuration:
820
+ stx will automatically document web components defined in your configuration:
773
821
 
774
822
  ```ts
775
823
  export default {
package/dist/a11y.d.ts ADDED
@@ -0,0 +1,40 @@
1
+ import type { CustomDirective, StxOptions } from './types';
2
+ /**
3
+ * Process accessibility directives
4
+ */
5
+ export declare function processA11yDirectives(template: string, context: Record<string, any>, filePath: string, options: StxOptions): string;
6
+ /**
7
+ * Create the screen reader only style
8
+ */
9
+ export declare function getScreenReaderOnlyStyle(): string;
10
+ /**
11
+ * Automatically check template for accessibility issues
12
+ */
13
+ export declare function checkA11y(html: string, filePath: string): Promise<A11yViolation[]>;
14
+ /**
15
+ * Scan a directory of stx files for accessibility issues
16
+ */
17
+ export declare function scanA11yIssues(directory: string, options?: { recursive?: boolean, ignorePaths?: string[] }): Promise<Record<string, A11yViolation[]>>;
18
+ /**
19
+ * Register all a11y directives
20
+ */
21
+ export declare function registerA11yDirectives(): CustomDirective[];
22
+ /**
23
+ * A11y directive for adding accessibility hints
24
+ */
25
+ export declare const a11yDirective: CustomDirective;
26
+ /**
27
+ * Screen reader directive for screen reader only content
28
+ */
29
+ export declare const screenReaderDirective: CustomDirective;
30
+ /**
31
+ * Accessibility violation found during a11y checks
32
+ */
33
+ export declare interface A11yViolation {
34
+ type: string
35
+ element: string
36
+ message: string
37
+ impact: 'critical' | 'serious' | 'moderate' | 'minor'
38
+ help: string
39
+ helpUrl?: string
40
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Analyze an stx template file
3
+ */
4
+ export declare function analyzeTemplate(filePath: string): Promise<AnalysisResult>;
5
+ /**
6
+ * Analyze multiple templates
7
+ */
8
+ export declare function analyzeProject(patterns?: string[], cwd?: string): Promise<{
9
+ results: AnalysisResult[]
10
+ summary: ProjectSummary
11
+ }>;
12
+ export declare interface AnalysisResult {
13
+ file: string
14
+ metrics: TemplateMetrics
15
+ issues: Issue[]
16
+ suggestions: Suggestion[]
17
+ performance: PerformanceMetrics
18
+ }
19
+ export declare interface TemplateMetrics {
20
+ lines: number
21
+ characters: number
22
+ directives: DirectiveCount
23
+ expressions: number
24
+ components: number
25
+ layouts: number
26
+ scriptLines: number
27
+ complexity: number
28
+ }
29
+ export declare interface DirectiveCount {
30
+ conditionals: number
31
+ loops: number
32
+ includes: number
33
+ custom: number
34
+ total: number
35
+ }
36
+ export declare interface Issue {
37
+ type: 'error' | 'warning' | 'info'
38
+ category: 'performance' | 'security' | 'maintainability' | 'accessibility' | 'syntax'
39
+ message: string
40
+ line?: number
41
+ column?: number
42
+ suggestion?: string
43
+ }
44
+ export declare interface Suggestion {
45
+ type: 'optimization' | 'best-practice' | 'refactor'
46
+ message: string
47
+ impact: 'low' | 'medium' | 'high'
48
+ effort: 'low' | 'medium' | 'high'
49
+ }
50
+ export declare interface PerformanceMetrics {
51
+ estimatedRenderTime: number
52
+ complexityScore: number
53
+ cacheability: 'high' | 'medium' | 'low'
54
+ recommendations: string[]
55
+ }
56
+ export declare interface ProjectSummary {
57
+ totalFiles: number
58
+ totalLines: number
59
+ avgComplexity: number
60
+ totalIssues: number
61
+ issuesByCategory: Record<string, number>
62
+ performanceScore: number
63
+ recommendations: string[]
64
+ }
@@ -0,0 +1,64 @@
1
+ import type { StxOptions } from './types';
2
+ /**
3
+ * Process animation directives in the template
4
+ */
5
+ export declare function processAnimationDirectives(template: string, context: Record<string, any>, filePath: string, options: StxOptions): string;
6
+ /**
7
+ * Register animation directives
8
+ */
9
+ export declare function registerAnimationDirectives(options: StxOptions): StxOptions;
10
+ /**
11
+ * Default transition options
12
+ */
13
+ export declare const DEFAULT_TRANSITION_OPTIONS: {
14
+ duration: number
15
+ delay: number
16
+ ease: string
17
+ direction: string
18
+ };
19
+ /**
20
+ * Transition directive for applying transitions to elements
21
+ */
22
+ export declare const transitionDirective: CustomDirective;
23
+ /**
24
+ * Scroll animation directive for triggering animations on scroll
25
+ */
26
+ export declare const scrollAnimateDirective: CustomDirective;
27
+ /**
28
+ * Animation group directive for coordinating multiple animations
29
+ */
30
+ export declare const animationGroupDirective: CustomDirective;
31
+ /**
32
+ * Motion preferences directive for controlling animation preferences
33
+ */
34
+ export declare const motionDirective: CustomDirective;
35
+ /**
36
+ * Available transition types that can be used with @transition directive
37
+ */
38
+ export declare enum TransitionType {
39
+ Fade = 'fade',
40
+ Slide = 'slide',
41
+ Scale = 'scale',
42
+ Flip = 'flip',
43
+ Rotate = 'rotate',
44
+ Custom = 'custom',
45
+ }
46
+ /**
47
+ * Available transition directions that can be used with @transition directive
48
+ */
49
+ export declare enum TransitionDirection {
50
+ In = 'in',
51
+ Out = 'out',
52
+ Both = 'both',
53
+ }
54
+ /**
55
+ * Available ease functions for transitions
56
+ */
57
+ export declare enum TransitionEase {
58
+ Linear = 'linear',
59
+ Ease = 'ease',
60
+ EaseIn = 'ease-in',
61
+ EaseOut = 'ease-out',
62
+ EaseInOut = 'ease-in-out',
63
+ Spring = 'spring',
64
+ }
@@ -0,0 +1,19 @@
1
+ import type { StxOptions } from './types';
2
+ /**
3
+ * Read and parse a markdown file with frontmatter
4
+ * @param filePath Path to the markdown file
5
+ * @param options stx options
6
+ * @returns Object containing parsed content and frontmatter data
7
+ */
8
+ export declare function readMarkdownFile(filePath: string, options?: StxOptions): Promise<{ content: string, data: Record<string, any> }>;
9
+ /**
10
+ * Process @markdown-file directive
11
+ * This directive includes markdown files in templates
12
+ */
13
+ export declare function processMarkdownFileDirectives(template: string, context: Record<string, any>, filePath?: string, options?: StxOptions): Promise<string>;
14
+ // Define a cache for markdown files to avoid repeated file reads
15
+ export declare const markdownCache: Map<string, {
16
+ content: string
17
+ data: Record<string, any>
18
+ updatedAt: number
19
+ }>;
package/dist/auth.d.ts CHANGED
@@ -1 +1,12 @@
1
+ /**
2
+ * Module for handling authentication and authorization in templates
3
+ */
4
+ /**
5
+ * Safely evaluates an auth expression within the given context
6
+ * Similar to evaluateExpression but specialized for auth conditionals
7
+ *
8
+ * @param {string} expression - The expression to evaluate
9
+ * @param {Record<string, any>} context - The context object containing variables
10
+ * @returns The evaluated result
11
+ */
1
12
  export declare function evaluateAuthExpression(expression: string, context: Record<string, any>): any;