vuetty 0.1.0 → 0.1.2
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 +25 -54
- package/dist/build/compiler-core.js +117 -0
- package/dist/index.js +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -16,76 +16,47 @@ For detailed documentation, component references, and advanced usage, visit the
|
|
|
16
16
|
- **Advanced Input Management**: Built-in keyboard and mouse input handling with focus management and interactive form components.
|
|
17
17
|
- **Optimized Performance**: Efficient rendering with smart caching for text, images, and markdown content.
|
|
18
18
|
|
|
19
|
-
##
|
|
19
|
+
## Demo
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
bun add vuetty vue
|
|
23
|
-
```
|
|
21
|
+

|
|
24
22
|
|
|
25
23
|
## Quick Start
|
|
26
24
|
|
|
27
|
-
|
|
25
|
+
Use the repository's `simple-app-example` to get a working app with routing and layout in place.
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
<!-- Hello.vue -->
|
|
31
|
-
<template>
|
|
32
|
-
<Box :padding="1" color="cyan">
|
|
33
|
-
<TextBox bold>Hello, World!</TextBox>
|
|
34
|
-
</Box>
|
|
35
|
-
</template>
|
|
27
|
+
1) Clone and copy the example
|
|
36
28
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
```bash
|
|
30
|
+
git clone https://github.com/tterrasson/vuetty
|
|
31
|
+
cd vuetty
|
|
32
|
+
cp -a simple-app-example my-vuetty-app
|
|
33
|
+
cd my-vuetty-app
|
|
40
34
|
```
|
|
41
35
|
|
|
42
|
-
|
|
36
|
+
2) Install dependencies
|
|
43
37
|
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
import { vuetty } from 'vuetty';
|
|
48
|
-
import Hello from './Hello.vue';
|
|
38
|
+
```bash
|
|
39
|
+
bun install
|
|
40
|
+
```
|
|
49
41
|
|
|
50
|
-
|
|
42
|
+
3) Run the example
|
|
51
43
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
process.exit(0);
|
|
55
|
-
});
|
|
44
|
+
```bash
|
|
45
|
+
bun run dev
|
|
56
46
|
```
|
|
57
47
|
|
|
48
|
+
Press `Ctrl+C` to stop it.
|
|
49
|
+
|
|
50
|
+
## Running examples
|
|
51
|
+
|
|
52
|
+
From the repo root, list and run component examples:
|
|
53
|
+
|
|
58
54
|
```bash
|
|
59
|
-
bun
|
|
55
|
+
bun run dev --list
|
|
56
|
+
bun run dev box
|
|
60
57
|
```
|
|
61
58
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
```vue
|
|
65
|
-
<template>
|
|
66
|
-
<Col>
|
|
67
|
-
<Box :padding="1" color="cyan">
|
|
68
|
-
<TextBox bold>Counter: {{ count }}</TextBox>
|
|
69
|
-
</Box>
|
|
70
|
-
<Box :padding="1" :color="countColor">
|
|
71
|
-
<TextBox>{{ message }}</TextBox>
|
|
72
|
-
</Box>
|
|
73
|
-
</Col>
|
|
74
|
-
</template>
|
|
75
|
-
|
|
76
|
-
<script setup>
|
|
77
|
-
import { ref, computed, onMounted } from 'vue';
|
|
78
|
-
import { Box, TextBox, Col } from 'vuetty';
|
|
79
|
-
|
|
80
|
-
const count = ref(0);
|
|
81
|
-
const countColor = computed(() => count.value > 10 ? 'red' : 'green');
|
|
82
|
-
const message = computed(() => count.value < 5 ? 'Just started...' : 'Getting high!');
|
|
83
|
-
|
|
84
|
-
onMounted(() => {
|
|
85
|
-
setInterval(() => count.value++, 1000);
|
|
86
|
-
});
|
|
87
|
-
</script>
|
|
88
|
-
```
|
|
59
|
+
The available IDs are defined in `examples/examples.js`.
|
|
89
60
|
|
|
90
61
|
## Use Cases
|
|
91
62
|
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// src/build/compiler-core.js
|
|
2
|
+
/**
|
|
3
|
+
* Runtime-agnostic Vue SFC compilation core
|
|
4
|
+
* Extracted from vue-sfc-plugin.js to be shared across all runtime adapters
|
|
5
|
+
*/
|
|
6
|
+
import { parse, compileScript } from '@vue/compiler-sfc';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Compile a Vue Single File Component to JavaScript
|
|
10
|
+
* @param {string} source - The .vue file source code
|
|
11
|
+
* @param {string} filepath - The file path (used for error reporting and ID)
|
|
12
|
+
* @param {object} options - Compilation options
|
|
13
|
+
* @returns {{ code: string, errors: Array, map?: object }} Compilation result
|
|
14
|
+
*/
|
|
15
|
+
export function compileSFC(source, filepath, options = {}) {
|
|
16
|
+
try {
|
|
17
|
+
// Step 1: Parse SFC into descriptor (template, script, style blocks)
|
|
18
|
+
const { descriptor, errors: parseErrors } = parse(source, {
|
|
19
|
+
filename: filepath,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
if (parseErrors.length) {
|
|
23
|
+
return {
|
|
24
|
+
code: '',
|
|
25
|
+
errors: parseErrors.map(e => ({
|
|
26
|
+
message: `SFC Parse Error: ${e.message}`,
|
|
27
|
+
location: e.loc ? {
|
|
28
|
+
file: filepath,
|
|
29
|
+
line: e.loc.start.line,
|
|
30
|
+
column: e.loc.start.column,
|
|
31
|
+
} : undefined,
|
|
32
|
+
})),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Step 2: Compile script block with inline template
|
|
37
|
+
// For <script setup>, using inlineTemplate: true automatically handles:
|
|
38
|
+
// - Template compilation
|
|
39
|
+
// - Component resolution (imported components are available)
|
|
40
|
+
// - Reactive state exposure to template
|
|
41
|
+
let scriptCode = '';
|
|
42
|
+
|
|
43
|
+
if (descriptor.script || descriptor.scriptSetup) {
|
|
44
|
+
try {
|
|
45
|
+
const compiled = compileScript(descriptor, {
|
|
46
|
+
id: filepath,
|
|
47
|
+
// IMPORTANT: Inline template compilation with script
|
|
48
|
+
// This ensures imported components and setup vars are accessible
|
|
49
|
+
inlineTemplate: true,
|
|
50
|
+
templateOptions: {
|
|
51
|
+
compilerOptions: {
|
|
52
|
+
// Removed isCustomElement - let Vue always resolve as components
|
|
53
|
+
// This ensures component setup() always runs and inputManager injection works
|
|
54
|
+
whitespace: 'preserve',
|
|
55
|
+
comments: false,
|
|
56
|
+
hoistStatic: true,
|
|
57
|
+
...options.compilerOptions,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
scriptCode = compiled.content;
|
|
63
|
+
|
|
64
|
+
// Return compiled code
|
|
65
|
+
return {
|
|
66
|
+
code: scriptCode,
|
|
67
|
+
errors: [],
|
|
68
|
+
map: compiled.map,
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
} catch (error) {
|
|
72
|
+
return {
|
|
73
|
+
code: '',
|
|
74
|
+
errors: [{
|
|
75
|
+
message: `Script/Template Compilation Error: ${error.message}`,
|
|
76
|
+
location: error.loc ? {
|
|
77
|
+
file: filepath,
|
|
78
|
+
line: error.loc.start.line,
|
|
79
|
+
column: error.loc.start.column,
|
|
80
|
+
} : undefined,
|
|
81
|
+
}],
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// If no script block, return empty
|
|
87
|
+
return {
|
|
88
|
+
code: '',
|
|
89
|
+
errors: [{
|
|
90
|
+
message: 'SFC has no script or scriptSetup block',
|
|
91
|
+
location: { file: filepath },
|
|
92
|
+
}],
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
} catch (error) {
|
|
96
|
+
return {
|
|
97
|
+
code: '',
|
|
98
|
+
errors: [{
|
|
99
|
+
message: `Unexpected SFC Compilation Error: ${error.message}`,
|
|
100
|
+
location: { file: filepath },
|
|
101
|
+
}],
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Format compilation errors for display
|
|
108
|
+
* @param {Array} errors - Array of error objects
|
|
109
|
+
* @param {string} filepath - The file path
|
|
110
|
+
* @returns {Array} Formatted errors
|
|
111
|
+
*/
|
|
112
|
+
export function formatErrors(errors, filepath) {
|
|
113
|
+
return errors.map(e => ({
|
|
114
|
+
text: e.message || 'Unknown error',
|
|
115
|
+
location: e.location || { file: filepath },
|
|
116
|
+
}));
|
|
117
|
+
}
|