@ape-egg/vibe 1.3.2 → 1.6.0

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.
@@ -1,63 +0,0 @@
1
- // Shared utility for processing component state
2
-
3
- /**
4
- * Generate unique component ID
5
- */
6
- export const generateComponentId = () => {
7
- return `_c${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
8
- };
9
-
10
- /**
11
- * Transform variable declarations to property assignments
12
- * let count = 0; → this.count = 0;
13
- */
14
- const transformDeclarations = (code) => {
15
- return code
16
- // Transform: let varName = value;
17
- .replace(/\b(let|const|var)\s+(\w+)\s*=\s*([^;]+);/g, 'this.$2 = $3;')
18
- // Transform: let varName;
19
- .replace(/\b(let|const|var)\s+(\w+)\s*;/g, 'this.$2 = undefined;');
20
- };
21
-
22
- /**
23
- * Execute component script and return state object
24
- * @param {string} scriptContent - JavaScript code to execute
25
- * @returns {object} - Component state object
26
- */
27
- export const executeComponentScript = (scriptContent) => {
28
- const componentState = {};
29
-
30
- if (!scriptContent || !scriptContent.trim()) {
31
- return componentState;
32
- }
33
-
34
- try {
35
- // Transform declarations to property assignments
36
- const transformed = transformDeclarations(scriptContent);
37
-
38
- // Execute script with 'this' = componentState
39
- const fn = new Function(transformed);
40
- fn.call(componentState);
41
-
42
- } catch (error) {
43
- console.error('[vibe] Error executing component script:', error);
44
- console.error('[vibe] Script content:', scriptContent);
45
- }
46
-
47
- return componentState;
48
- };
49
-
50
- /**
51
- * Register component state in global store
52
- * @param {string} componentId - Unique component identifier
53
- * @param {object} state - Component state object
54
- * @param {object} globalState - Global $ object
55
- */
56
- export const registerComponentState = (componentId, state, globalState) => {
57
- if (!globalState[componentId]) {
58
- globalState[componentId] = state;
59
- } else {
60
- // Component already registered, merge new state
61
- Object.assign(globalState[componentId], state);
62
- }
63
- };