@meekojs/meeko 0.0.0-stage → 0.0.1
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/LICENSE +21 -0
- package/README.md +101 -2
- package/dist/check.d.ts +3 -0
- package/dist/check.js +130 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +43 -0
- package/dist/compiler/mapping.d.ts +16 -0
- package/dist/compiler/mapping.js +48 -0
- package/dist/compiler/sfc.d.ts +43 -0
- package/dist/compiler/sfc.js +70 -0
- package/dist/compiler/template.d.ts +31 -0
- package/dist/compiler/template.js +44 -0
- package/dist/compiler.d.ts +13 -0
- package/dist/compiler.js +404 -0
- package/dist/dom.d.ts +43 -0
- package/dist/dom.js +315 -0
- package/dist/hmr.d.ts +24 -0
- package/dist/hmr.js +137 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +4 -0
- package/dist/reactivity.d.ts +22 -0
- package/dist/reactivity.js +151 -0
- package/dist/server.d.ts +8 -0
- package/dist/server.js +79 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.js +38 -0
- package/dist/vite.d.ts +3 -0
- package/dist/vite.js +47 -0
- package/package.json +69 -4
package/dist/server.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/** Escapa texto dinámico antes de insertarlo en HTML generado por SSR. */
|
|
2
|
+
export function escapeHtml(value) {
|
|
3
|
+
return String(value)
|
|
4
|
+
.replaceAll("&", "&")
|
|
5
|
+
.replaceAll("<", "<")
|
|
6
|
+
.replaceAll(">", ">")
|
|
7
|
+
.replaceAll('"', """)
|
|
8
|
+
.replaceAll("'", "'");
|
|
9
|
+
}
|
|
10
|
+
const booleanAttributes = new Set(["allowfullscreen", "async", "autofocus", "autoplay", "checked", "controls", "default", "defer", "disabled", "formnovalidate", "hidden", "inert", "ismap", "loop", "multiple", "muted", "nomodule", "novalidate", "open", "playsinline", "readonly", "required", "reversed", "selected"]);
|
|
11
|
+
/** Convierte un valor de atributo dinámico en su forma DOM; null lo elimina. */
|
|
12
|
+
export function attributeValue(name, value) {
|
|
13
|
+
if (booleanAttributes.has(name))
|
|
14
|
+
return value ? "" : null;
|
|
15
|
+
if (value === null || value === undefined || value === false)
|
|
16
|
+
return null;
|
|
17
|
+
return String(value);
|
|
18
|
+
}
|
|
19
|
+
/** Genera un atributo HTML dinámico con escape seguro para SSR. */
|
|
20
|
+
export function renderAttribute(name, value) {
|
|
21
|
+
if (!/^[a-zA-Z_:][a-zA-Z0-9_:.-]*$/.test(name))
|
|
22
|
+
throw new TypeError(`Invalid attribute name: ${name}`);
|
|
23
|
+
const resolved = attributeValue(name, value);
|
|
24
|
+
return resolved === null ? "" : ` ${name}="${escapeHtml(resolved)}"`;
|
|
25
|
+
}
|
|
26
|
+
function assertSerializable(value, path, ancestors) {
|
|
27
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
28
|
+
return;
|
|
29
|
+
if (typeof value === "number") {
|
|
30
|
+
if (Number.isFinite(value))
|
|
31
|
+
return;
|
|
32
|
+
throw new TypeError(`Non-finite number at ${path}`);
|
|
33
|
+
}
|
|
34
|
+
if (typeof value !== "object")
|
|
35
|
+
throw new TypeError(`Non-serializable value at ${path}`);
|
|
36
|
+
if (ancestors.has(value))
|
|
37
|
+
throw new TypeError(`Circular reference at ${path}`);
|
|
38
|
+
const prototype = Object.getPrototypeOf(value);
|
|
39
|
+
if (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null) {
|
|
40
|
+
throw new TypeError(`Non-plain object at ${path}`);
|
|
41
|
+
}
|
|
42
|
+
if (Object.hasOwn(value, "toJSON"))
|
|
43
|
+
throw new TypeError(`Custom toJSON at ${path}`);
|
|
44
|
+
if (Array.isArray(value)) {
|
|
45
|
+
for (let index = 0; index < value.length; index++) {
|
|
46
|
+
if (!Object.hasOwn(value, index))
|
|
47
|
+
throw new TypeError(`Sparse array at ${path}[${index}]`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
ancestors.add(value);
|
|
51
|
+
try {
|
|
52
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
53
|
+
if (typeof key !== "string")
|
|
54
|
+
throw new TypeError(`Symbol key at ${path}`);
|
|
55
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
56
|
+
if (!descriptor?.enumerable)
|
|
57
|
+
continue;
|
|
58
|
+
if (!("value" in descriptor))
|
|
59
|
+
throw new TypeError(`Accessor property at ${path}.${key}`);
|
|
60
|
+
assertSerializable(descriptor.value, `${path}.${key}`, ancestors);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
ancestors.delete(value);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** Serializa estado y props transferibles al navegador, rechazando valores ambiguos. */
|
|
68
|
+
export function serializeJson(value) {
|
|
69
|
+
assertSerializable(value, "$", new WeakSet());
|
|
70
|
+
const json = JSON.stringify(value);
|
|
71
|
+
if (json === undefined)
|
|
72
|
+
throw new TypeError("Value cannot be serialized to JSON");
|
|
73
|
+
return json
|
|
74
|
+
.replaceAll("<", "\\u003c")
|
|
75
|
+
.replaceAll(">", "\\u003e")
|
|
76
|
+
.replaceAll("&", "\\u0026")
|
|
77
|
+
.replaceAll("\u2028", "\\u2028")
|
|
78
|
+
.replaceAll("\u2029", "\\u2029");
|
|
79
|
+
}
|
package/dist/types.d.ts
ADDED
package/dist/types.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
import ts from "@typescript/typescript6";
|
|
4
|
+
import { compile } from "./compiler.js";
|
|
5
|
+
/** Genera declaraciones TypeScript para un componente y sus imports .meeko relativos. */
|
|
6
|
+
export async function generateTypes(source, filename) {
|
|
7
|
+
if (!filename.endsWith(".meeko"))
|
|
8
|
+
throw new TypeError("Type generation requires a .meeko input file");
|
|
9
|
+
const declarations = new Map();
|
|
10
|
+
async function collect(content, path) {
|
|
11
|
+
if (declarations.has(path))
|
|
12
|
+
return;
|
|
13
|
+
const generated = compile(content, path).code;
|
|
14
|
+
const result = ts.transpileDeclaration(generated, {
|
|
15
|
+
fileName: `${path}.ts`,
|
|
16
|
+
compilerOptions: { declaration: true, emitDeclarationOnly: true },
|
|
17
|
+
});
|
|
18
|
+
const error = result.diagnostics?.find((diagnostic) => diagnostic.category === ts.DiagnosticCategory.Error);
|
|
19
|
+
if (error)
|
|
20
|
+
throw new Error(ts.flattenDiagnosticMessageText(error.messageText, "\n"));
|
|
21
|
+
declarations.set(path, result.outputText);
|
|
22
|
+
for (const match of generated.matchAll(/\b(?:from\s*|import\s*)["']([^"']+\.meeko)["']/g)) {
|
|
23
|
+
const specifier = match[1];
|
|
24
|
+
if (!specifier.startsWith("."))
|
|
25
|
+
continue;
|
|
26
|
+
const child = resolve(dirname(path), specifier);
|
|
27
|
+
await collect(await readFile(child, "utf8"), child);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
await collect(source, resolve(filename));
|
|
31
|
+
const outputs = [];
|
|
32
|
+
for (const [path, declaration] of declarations) {
|
|
33
|
+
const output = path.replace(/\.meeko$/, ".d.meeko.ts");
|
|
34
|
+
await writeFile(output, declaration, "utf8");
|
|
35
|
+
outputs.push(output);
|
|
36
|
+
}
|
|
37
|
+
return outputs;
|
|
38
|
+
}
|
package/dist/vite.d.ts
ADDED
package/dist/vite.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { normalizePath, transformWithOxc } from "vite";
|
|
5
|
+
import { compile } from "./compiler.js";
|
|
6
|
+
const stylePrefix = "\0virtual:meeko-style:";
|
|
7
|
+
const runtimeDirectory = `${normalizePath(dirname(fileURLToPath(import.meta.url)))}/`;
|
|
8
|
+
/** Transforma componentes .meeko para Vite, tanto en cliente como en SSR. */
|
|
9
|
+
export function meeko() {
|
|
10
|
+
let isDev = false;
|
|
11
|
+
const styles = new Map();
|
|
12
|
+
return {
|
|
13
|
+
name: "meeko:components",
|
|
14
|
+
enforce: "pre",
|
|
15
|
+
configResolved(config) {
|
|
16
|
+
isDev = config.command === "serve";
|
|
17
|
+
},
|
|
18
|
+
resolveId(id) {
|
|
19
|
+
if (id.startsWith("virtual:meeko-style:"))
|
|
20
|
+
return `\0${id}`;
|
|
21
|
+
return null;
|
|
22
|
+
},
|
|
23
|
+
load(id) {
|
|
24
|
+
if (!id.startsWith(stylePrefix) || !id.endsWith(".css"))
|
|
25
|
+
return null;
|
|
26
|
+
return styles.get(id) ?? null;
|
|
27
|
+
},
|
|
28
|
+
async transform(source, id) {
|
|
29
|
+
if (!id.endsWith(".meeko"))
|
|
30
|
+
return null;
|
|
31
|
+
const filename = normalizePath(resolve(id));
|
|
32
|
+
const result = compile(source, filename, { hot: isDev });
|
|
33
|
+
const styleId = `${stylePrefix}${createHash("sha256").update(filename).update("\0").update(result.css).digest("hex")}.css`;
|
|
34
|
+
if (result.css)
|
|
35
|
+
styles.set(styleId, result.css);
|
|
36
|
+
const cssImport = result.css ? `\nimport ${JSON.stringify(styleId.slice(1))};` : "";
|
|
37
|
+
const hotCode = isDev ? `\nif (import.meta.hot) {\n __meeko.enableHotModule(__hotId);\n import.meta.hot.accept((next) => { if (next) __meeko.replaceHotModule(__hotId, next); });\n}\n` : "";
|
|
38
|
+
return transformWithOxc(`${result.code}${cssImport}${hotCode}`, `${filename}.ts`, { lang: "ts" });
|
|
39
|
+
},
|
|
40
|
+
handleHotUpdate({ file, server }) {
|
|
41
|
+
if (!normalizePath(file).startsWith(runtimeDirectory))
|
|
42
|
+
return;
|
|
43
|
+
server.ws.send({ type: "full-reload" });
|
|
44
|
+
return [];
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,71 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meekojs/meeko",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"packageManager": "pnpm@12.14.0",
|
|
5
|
+
"description": "Typed .meeko component engine with SSR, hydration, signals, and Vite integration.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"files": ["dist/"],
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"repository": { "type": "git", "url": "git+https://github.com/meekojs/meeko.git" },
|
|
11
|
+
"homepage": "https://github.com/meekojs/meeko#readme",
|
|
12
|
+
"bugs": { "url": "https://github.com/meekojs/meeko/issues" },
|
|
13
|
+
"keywords": ["meeko", "components", "ssr", "hydration", "reactivity", "vite", "typescript"],
|
|
14
|
+
"publishConfig": { "access": "public" },
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./vite": {
|
|
21
|
+
"types": "./dist/vite.d.ts",
|
|
22
|
+
"default": "./dist/vite.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"bin": {
|
|
26
|
+
"meeko": "dist/cli.js"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"prepack": "tsc -p tsconfig.build.json",
|
|
30
|
+
"build": "tsc -p tsconfig.build.json",
|
|
31
|
+
"check": "tsc -p tsconfig.json --noEmit",
|
|
32
|
+
"test": "pnpm run build && pnpm run example:compile && tsx --test tests/*.test.ts",
|
|
33
|
+
"example:compile": "node dist/cli.js compile examples/counter/Counter.meeko examples/counter/Counter.generated.ts && node dist/cli.js compile examples/attributes/Attributes.meeko examples/attributes/Attributes.generated.ts && node dist/cli.js compile examples/regions/Regions.meeko examples/regions/Regions.generated.ts && node dist/cli.js compile examples/primitives/Primitives.meeko examples/primitives/Primitives.generated.ts",
|
|
34
|
+
"example:bundle": "pnpm run build && pnpm run example:compile && esbuild examples/counter/client.ts --bundle --format=esm --platform=browser --target=es2022 --outfile=examples/counter/client.bundle.js",
|
|
35
|
+
"example:check": "tsc -p examples/counter/tsconfig.json --noEmit",
|
|
36
|
+
"example:serve": "pnpm run example:bundle && tsx examples/counter/server.ts",
|
|
37
|
+
"vite:dev": "vite examples/vite --config examples/vite/vite.config.ts",
|
|
38
|
+
"vite:types": "pnpm run build && node dist/cli.js types examples/counter/Counter.meeko && node dist/cli.js types examples/regions/Regions.meeko && node dist/cli.js types examples/vite/Hot.meeko && node dist/cli.js types examples/nested/Parent.meeko && tsc -p examples/vite/tsconfig.json --noEmit",
|
|
39
|
+
"vite:build": "vite build examples/vite --config examples/vite/vite.config.ts",
|
|
40
|
+
"e2e": "pnpm run example:bundle && pnpm run vite:build && tsx --test tests/browser.e2e.ts",
|
|
41
|
+
"benchmark:check": "pnpm run example:compile && tsc -p tsconfig.benchmark.json --noEmit",
|
|
42
|
+
"benchmark": "pnpm run build && pnpm run benchmark:check && node --expose-gc --import tsx benchmarks/run.ts",
|
|
43
|
+
"package:smoke": "pwsh -NoProfile -File tests/package-consumer.ps1",
|
|
44
|
+
"verify": "pnpm run check && pnpm run test && pnpm run example:check && tsc -p tsconfig.test.json --noEmit && pnpm run vite:types && pnpm run benchmark:check && pnpm run vite:build"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@typescript/typescript6": "6.0.2",
|
|
48
|
+
"parse5": "^8.0.0",
|
|
49
|
+
"postcss": "^8.5.31",
|
|
50
|
+
"postcss-selector-parser": "^7.1.7",
|
|
51
|
+
"typescript": "7.0.2"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"vite": "^8.3.5"
|
|
55
|
+
},
|
|
56
|
+
"peerDependenciesMeta": {
|
|
57
|
+
"vite": { "optional": true }
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@types/node": "^24.0.0",
|
|
61
|
+
"esbuild": "0.28.2",
|
|
62
|
+
"happy-dom": "^20.0.0",
|
|
63
|
+
"playwright-core": "1.64.1",
|
|
64
|
+
"tsx": "^4.20.0",
|
|
65
|
+
"vite": "8.3.5",
|
|
66
|
+
"vue": "3.5.44"
|
|
67
|
+
},
|
|
68
|
+
"engines": {
|
|
69
|
+
"node": ">=24"
|
|
70
|
+
}
|
|
71
|
+
}
|