chocola 1.3.1 → 1.3.3
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/chocola-1.3.2.tgz +0 -0
- package/compiler/component-processor.js +25 -2
- package/compiler/dom-processor.js +2 -4
- package/compiler/pipeline.js +0 -10
- package/compiler/utils.js +0 -4
- package/package.json +41 -41
|
Binary file
|
|
@@ -23,14 +23,31 @@ export function processComponentElement(
|
|
|
23
23
|
const tagName = element.tagName.toLowerCase();
|
|
24
24
|
const compName = tagName + ".js";
|
|
25
25
|
const ctx = extractContextFromElement(element);
|
|
26
|
+
const srcInnerHtml = element.innerHTML;
|
|
26
27
|
|
|
27
28
|
const instance = loadedComponents.get(compName);
|
|
28
29
|
if (!instance || instance === undefined) return false;
|
|
29
30
|
|
|
30
31
|
if (instance && instance.body) {
|
|
31
32
|
let body = instance.body;
|
|
32
|
-
body = body.replace(
|
|
33
|
+
body = body.replace(
|
|
34
|
+
/(?<!\b(?:if|del-if)=)\{ctx\.(\w+)\}/g,
|
|
35
|
+
(_, key) => ctx[key] || ""
|
|
36
|
+
);
|
|
33
37
|
const fragment = JSDOM.fragment(body);
|
|
38
|
+
const children = Array.from(fragment.querySelectorAll("*"));
|
|
39
|
+
children.forEach(child => {
|
|
40
|
+
if (child.hasAttribute("if")) {
|
|
41
|
+
const expr = child.getAttribute("if").slice(1, -1);
|
|
42
|
+
const fn = new Function("ctx", `if (${expr} === true) {return true} else {return ${expr} === '{true}'}`);
|
|
43
|
+
if (!fn(ctx)) child.style.display = "none";
|
|
44
|
+
}
|
|
45
|
+
if (child.hasAttribute("del-if")) {
|
|
46
|
+
const expr = child.getAttribute("del-if").slice(1, -1);
|
|
47
|
+
const fn = new Function("ctx", `if (${expr} === true) {return true} else {return ${expr} === '{true}'}`);
|
|
48
|
+
if (!fn(ctx)) child.remove();
|
|
49
|
+
}
|
|
50
|
+
});
|
|
34
51
|
const firstChild = fragment.firstChild;
|
|
35
52
|
|
|
36
53
|
if (firstChild && firstChild.nodeType === 1) {
|
|
@@ -57,7 +74,6 @@ export function processComponentElement(
|
|
|
57
74
|
script = script.replace(ctxRegex, "ctx");
|
|
58
75
|
script = script.replace(/RUNTIME\([^)]*\)\s*{/, match => match + "\n" + ctxDef);
|
|
59
76
|
|
|
60
|
-
// Determine or create a single runtime function per component
|
|
61
77
|
let letterEntry = runtimeMap && runtimeMap.get(compName);
|
|
62
78
|
let letter;
|
|
63
79
|
if (!letterEntry) {
|
|
@@ -72,7 +88,14 @@ export function processComponentElement(
|
|
|
72
88
|
runtimeChunks.push(`${letter}RUNTIME(document.querySelector('[chid="${compId}"]'), ${JSON.stringify(ctx)});`);
|
|
73
89
|
}
|
|
74
90
|
}
|
|
91
|
+
|
|
92
|
+
const slotFragment = JSDOM.fragment(srcInnerHtml);
|
|
93
|
+
Array.from(fragment.querySelectorAll("slot")).forEach(slot => {
|
|
94
|
+
slot.replaceWith(slotFragment);
|
|
95
|
+
});
|
|
96
|
+
|
|
75
97
|
element.replaceWith(fragment);
|
|
98
|
+
|
|
76
99
|
return true;
|
|
77
100
|
}
|
|
78
101
|
|
|
@@ -43,10 +43,8 @@ export function getAppElements(appContainer) {
|
|
|
43
43
|
export function extractContextFromElement(element) {
|
|
44
44
|
const ctx = {};
|
|
45
45
|
for (const attr of element.attributes) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
ctx[key] = attr.value;
|
|
49
|
-
}
|
|
46
|
+
const key = attr.name;
|
|
47
|
+
ctx[key] = attr.value;
|
|
50
48
|
}
|
|
51
49
|
return ctx;
|
|
52
50
|
}
|
package/compiler/pipeline.js
CHANGED
|
@@ -4,8 +4,6 @@ import { readMyFile, checkFile } from "./fs.js";
|
|
|
4
4
|
import { JSDOM } from "jsdom";
|
|
5
5
|
import path from "path";
|
|
6
6
|
|
|
7
|
-
// ===== Component Loading =====
|
|
8
|
-
|
|
9
7
|
/**
|
|
10
8
|
* Discovers and loads all components from a library directory.
|
|
11
9
|
* Components are JavaScript files that start with an uppercase letter.
|
|
@@ -31,7 +29,6 @@ export async function getComponents(libDir) {
|
|
|
31
29
|
}
|
|
32
30
|
|
|
33
31
|
for (const comp of components) {
|
|
34
|
-
// Only load .js files that start with uppercase (component convention)
|
|
35
32
|
if (!comp.endsWith(".js") || comp[0] !== comp[0].toUpperCase()) continue;
|
|
36
33
|
|
|
37
34
|
componentsLib.push(comp);
|
|
@@ -45,7 +42,6 @@ export async function getComponents(libDir) {
|
|
|
45
42
|
|
|
46
43
|
const instance = module.default();
|
|
47
44
|
|
|
48
|
-
// Load external body template if specified
|
|
49
45
|
if (instance.bodyPath) {
|
|
50
46
|
instance.body = await fs.readFile(
|
|
51
47
|
path.resolve(libDir, instance.bodyPath),
|
|
@@ -62,8 +58,6 @@ export async function getComponents(libDir) {
|
|
|
62
58
|
}
|
|
63
59
|
}
|
|
64
60
|
|
|
65
|
-
// ===== Index File Loading =====
|
|
66
|
-
|
|
67
61
|
/**
|
|
68
62
|
* Loads the project index file (HTML or .choco)
|
|
69
63
|
* If both HTML and .choco files exist, throws an error
|
|
@@ -104,8 +98,6 @@ export async function getSrcIndex(srcPath) {
|
|
|
104
98
|
}
|
|
105
99
|
}
|
|
106
100
|
|
|
107
|
-
// ===== Asset Processing =====
|
|
108
|
-
|
|
109
101
|
/**
|
|
110
102
|
* Processes stylesheet links: copies CSS files to output and updates link href
|
|
111
103
|
* @param {HTMLLinkElement} link - The link element to process
|
|
@@ -162,12 +154,10 @@ export async function copyResources(rootDir, srcDir, outDirPath) {
|
|
|
162
154
|
const newElements = Array.from(newDoc.window.document.querySelectorAll("*"));
|
|
163
155
|
|
|
164
156
|
for (const el of newElements) {
|
|
165
|
-
// Skip LINK and SCRIPT tags as they're already processed
|
|
166
157
|
if (el.tagName === "LINK" || el.tagName === "SCRIPT") continue;
|
|
167
158
|
|
|
168
159
|
const src = el.getAttribute("src") || el.getAttribute("href");
|
|
169
160
|
|
|
170
|
-
// Only copy local resources, not external web links
|
|
171
161
|
if (src && !isWebLink(src)) {
|
|
172
162
|
const srcPath = path.join(rootDir, srcDir, src);
|
|
173
163
|
const destPath = path.join(outDirPath, src);
|
package/compiler/utils.js
CHANGED
|
@@ -26,7 +26,6 @@ export function throwError(err) {
|
|
|
26
26
|
export async function loadWithAssets(filePath) {
|
|
27
27
|
let code = await fs.readFile(filePath, "utf8");
|
|
28
28
|
|
|
29
|
-
// Find all `import varName from "*.html"` or `import varName from "*.css"`
|
|
30
29
|
const importRegex = /import\s+(\w+)\s+from\s+["'](.+?\.(html|css))["'];?/g;
|
|
31
30
|
|
|
32
31
|
let match;
|
|
@@ -34,16 +33,13 @@ export async function loadWithAssets(filePath) {
|
|
|
34
33
|
const varName = match[1];
|
|
35
34
|
const relPath = match[2];
|
|
36
35
|
|
|
37
|
-
// Resolve relative path and read the asset file
|
|
38
36
|
const absPath = path.resolve(path.dirname(filePath), relPath);
|
|
39
37
|
let content = await fs.readFile(absPath, "utf8");
|
|
40
38
|
|
|
41
|
-
// Replace the import with a const assignment of the file contents
|
|
42
39
|
const replacement = `const ${varName} = ${JSON.stringify(content)};`;
|
|
43
40
|
code = code.replace(match[0], replacement);
|
|
44
41
|
}
|
|
45
42
|
|
|
46
|
-
// Convert to data URL and import dynamically to avoid filesystem restrictions
|
|
47
43
|
const dataUrl =
|
|
48
44
|
"data:text/javascript;base64," +
|
|
49
45
|
Buffer.from(code).toString("base64");
|
package/package.json
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "chocola",
|
|
3
|
-
"version": "1.3.
|
|
4
|
-
"description": "The sweetest way to build reactive web apps",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"web",
|
|
7
|
-
"app",
|
|
8
|
-
"pipeline",
|
|
9
|
-
"framework",
|
|
10
|
-
"gui",
|
|
11
|
-
"components",
|
|
12
|
-
"ui"
|
|
13
|
-
],
|
|
14
|
-
"homepage": "https://github.com/sad-gabi/chocola#readme",
|
|
15
|
-
"bugs": {
|
|
16
|
-
"url": "https://github.com/sad-gabi/chocola/issues"
|
|
17
|
-
},
|
|
18
|
-
"repository": {
|
|
19
|
-
"type": "git",
|
|
20
|
-
"url": "git+https://github.com/sad-gabi/chocola.git"
|
|
21
|
-
},
|
|
22
|
-
"license": "MIT",
|
|
23
|
-
"author": "SadGabi",
|
|
24
|
-
"type": "module",
|
|
25
|
-
"main": "index.js",
|
|
26
|
-
"scripts": {
|
|
27
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
28
|
-
},
|
|
29
|
-
"exports": {
|
|
30
|
-
".": "./index.js",
|
|
31
|
-
"./types": "./types/index.js"
|
|
32
|
-
},
|
|
33
|
-
"dependencies": {
|
|
34
|
-
"chalk": "^5.6.2",
|
|
35
|
-
"js-beautify": "^1.15.4",
|
|
36
|
-
"jsdom": "^27.4.0"
|
|
37
|
-
},
|
|
38
|
-
"devDependencies": {
|
|
39
|
-
"js-beautify": "^1.15.4"
|
|
40
|
-
}
|
|
41
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "chocola",
|
|
3
|
+
"version": "1.3.3",
|
|
4
|
+
"description": "The sweetest way to build reactive web apps",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"web",
|
|
7
|
+
"app",
|
|
8
|
+
"pipeline",
|
|
9
|
+
"framework",
|
|
10
|
+
"gui",
|
|
11
|
+
"components",
|
|
12
|
+
"ui"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/sad-gabi/chocola#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/sad-gabi/chocola/issues"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/sad-gabi/chocola.git"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"author": "SadGabi",
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "index.js",
|
|
26
|
+
"scripts": {
|
|
27
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
28
|
+
},
|
|
29
|
+
"exports": {
|
|
30
|
+
".": "./index.js",
|
|
31
|
+
"./types": "./types/index.js"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"chalk": "^5.6.2",
|
|
35
|
+
"js-beautify": "^1.15.4",
|
|
36
|
+
"jsdom": "^27.4.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"js-beautify": "^1.15.4"
|
|
40
|
+
}
|
|
41
|
+
}
|