chocola 1.0.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.
package/.gitattributes ADDED
@@ -0,0 +1,2 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Meta Platforms, Inc. and affiliates.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # Chocola.js · [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/sad-gabi/chocola/blob/main/LICENSE) [![npm version](https://img.shields.io/badge/npm-v1.0.0-blue)](https://www.npmjs.com/package/chocola)
2
+ Chocola.js is a framework for creating user interfaces.
@@ -0,0 +1,3 @@
1
+ export function renderComponents(html) {
2
+ return html;
3
+ }
package/core/parser.js ADDED
@@ -0,0 +1,39 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+
4
+ export function parseChocola(code, id) {
5
+ const htmlRegex = /html:\s*([\s\S]*)\}\)/m;
6
+ let htmlMatch = code.match(htmlRegex);
7
+ if (!htmlMatch) return code;
8
+
9
+ let htmlContent = htmlMatch[1];
10
+
11
+ // REPLACE COMPONENTS <Component ...>...</Component>
12
+ htmlContent = htmlContent.replace(
13
+ /<([A-Z][a-zA-Z0-9]*)\s*([^>]*)>([\s\S]*?)<\/\1>/g,
14
+ (_, name, props, children) => {
15
+ const propsObj = parseProps(props);
16
+ if (children.trim()) propsObj.children = children.trim();
17
+ return `\${${name}(${JSON.stringify(propsObj)})}`;
18
+ }
19
+ );
20
+
21
+ // REPLACE SELF-CLOSING COMPONENTS <Component ... />
22
+ htmlContent = htmlContent.replace(
23
+ /<([A-Z][a-zA-Z0-9]*)\s*([^>]*)\/>/g,
24
+ (_, name, props) => {
25
+ const propsObj = parseProps(props);
26
+ return `\${${name}(${JSON.stringify(propsObj)})}`;
27
+ }
28
+ );
29
+
30
+ // CONVERT HTML INTO STRING TEMPLATE
31
+ const newCode = code.replace(htmlRegex, `html: \`${htmlContent}\` })`);
32
+ return newCode;
33
+ }
34
+
35
+ function parseProps(str) {
36
+ const props = {};
37
+ str.replace(/(\w+)="([^"]*)"/g, (_, key, value) => props[key] = value);
38
+ return props;
39
+ }
@@ -0,0 +1,10 @@
1
+ import { renderComponents } from './componentLoader.js';
2
+
3
+ export async function renderView(viewModule) {
4
+ const view = (await viewModule()).default();
5
+ document.title = view.title;
6
+ let html = view.html;
7
+ html = renderComponents(html);
8
+ document.querySelector('#app').innerHTML = html;
9
+ for (const script of view.scripts || []) await script();
10
+ }
package/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { chocolaPlugin } from './vite-plugin-chocola.js';
2
+ export { renderView } from './core/renderer.js';
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "chocola",
3
+ "version": "1.0.0",
4
+ "description": "A framework for creating user interfaces.",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [
10
+ "vite",
11
+ "web",
12
+ "framework",
13
+ "ui",
14
+ "interface",
15
+ "components"
16
+ ],
17
+ "author": "SadGabi <sadgabi20@gmail.com>",
18
+ "license": "GPL-3.0-or-later",
19
+ "dependencies": {
20
+ "vite": "7.1.1"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/sad-gabi/chocola"
25
+ }
26
+ }
@@ -0,0 +1,14 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { parseChocola } from './core/parser.js';
4
+
5
+ export function chocolaPlugin() {
6
+ return {
7
+ name: 'vite-plugin-chocola',
8
+ enforce: 'pre',
9
+ transform(code, id) {
10
+ if (!id.endsWith('.chcl')) return;
11
+ return parseChocola(code, id);
12
+ }
13
+ };
14
+ }