mdzjs 0.0.4 → 0.0.6
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/examples/vanjs/README.md +4 -0
- package/examples/vanjs/package-lock.json +1979 -52
- package/examples/vanjs/package.json +2 -0
- package/examples/vanjs/src/App.css +13 -2
- package/examples/vanjs/src/App.js +25 -27
- package/examples/vanjs/src/blog/test.mdx +42 -80
- package/examples/vanjs/src/components/Counter.js +7 -4
- package/examples/vanjs/src/components/Sketch.js +24 -0
- package/examples/vanjs/vite.config.js +4 -1
- package/package.json +3 -2
- package/preview/test.mdz +2 -0
- package/src/bundlers/vite.js +2 -2
- package/src/transpiler/transpile.js +2 -1
- package/src/utils/hyperscript.js +3 -2
- package/examples/vanjs/src/blog/__test__.mdx +0 -18
- package/examples/vanjs/src/components/comp.js +0 -13
- package/examples/vanjs/src/components/md.mdx +0 -0
|
@@ -22,13 +22,23 @@ a:hover {
|
|
|
22
22
|
color: #535bf2;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
.counter{
|
|
26
|
+
margin: 10px auto;
|
|
27
|
+
display: flex;
|
|
28
|
+
justify-content: center;
|
|
29
|
+
align-items: center;
|
|
30
|
+
width : 50vw;
|
|
31
|
+
height: 120px;
|
|
32
|
+
border : 2px solid darkcyan;
|
|
33
|
+
border-radius: 10%;
|
|
34
|
+
}
|
|
35
|
+
/* body {
|
|
26
36
|
margin: 0;
|
|
27
37
|
display: flex;
|
|
28
38
|
place-items: center;
|
|
29
39
|
min-width: 320px;
|
|
30
40
|
min-height: 100vh;
|
|
31
|
-
}
|
|
41
|
+
} */
|
|
32
42
|
|
|
33
43
|
h1 {
|
|
34
44
|
font-size: 3.2em;
|
|
@@ -71,6 +81,7 @@ button {
|
|
|
71
81
|
background-color: #1a1a1a;
|
|
72
82
|
cursor: pointer;
|
|
73
83
|
transition: border-color 0.25s;
|
|
84
|
+
height: 50px;
|
|
74
85
|
}
|
|
75
86
|
button:hover {
|
|
76
87
|
border-color: #646cff;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import van from "vanjs-core";
|
|
2
|
-
import Counter from "./components/Counter";
|
|
3
2
|
import "./App.css";
|
|
4
|
-
import "ziko-wrapper/van"
|
|
5
3
|
import Blog ,{title} from "./blog/test.mdx";
|
|
6
4
|
console.log({title})
|
|
7
5
|
|
|
@@ -9,31 +7,31 @@ export const App = () => {
|
|
|
9
7
|
const { div, h1, img, p, a } = van.tags;
|
|
10
8
|
return div(
|
|
11
9
|
Blog({name : "cyan", __code_style__ : "1c-light"}).vertical(-1, -1),
|
|
12
|
-
a(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
),
|
|
22
|
-
a(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
),
|
|
32
|
-
h1(
|
|
33
|
-
|
|
34
|
-
),
|
|
35
|
-
div({ class: "card" }, Counter()),
|
|
36
|
-
p({ class: "read-the-docs" }, "Click on the VanJS logo to learn more"),
|
|
10
|
+
// a(
|
|
11
|
+
// { href: "https://vite.dev", target: "_blank" },
|
|
12
|
+
// img({
|
|
13
|
+
// src: "/vite.svg",
|
|
14
|
+
// class: "logo",
|
|
15
|
+
// alt: "Vite logo",
|
|
16
|
+
// width: 96,
|
|
17
|
+
// height: 96,
|
|
18
|
+
// }),
|
|
19
|
+
// ),
|
|
20
|
+
// a(
|
|
21
|
+
// { href: "https://vanjs.org", target: "_blank" },
|
|
22
|
+
// img({
|
|
23
|
+
// src: "/vanjs.svg",
|
|
24
|
+
// class: "logo vanjs",
|
|
25
|
+
// alt: "VanJS logo",
|
|
26
|
+
// width: 96,
|
|
27
|
+
// height: 96,
|
|
28
|
+
// }),
|
|
29
|
+
// ),
|
|
30
|
+
// h1(
|
|
31
|
+
// "Hello VanJS!",
|
|
32
|
+
// ),
|
|
33
|
+
// div({ class: "card" }, Counter()),
|
|
34
|
+
// p({ class: "read-the-docs" }, "Click on the VanJS logo to learn more"),
|
|
37
35
|
);
|
|
38
36
|
};
|
|
39
37
|
|
|
@@ -1,106 +1,68 @@
|
|
|
1
1
|
---
|
|
2
2
|
title : "Vanjs Zikojs Interleaving"
|
|
3
|
-
background : "red"
|
|
4
3
|
__props__ : {
|
|
5
|
-
|
|
6
|
-
cel ,
|
|
4
|
+
counter_start : 0
|
|
7
5
|
}
|
|
8
|
-
__code_style__ : "default"
|
|
9
6
|
---
|
|
10
7
|
|
|
11
|
-
import
|
|
8
|
+
import Counter from "../components/Counter.js"
|
|
9
|
+
import Sketch from "../components/Sketch.js"
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
# Hello World
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const b = 20
|
|
18
|
-
console.log({a, b})
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
Hello {background}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
<Dom>
|
|
26
|
-
Dm
|
|
27
|
-
*inline*
|
|
28
|
-
</Dom>
|
|
29
|
-
|
|
30
|
-
<p>
|
|
31
|
-
** Html **
|
|
32
|
-
</p>
|
|
33
|
-
|
|
34
|
-
## Overview
|
|
35
|
-
|
|
36
|
-
Hi 👋 I'm working on a library called [Zikojs](https://github.com/zakarialaoui10/ziko.js), It shares many principles with VanJS especially in terms of **declarative hyperscript-style coding** **Strong 2**
|
|
37
|
-
|
|
38
|
-
Hi 👋 I'm working on a library called [Zikojs](https://github.com/zakarialaoui10/ziko.js),
|
|
39
|
-
It shares many principles with VanJS especially in terms of **declarative hyperscript-style coding** **Strong 2** .
|
|
13
|
+
Introducing **MDZ** a Markdown preprocessor designed for [Zikojs](https://github.com/zakarialaoui10)
|
|
14
|
+
Thanks to the [interleaving](https://github.com/vanjs-org/van/issues/456) capability between **Zikojs** and **VanJS**, MDZ is fully compatible with VanJS as well.
|
|
40
15
|
|
|
41
|
-
|
|
16
|
+
The example below show how it works.
|
|
42
17
|
|
|
43
|
-
|
|
18
|
+
To define a component, you can use a Hyperscript-based syntax :
|
|
19
|
+
```js
|
|
20
|
+
// compoenents/Counter.js
|
|
21
|
+
import van from "vanjs-core";
|
|
44
22
|
|
|
45
|
-
|
|
23
|
+
const Counter = ({start = 0}={}) => {
|
|
24
|
+
const { button } = van.tags;
|
|
25
|
+
const counter = van.state(start);
|
|
26
|
+
return (
|
|
27
|
+
button({ onclick: () => ++counter.val }, "Counter: ", counter)
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
export default Counter;
|
|
46
31
|
|
|
47
|
-
|
|
32
|
+
```
|
|
48
33
|
|
|
49
|
-
|
|
50
|
-
- In **Vanjs** it returns a Dom `Node` ( `HTMLElement` or `SVGElement`)
|
|
51
|
-
- In **Zikojs** returns an instance `ZikoUIElement`, which contains the DOM node internally (accessible via .element) and provides an extended API.
|
|
34
|
+
To integrate the component inside MDZ, use JSX-like syntax :
|
|
52
35
|
|
|
53
|
-
|
|
36
|
+
```jsx
|
|
37
|
+
<Counter start={5} />
|
|
38
|
+
```
|
|
54
39
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
- Use **VanJS elements** inside ZikoJS layouts.
|
|
58
|
-
- Use **ZikoJS components** inside VanJS tags.
|
|
40
|
+
The MDZ file is parsed as a JavaScript module and returns the UI component as its default export.
|
|
41
|
+
Additionally, any declared attributes are exposed as named exports
|
|
59
42
|
|
|
60
|
-
## How It works ?
|
|
61
|
-
- In order to make vanjs elements compatible with zikojs i added this line inside my library :
|
|
62
43
|
```js
|
|
63
|
-
|
|
44
|
+
import Blog ,{title} from "./blog/test.mdx";
|
|
45
|
+
console.log(title) // Vanjs Zikojs Interleaving
|
|
64
46
|
```
|
|
65
|
-
|
|
47
|
+
In this case, Blog behaves like a JavaScript function with destructured props : (\{ counter_start = 0 } = \{})
|
|
66
48
|
|
|
67
|
-
|
|
68
|
-
ziko-wrapper/vanify.js
|
|
49
|
+
this design allows you to pass props to any part of the Markdown content — including passing them as props to embedded VanJS components.
|
|
69
50
|
|
|
70
|
-
|
|
51
|
+
<Counter start={counter_start} />
|
|
71
52
|
|
|
72
|
-
```js
|
|
73
|
-
import "ziko-wrapper/van";
|
|
74
|
-
```
|
|
75
|
-
This will patch VanJS to automatically unwrap ZikoJS elements when used as children.
|
|
76
|
-
|
|
77
|
-
> [!Tip]
|
|
78
|
-
> So, practically, all ZikoJS libraries can be considered usable as VanJS libraries and vice versa.
|
|
79
53
|
|
|
80
|
-
##
|
|
81
|
-
```javascript
|
|
82
|
-
import van from "vanjs-core";
|
|
83
|
-
import { Flex } from "ziko";
|
|
84
|
-
import { Activity } from "vanjs-lucide";
|
|
85
|
-
import "ziko-wrapper/van";
|
|
86
|
-
|
|
87
|
-
const { p } = van.tags;
|
|
88
|
-
|
|
89
|
-
const para = p(
|
|
90
|
-
Flex(
|
|
91
|
-
p("Hello From Van"),
|
|
92
|
-
Activity({ class:"icon", style:"color: turquoise" })
|
|
93
|
-
)
|
|
94
|
-
.style({ border: "1px darkblue solid" })
|
|
95
|
-
.vertical(0, 0)
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
document.body.append(para)
|
|
99
|
-
```
|
|
54
|
+
## P5-wrapper Example :
|
|
100
55
|
|
|
101
|
-
|
|
56
|
+
First of all [P5.wrapper](https://github.com/zakarialaoui10/p5.wrapper) is another Zikojs and VanJS plugin that enables P5.js to run in a declarative and component-based way.
|
|
57
|
+
It's not ready for production yet, but I've included this demo to showcase how it works.
|
|
102
58
|
|
|
103
|
-
|
|
104
|
-
> For me, once I finish the documentation, I plan to add VanJS plugins as ZikoJS plugins. Now, I want to add some of my libraries as VanJS plugins as well, but I’m wondering whether I should create independent packages with names prefixed by `van-[plugin]`, or if it’s enough to provide a wrapper—like I did in [p5.wrapper](https://github.com/zakarialaoui10/p5.wrapper)—so users just need to import from `ziko-[plugin]/van` ?
|
|
59
|
+
<Sketch />
|
|
105
60
|
|
|
61
|
+
## Show Supports
|
|
106
62
|
|
|
63
|
+
If you find this project useful or inspiring, consider showing your support by giving a star to the libraries that make it all possible :
|
|
64
|
+
- => [Zikojs](https://github.com/zakarialaoui10/ziko.js) The core UI engine that powers reactive rendering in this project.
|
|
65
|
+
- => [Mdzjs](https://github.com/zakarialaoui10/mdzjs) The Markdown preprocessor that lets you use JSX-like components and JavaScript expressions inside Markdown files.
|
|
66
|
+
- => [Vanjs](https://github.com/vanjs-org/van) A lightweight UI library compatible with Zikojs, used here for interleaving component rendering.
|
|
67
|
+
- => [Ziko-Wrapper](https://github.com/zakarialaoui10/ziko-wrapper) The bridge that enables using Zikojs components inside Vanjs seamlessly without compatibility issues.
|
|
68
|
+
- => [p5.wrapper](https://github.com/zakarialaoui10/p5.wrapper) A declarative wrapper that allows embedding P5.js sketches as components inside your app.
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import van from "vanjs-core";
|
|
2
2
|
|
|
3
|
-
const Counter = () => {
|
|
4
|
-
const { button } = van.tags;
|
|
5
|
-
const counter = van.state(
|
|
3
|
+
const Counter = ({counter_start = 10}={}) => {
|
|
4
|
+
const { button, div } = van.tags;
|
|
5
|
+
const counter = van.state(counter_start);
|
|
6
6
|
return (
|
|
7
|
-
|
|
7
|
+
div(
|
|
8
|
+
{class : "counter"},
|
|
9
|
+
button({ onclick: () => ++counter.val }, "Counter: ", counter),
|
|
10
|
+
)
|
|
8
11
|
);
|
|
9
12
|
};
|
|
10
13
|
export default Counter;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { P5Canvas2D, P5Circle } from "p5.wrapper/van";
|
|
2
|
+
import { cos, sin, PI } from "ziko";
|
|
3
|
+
|
|
4
|
+
const c1 = P5Circle({ r : 40})
|
|
5
|
+
.fill("blue")
|
|
6
|
+
.stroke("green");
|
|
7
|
+
const c2 = P5Circle({x:0, y:0, r:50})
|
|
8
|
+
.fill("darkblue")
|
|
9
|
+
.stroke("green");
|
|
10
|
+
|
|
11
|
+
const Canvas = () => P5Canvas2D(c1, c2)
|
|
12
|
+
.style({
|
|
13
|
+
outline : "2px darkblue solid",
|
|
14
|
+
margin : "50px auto"
|
|
15
|
+
})
|
|
16
|
+
.size("250px", "250px")
|
|
17
|
+
.view(-100, -100, 100, 100)
|
|
18
|
+
.setCustomLoopCallback(e => {
|
|
19
|
+
c1.posX(75 * cos((e.iter * PI) / 50));
|
|
20
|
+
c1.posY(75 * sin((e.iter * PI) / 50));
|
|
21
|
+
c2.setRadius(20*(1.5+cos(e.iter * PI/50)))
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export default Canvas
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mdzjs",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
"rollup": "^4.24.0",
|
|
36
36
|
"unified": "^11.0.5",
|
|
37
37
|
"yaml": "^2.6.1",
|
|
38
|
-
"ziko": "^0.0.27"
|
|
38
|
+
"ziko": "^0.0.27",
|
|
39
|
+
"ziko-wrapper": "^0.0.25"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"@rollup/plugin-commonjs": "^28.0.0",
|
package/preview/test.mdz
CHANGED
package/src/bundlers/vite.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { transpileMDZ } from "../transpiler/index.js";
|
|
2
|
-
export default function ViteMDZ({extensions = [".mdx"]}={}){
|
|
2
|
+
export default function ViteMDZ({extensions = [".mdx"], useVanJs = false}={}){
|
|
3
3
|
return {
|
|
4
4
|
name: 'MDZ',
|
|
5
5
|
transform(src, id) {
|
|
6
6
|
if (id.endsWith('.mdz')||extensions.some(ext=>id.endsWith(ext))) {
|
|
7
7
|
return {
|
|
8
|
-
code: transpileMDZ(src),
|
|
8
|
+
code: transpileMDZ(src, useVanJs),
|
|
9
9
|
map: null,
|
|
10
10
|
};
|
|
11
11
|
}
|
|
@@ -2,7 +2,7 @@ import { parseMDZ } from "./parser.js";
|
|
|
2
2
|
import { processMDZAST } from "./process.js";
|
|
3
3
|
import { stringifyProps } from "../utils/parse-yml.js";
|
|
4
4
|
|
|
5
|
-
const transpileMDZ=(Markdown, CodeStyle = "1c-light")=>{
|
|
5
|
+
const transpileMDZ=(Markdown, useVanJs = false, CodeStyle = "1c-light")=>{
|
|
6
6
|
const ast = parseMDZ(Markdown);
|
|
7
7
|
const {attrs, props, esm, statements, hasCode}= processMDZAST(ast)
|
|
8
8
|
const body = [
|
|
@@ -16,6 +16,7 @@ const transpileMDZ=(Markdown, CodeStyle = "1c-light")=>{
|
|
|
16
16
|
"return UI }"
|
|
17
17
|
]
|
|
18
18
|
if(hasCode) body.unshift(`import("highlight.js/styles/${CodeStyle}.css")`);
|
|
19
|
+
if(useVanJs) body.unshift('import "ziko-wrapper/van"')
|
|
19
20
|
return body.join("\n");
|
|
20
21
|
}
|
|
21
22
|
export{
|
package/src/utils/hyperscript.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
export const hyperscript = (tag, attrs, children="") => {
|
|
2
2
|
const HasChildren = !!children;
|
|
3
3
|
|
|
4
|
-
if(tag
|
|
5
|
-
children = children + ',""'
|
|
4
|
+
if(tag){
|
|
5
|
+
children = ',""' + children + ',""'
|
|
6
6
|
const splitted = splitQuotedLines(children);
|
|
7
7
|
children = insertBetween(splitted, 'h("br")')
|
|
8
8
|
children[children.length - 1] = children.at(-1).slice(0, -3)
|
|
9
|
+
children[0] = children.at(0).slice(3)
|
|
9
10
|
}
|
|
10
11
|
return `h("${tag}", ${attrs}${HasChildren ?`, ${children}` : ""})`
|
|
11
12
|
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// export default function Dom({}, ...children){
|
|
2
|
-
// console.log({children})
|
|
3
|
-
// const element = document.createElement("div")
|
|
4
|
-
// children.forEach(n=>element.append(n))
|
|
5
|
-
// return element
|
|
6
|
-
// }
|
|
7
|
-
|
|
8
|
-
import {p} from "ziko"
|
|
9
|
-
|
|
10
|
-
export default function Dom({children}){
|
|
11
|
-
// children.forEach(n=>console.log(n.element))
|
|
12
|
-
return p("ppp");
|
|
13
|
-
}
|
|
File without changes
|