vite-plugin-vanjs 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/jsx/jsx.mjs ADDED
@@ -0,0 +1,46 @@
1
+ import van from "@vanjs/van";
2
+ import setup from "@vanjs/van";
3
+ import { setAttribute, styleToString } from "./utils.mjs";
4
+
5
+ export const jsx = (jsxTag, { children, ref, style, ...props }) => {
6
+ if (typeof jsxTag === "string") {
7
+ const newElement = van.tags[jsxTag](props, children);
8
+
9
+ // on server it's good enough to return here
10
+ if (setup.isServer) return newElement;
11
+
12
+ // on the client, we sure do need to set the attributes
13
+ for (const [k, value] of Object.entries(props)) {
14
+ if (typeof value === "function" && !k.startsWith("on")) {
15
+ van.derive(() => setAttribute(newElement, k, value()));
16
+ continue;
17
+ }
18
+
19
+ if (typeof value === "function" && k.startsWith("on")) {
20
+ newElement.addEventListener(k.slice(2).toLowerCase(), value);
21
+ continue;
22
+ }
23
+
24
+ if (typeof value === "object" && "val" in value) {
25
+ van.derive(() => setAttribute(newElement, k, value.val));
26
+ continue;
27
+ }
28
+
29
+ setAttribute(newElement, k, value);
30
+ }
31
+ if (style) {
32
+ if (typeof style === "function") {
33
+ van.derive(() => newElement.style.cssText = styleToString(style()));
34
+ } else {
35
+ newElement.style.cssText = styleToString(style);
36
+ }
37
+ }
38
+
39
+ if (ref) ref.val = newElement;
40
+ return newElement;
41
+ }
42
+
43
+ return typeof jsxTag === "function"
44
+ ? jsxTag({ children, ref, style, ...props })
45
+ : null;
46
+ };
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "jsx",
3
+ "type": "module",
4
+ "exports": {
5
+ ".": {
6
+ "types": "./index.d.ts",
7
+ "import": "./index.mjs"
8
+ },
9
+ "./jsx-runtime": {
10
+ "types": "./jsx-runtime.d.ts",
11
+ "import": "./jsx-runtime.mjs"
12
+ },
13
+ "./jsx-dev-runtime": {
14
+ "types": "./jsx-dev-runtime.d.ts",
15
+ "import": "./jsx-dev-runtime.mjs"
16
+ }
17
+ },
18
+ "peerDependencies": {
19
+ "vite-plugin-vanjs": "*",
20
+ "csstype": "*",
21
+ "mini-van-plate": "*",
22
+ "vanjs-core": "*",
23
+ "vanjs-ext": "*"
24
+ },
25
+ "sideEffects": false
26
+ }
package/jsx/utils.mjs ADDED
@@ -0,0 +1,24 @@
1
+ export const setAttribute = (element, key, value) => {
2
+ if (value == null || value === false || value === "") {
3
+ element.removeAttribute(key);
4
+ } else {
5
+ const attr = value === true ? "" : String(value);
6
+ element.setAttribute(key, attr);
7
+ }
8
+ };
9
+
10
+ export const styleToString = (style) => {
11
+ return typeof style === "string"
12
+ ? style
13
+ : typeof style === "object"
14
+ ? Object.entries(style).reduce((acc, key) =>
15
+ acc +
16
+ key[0]
17
+ .split(/(?=[A-Z])/)
18
+ .join("-")
19
+ .toLowerCase() +
20
+ ":" +
21
+ key[1] +
22
+ ";", "")
23
+ : "";
24
+ };
@@ -0,0 +1 @@
1
+ export * from "./jsx/jsx-dev-runtime";
@@ -0,0 +1 @@
1
+ export * from "./jsx/jsx-runtime";
package/package.json ADDED
@@ -0,0 +1,80 @@
1
+ {
2
+ "name": "vite-plugin-vanjs",
3
+ "version": "0.0.1",
4
+ "author": "thednp",
5
+ "license": "MIT",
6
+ "description": "A Vite plugin for VanJS to enable JSX transformation and simplify aplication development.",
7
+ "repository": "https://github.com/thednp/vite-plugin-vanjs",
8
+ "type": "module",
9
+ "sideEffects": false,
10
+ "main": "./src/index.mjs",
11
+ "module": "./src/index.mjs",
12
+ "types": "./src/types.d.ts",
13
+ "files": [
14
+ "src",
15
+ "setup",
16
+ "jsx",
17
+ "tsconfig.json",
18
+ "package.json",
19
+ "jsx-runtime.d.ts",
20
+ "jsx-dev-runtime.d.ts",
21
+ "README.md",
22
+ "LICENSE"
23
+ ],
24
+ "keywords": [
25
+ "vanjs",
26
+ "vite",
27
+ "plugin",
28
+ "ssr",
29
+ "ssg",
30
+ "jsx"
31
+ ],
32
+ "exports": {
33
+ ".": {
34
+ "types": "./src/types.d.ts",
35
+ "import": "./src/index.mjs",
36
+ "default": "./src/index.mjs"
37
+ },
38
+ "./setup": {
39
+ "types": "./setup/index.d.ts",
40
+ "import": "./setup/index.mjs",
41
+ "require": "./setup/index.cjs"
42
+ },
43
+ "./jsx": {
44
+ "types": "./jsx/index.d.ts",
45
+ "import": "./jsx/index.mjs"
46
+ },
47
+ "./jsx-runtime": {
48
+ "types": "./jsx/jsx-runtime.d.ts",
49
+ "import": "./jsx/jsx-runtime.mjs"
50
+ },
51
+ "./jsx-dev-runtime": {
52
+ "types": "./jsx/jsx-dev-runtime.d.ts",
53
+ "import": "./jsx/jsx-dev-runtime.mjs"
54
+ }
55
+ },
56
+ "peerDependencies": {
57
+ "csstype": "*",
58
+ "mini-van-plate": "*",
59
+ "vanjs-core": "*",
60
+ "vanjs-ext": "*"
61
+ },
62
+ "dependencies": {
63
+ "csstype": "^3.1.3",
64
+ "mini-van-plate": "^0.6.1",
65
+ "vanjs-core": "^1.5.2",
66
+ "vanjs-ext": "^0.6.2"
67
+ },
68
+ "devDependencies": {
69
+ "typescript": "5.6.2",
70
+ "vite": "^6.0.5"
71
+ },
72
+ "scripts": {
73
+ "badges": "npx -p dependency-version-badge update-badge vanjs-core mini-van-plate typescript vite",
74
+ "format": "deno fmt src setup jsx",
75
+ "lint": "pnpm lint:ts && pnpm check:ts",
76
+ "lint:ts": "deno lint src",
77
+ "fix:ts": "deno lint src --fix",
78
+ "check:ts": "tsc -noEmit"
79
+ }
80
+ }
@@ -0,0 +1,24 @@
1
+ declare module "@vanjs/van" {
2
+ import type { Van } from "vanjs-core";
3
+ const van: Van;
4
+ export default van;
5
+ }
6
+
7
+ declare module "@vanjs/vanX" {
8
+ import * as VanX from "vanjs-ext";
9
+ const vanX: typeof VanX;
10
+ export default vanX;
11
+ }
12
+
13
+ declare module "@vanjs/setup" {
14
+ import type { Van } from "vanjs-core";
15
+ import * as VanX from "vanjs-ext";
16
+
17
+ interface Setup {
18
+ isServer: boolean;
19
+ van: Van;
20
+ vanX: typeof VanX;
21
+ }
22
+ const setup: Setup;
23
+ export default setup;
24
+ }
@@ -0,0 +1,14 @@
1
+ /// <reference path="global.d.ts" />
2
+
3
+ import { dummyVanX } from "mini-van-plate/shared";
4
+ import vanPlate from "mini-van-plate/van-plate";
5
+ import vanCore from "vanjs-core";
6
+ import * as vanX from "vanjs-ext";
7
+
8
+ type VansSetup = {
9
+ isServer: boolean;
10
+ van: typeof vanPlate & typeof vanCore;
11
+ vanX: typeof dummyVanX | typeof vanX;
12
+ };
13
+
14
+ export default VansSetup;
@@ -0,0 +1,18 @@
1
+ import { dummyVanX, registerEnv } from "mini-van-plate/shared";
2
+ import vanPlate from "mini-van-plate/van-plate";
3
+ import vanCore from "vanjs-core";
4
+ import * as vanX from "vanjs-ext";
5
+
6
+ const setup = {
7
+ isServer: typeof window === "undefined",
8
+ get van() {
9
+ return this.isServer ? vanPlate : vanCore;
10
+ },
11
+ get vanX() {
12
+ return this.isServer ? dummyVanX : vanX;
13
+ },
14
+ };
15
+
16
+ registerEnv(setup);
17
+
18
+ export default setup;
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "setup",
3
+ "main": "./index.mjs",
4
+ "module": "./index.mjs",
5
+ "types": "./index.d.ts",
6
+ "type": "module",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./index.d.ts",
10
+ "import": "./index.mjs"
11
+ },
12
+ "./van": {
13
+ "types": "./van.d.ts",
14
+ "import": "./van.mjs"
15
+ },
16
+ "./vanX": {
17
+ "types": "./vanX.d.ts",
18
+ "import": "./vanX.mjs"
19
+ }
20
+ },
21
+ "peerDependencies": {
22
+ "vite-plugin-vanjs": "*",
23
+ "csstype": "*",
24
+ "mini-van-plate": "*",
25
+ "vanjs-core": "*",
26
+ "vanjs-ext": "*"
27
+ },
28
+ "sideEffects": false
29
+ }
package/setup/van.mjs ADDED
@@ -0,0 +1,2 @@
1
+ import setup from "./index.mjs";
2
+ export default setup.van;
package/setup/vanX.mjs ADDED
@@ -0,0 +1,2 @@
1
+ import setup from "./index.mjs";
2
+ export default setup.vanX;
package/src/index.mjs ADDED
@@ -0,0 +1,32 @@
1
+ import { fileURLToPath } from "node:url";
2
+ import { dirname, resolve } from "node:path";
3
+
4
+ const __filename = fileURLToPath(import.meta.url);
5
+ const __dirname = dirname(__filename);
6
+
7
+ export default function VitePluginVanJS() {
8
+ return {
9
+ name: "vanjs",
10
+ enforce: "pre",
11
+ config() {
12
+ return {
13
+ resolve: {
14
+ alias: {
15
+ "@vanjs/jsx": resolve(__dirname, "../jsx"),
16
+ "@vanjs/setup": resolve(__dirname, "../setup"),
17
+ "@vanjs/van": resolve(__dirname, "../setup/van"),
18
+ "@vanjs/vanX": resolve(__dirname, "../setup/vanX"),
19
+ },
20
+ },
21
+ optimizeDeps: {
22
+ include: ["vanjs-core", "mini-van-plate", "vanjs-ext"],
23
+ },
24
+ esbuild: {
25
+ jsx: "automatic",
26
+ jsxFactory: "jsx",
27
+ jsxFragment: "Fragment",
28
+ },
29
+ };
30
+ },
31
+ };
32
+ }
package/src/types.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import type { Plugin } from "vite";
2
+ export * from "../jsx";
3
+ export * from "../setup";
4
+ export default function VitePluginVanJS(): Plugin;
package/tsconfig.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ // https://janessagarrow.com/blog/typescript-and-esbuild/
3
+ "compilerOptions": {
4
+ "lib": ["DOM", "ESNext", "DOM.Iterable"],
5
+ "rootDir": "./",
6
+ "baseUrl": "./",
7
+ "module": "ESNext",
8
+ "target": "ESNext",
9
+ "moduleResolution": "Bundler",
10
+ "allowJs": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "resolvePackageJsonImports": true,
13
+ "useDefineForClassFields": true,
14
+ "strict": true,
15
+ "sourceMap": true,
16
+ "resolveJsonModule": true,
17
+ "esModuleInterop": true,
18
+ "isolatedModules": true,
19
+ "noUnusedLocals": true,
20
+ "noUnusedParameters": true,
21
+ "noImplicitReturns": true,
22
+ "removeComments": false,
23
+ "allowSyntheticDefaultImports": true,
24
+ "allowImportingTsExtensions": true,
25
+ "skipLibCheck": true,
26
+ "noEmit": true,
27
+ "checkJs": true,
28
+ "jsx": "preserve",
29
+ "jsxImportSource": "vite-plugin-vanjs",
30
+ },
31
+ "include": ["./src/**/*", "./jsx/**/*.d.ts", "setup/**/*"],
32
+ "exclude": ["node_modules", "experiments", "coverage"],
33
+ }