mdzjs 0.0.1 → 0.0.2

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.
Files changed (52) hide show
  1. package/README.md +70 -56
  2. package/__src__/index.js +2 -0
  3. package/__src__/test.js +21 -0
  4. package/{v2/test.js → __v2__/_test.js} +1 -1
  5. package/__v2__/clean.js +67 -0
  6. package/__v2__/hast.js +70 -0
  7. package/__v2__/html2js.js +59 -0
  8. package/__v2__/pre-parse/clean-md.js +93 -0
  9. package/__v2__/test.js +19 -0
  10. package/{v2 → __v2__}/transpiler/index.js +17 -12
  11. package/__v2__/utils/is-object.js +11 -0
  12. package/__v2__/utils/split-between.js +47 -0
  13. package/package.json +12 -6
  14. package/preview/Components/Dom.js +6 -0
  15. package/preview/index.html +10 -1
  16. package/preview/main.js +8 -17
  17. package/preview/package-lock.json +712 -8
  18. package/preview/package.json +6 -2
  19. package/preview/test.mdz +27 -49
  20. package/preview/vite.config.js +1 -1
  21. package/src/bundlers/vite.js +15 -0
  22. package/src/example.md +3 -0
  23. package/src/index.js +1 -2
  24. package/src/test.js +45 -17
  25. package/src/transpiler/index.js +3 -0
  26. package/src/transpiler/parser.js +14 -0
  27. package/src/transpiler/process.js +172 -0
  28. package/src/transpiler/transpile.js +22 -0
  29. package/src/utils/component-type.js +5 -0
  30. package/src/utils/hyperscript.js +4 -0
  31. package/src/utils/index.js +4 -0
  32. package/src/utils/parse-yml.js +19 -0
  33. package/src/utils/process-attributes.js +13 -0
  34. package/v2/pre-parse/clean-md.js +0 -93
  35. /package/{src → __src__}/converter/index.js +0 -0
  36. /package/{src → __src__}/parser/get-component-type.js +0 -0
  37. /package/{src → __src__}/parser/index.js +0 -0
  38. /package/{src → __src__}/parser/jsx2js.js +0 -0
  39. /package/{src → __src__}/parser/parser-markdown.js +0 -0
  40. /package/{src → __src__}/parser/smart-join.js +0 -0
  41. /package/{src → __src__}/vite/index.js +0 -0
  42. /package/{v2 → __v2__}/index.js +0 -0
  43. /package/{v2 → __v2__}/readme.md +0 -0
  44. /package/{v2 → __v2__}/transformers/vite/index.js +0 -0
  45. /package/{v2 → __v2__}/transpiler/get-component-type.js +0 -0
  46. /package/{v2 → __v2__}/transpiler/import-plugin.js +0 -0
  47. /package/{v2 → __v2__}/transpiler/jsx2js.js +0 -0
  48. /package/{v2 → __v2__}/transpiler/process-text.js +0 -0
  49. /package/preview/{Hi.js → Components/Hi.js} +0 -0
  50. /package/preview/{InteractiveBlock.js → Components/InteractiveBlock.js} +0 -0
  51. /package/preview/{Scene.js → Components/Scene.js} +0 -0
  52. /package/preview/{__main2.js → __main2.js.txt} +0 -0
@@ -12,8 +12,12 @@
12
12
  "vite": "^5.4.8"
13
13
  },
14
14
  "dependencies": {
15
- "ziko": "^0.0.22",
15
+ "highlight.js": "^11.11.0",
16
+ "jsdom": "^25.0.1",
17
+ "prism": "^4.1.2",
18
+ "ziko": "^0.0.27",
16
19
  "ziko-gl": "^0.0.3",
17
- "ziko-lottie": "^0.0.7"
20
+ "ziko-lottie": "^0.0.7",
21
+ "ziko-wrapper": "^0.0.25"
18
22
  }
19
23
  }
package/preview/test.mdz CHANGED
@@ -1,59 +1,37 @@
1
1
  ---
2
- title : "MDZ"
2
+ title : "MDZ Overview"
3
3
  background : "red"
4
- __Props__ : {
5
- a : 1,
6
- c : 10
4
+ __props__ : {
5
+ name : World KKK
7
6
  }
8
7
  ---
8
+ import {Dom} from "./Components/Dom"
9
+ import InteractiveBlock from "./Components/InteractiveBlock.js"
9
10
 
10
- import {cos} from "ziko";
11
- import InteractiveBlock from "./InteractiveBlock.js";
12
- import Scene from "./Scene.js";
11
+ # Hello world
13
12
 
14
- Hello World {cos(0)}
13
+ <Dom text="Hello from dom" color="red" />
14
+ <InteractiveBlock />
15
15
 
16
- Hello {title}
16
+ Hello **{name}**
17
17
 
18
- <script>
19
- var a = 1000
20
- const b = ()=> Math.random()
21
- </script>
22
-
23
- test {a}
24
-
25
- <InteractiveBlock data="Hello from MDZ" color="cyan"/>
26
-
27
- import Hi from "./Hi.js";
28
-
29
- - <Hi txt="Messi" color="red"/>
30
- - <Hi txt="Messi" color="red"/>
31
- - <Hi txt="Messi" color="red"/>
32
-
33
-
34
- - <Scene data="h"/>
35
-
36
- |A|B|
18
+ |Addon|Dependncies|
37
19
  |-|-|
38
- |1|2|
39
-
40
-
41
- <!-- {p}
42
-
43
- # Test H1
44
- # Test H1 with Expression 1+1 = {1+1}
45
- # Test H1 With IIFE {(()=>Math.random())()}
46
- # Test H1 With <Hi txt="zikojs element" color="red"/>
47
-
48
-
49
- <script>
50
- let x = [0, PI/6, PI/4, PI/2, PI]
51
- let y = cos(x)
52
- import {sin} from "ziko"
53
- </script>
54
-
55
- - **cos(x[0])** : <Hi txt={1+1} />
56
-
57
- -->
20
+ |ziko-gl|threejs|
21
+ |ziko-code|codemirror|
22
+ |ziko-lottie|lottie-web|
23
+
24
+ ```js
25
+ console.log({a:1})
26
+ fuction B(){
27
+ return [
28
+ 1,
29
+ 2
30
+ ]
31
+ }
32
+ ```
58
33
 
59
- www.koora.com
34
+ ```py
35
+ print(10)
36
+ A=[1,2,3]
37
+ ```
@@ -1,6 +1,6 @@
1
1
  import { defineConfig } from "vite";
2
2
  // import { MDZ } from "../src/vite/index.js";
3
- import { ViteMDZ } from "../v2/transformers/vite/index.js"
3
+ import ViteMDZ from "../src/bundlers/vite.js"
4
4
  export default defineConfig({
5
5
  plugins : [ViteMDZ()]
6
6
  })
@@ -0,0 +1,15 @@
1
+ import { transpileMDZ } from "../transpiler/index.js";
2
+ export default function ViteMDZ({extensions = [".mdx"]}={}){
3
+ return {
4
+ name: 'MDZ',
5
+ transform(src, id) {
6
+ if (id.endsWith('.mdz')||extensions.some(ext=>id.endsWith(ext))) {
7
+ return {
8
+ code: transpileMDZ(src),
9
+ map: null,
10
+ };
11
+ }
12
+ },
13
+ };
14
+ }
15
+
package/src/example.md ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+ title : hello
3
+ ---
package/src/index.js CHANGED
@@ -1,2 +1 @@
1
- export {parseMDZ} from "./parser/index.js"
2
- export {MDZ} from "./vite/index.js"
1
+ export * from "./transpiler/index.js"
package/src/test.js CHANGED
@@ -1,21 +1,49 @@
1
- import { getZikoScript } from "./converter/index.js";
2
- const markdownContent = `
3
- ---
4
- modules:
5
- - import Component from "./Component"
6
- - import OtherComponent from "./OtherComponent"
7
- - import OtherComonenetWithProps from "./OtherComonenetWithProps"
8
- title: MDZ
1
+ // import { cleanMD } from "./pre-parse/clean-md.js";
2
+ import { parseMDZ, transpileMDZ } from "./transpiler/index.js";
3
+ import { parseYml } from "./utils/parse-yml.js";
4
+
5
+ const md = `---
6
+ title : get started
7
+ id : 1
8
+ __props__ :
9
+ color : red
10
+ size : 10
9
11
  ---
10
- Para
11
- [Link](#hi)
12
12
 
13
- <Component />
13
+ <script>
14
+ console.log(1)
15
+ console.log(2)
16
+
17
+ console.log(3)
18
+ </script>
19
+
20
+ import A from "./A"
21
+ export const b = 10;
22
+
23
+ Hello {name} mm {m} [mmmm](kkk)
24
+
25
+ <B exp={1+1} str="kk">
26
+ # hi
27
+ # hi
28
+ </B>
29
+
30
+ # Hi
31
+ ## HI {Ziko}
32
+
33
+
34
+ |A|B|
35
+ |-|-|
36
+
37
+ `
14
38
 
15
- line2
39
+ // const md = `---
40
+ // title : Hi
41
+ // ---
42
+ // `
43
+ const ast = parseMDZ(md)
44
+ // console.log(ast.children.at(-1))
45
+ const js = transpileMDZ(md)
46
+ console.log(js)
47
+ // console.log(JSON.stringify(ast, null, 2))
16
48
 
17
- <OtherComponent />
18
- <OtherComonenetWithProps data="hello" />
19
- `;
20
- const script = getZikoScript(markdownContent);
21
- console.log(script)
49
+ // parseYml('a : 1\n__props__ : \n d : 2\n e : 1')
@@ -0,0 +1,3 @@
1
+ export { parseMDZ } from "./parser.js";
2
+ export { processMDZAST } from "./process.js";
3
+ export { transpileMDZ } from "./transpile.js";
@@ -0,0 +1,14 @@
1
+ import { unified } from 'unified';
2
+ import remarkParse from 'remark-parse';
3
+ import remarkFrontmatter from 'remark-frontmatter';
4
+ import remarkGFM from "remark-gfm";
5
+ import remarkMdx from "remark-mdx"
6
+
7
+ const parseMDZ = (markdown) => unified()
8
+ .use(remarkParse)
9
+ .use(remarkGFM)
10
+ .use(remarkFrontmatter, ['yaml'])
11
+ .use(remarkMdx)
12
+ .parse(markdown)
13
+
14
+ export{parseMDZ}
@@ -0,0 +1,172 @@
1
+ import {
2
+ componentType,
3
+ processAttribute,
4
+ parseYml,
5
+ hyperscript
6
+ } from "../utils/index.js"
7
+ import hljs from "highlight.js"
8
+ const processMDZAST = (markdownAST) => {
9
+ const transformNode = (node) => {
10
+ switch(node.type){
11
+ case 'mdxjsEsm' : {
12
+ return {
13
+ type : "script",
14
+ value : node.value
15
+ }
16
+ }
17
+ case 'text' : {
18
+ const text = node.value;
19
+ return `"${text}"`
20
+ }
21
+ case 'mdxTextExpression' : {
22
+ const {value} = node
23
+ return value
24
+ }
25
+ case 'heading' : {
26
+ const childNodes = node.children.map(transformNode).join(', ');
27
+ return hyperscript(`h${node.depth}`,"{}", childNodes);
28
+ // return `h('h${node.depth}', {}, ${childNodes})`;
29
+ }
30
+ case 'paragraph' : {
31
+ const childNodes = node.children.map(transformNode).join(', ');
32
+ return hyperscript("p","{}", childNodes)
33
+ // return `h('p', {}, ${childNodes})`
34
+ }
35
+ case 'strong': {
36
+ const childNodes = node.children.map(transformNode).join(', ');
37
+ return hyperscript("strong","{}", childNodes);
38
+ // return `h('strong', {}, ${childNodes})`;
39
+ }
40
+
41
+ case 'emphasis': {
42
+ const childNodes = node.children.map(transformNode).join(', ');
43
+ return hyperscript("emphasis","{}", childNodes);
44
+ // return `h('em', {}, ${childNodes})`;
45
+ }
46
+
47
+ case 'link': {
48
+ const childNodes = node.children.map(transformNode).join(', ');
49
+ return hyperscript("a", `{ href: "${node.url}" }`, childNodes);
50
+ }
51
+
52
+ case 'image': {
53
+ hyperscript("img", `{ src: "${node.url}", alt: "${node.alt || ''}`)
54
+ return `h('img', { src: "${node.url}", alt: "${node.alt || ''}" })`;
55
+ }
56
+
57
+ case 'list': {
58
+ const listTag = node.ordered ? 'ol' : 'ul';
59
+ const childNodes = node.children.map(transformNode).join(', ');
60
+ return hyperscript(listTag, "{}", childNodes);
61
+ // return `h('${listTag}', {}, ${childNodes})`;
62
+ }
63
+
64
+ case 'listItem': {
65
+ const childNodes = node.children.map(transformNode).join(', ');
66
+ return hyperscript("li", "{}", childNodes);
67
+ // return `h('li', {}, ${childNodes})`;
68
+ }
69
+
70
+ case 'code': {
71
+ const language = node.lang ? `{ 'data-lang': '${node.lang}' }` : '';
72
+ const highlightedCode = hljs.highlightAuto(node.value, [node.lang || '']).value;
73
+ hljs
74
+ const formatedCode = highlightedCode.replace(/(\r\n|\n|\r)/g, "<br>")
75
+ const out = hyperscript("pre", "{}", hyperscript(
76
+ "code",
77
+ language,
78
+ JSON.stringify(node.value)
79
+ ));
80
+ return `HTMLWrapper('<pre>${formatedCode}</pre>')`
81
+ // return out
82
+ }
83
+
84
+ case 'blockquote': {
85
+ const childNodes = node.children.map(transformNode).join(', ');
86
+ return hyperscript("blockquote", "{}", childNodes);
87
+ }
88
+ case 'thematicBreak': {
89
+ return `h('hr', {})`;
90
+ }
91
+ case 'table': {
92
+ const headerRows = node.children[0].children.map(transformNode).join(', ');
93
+ const bodyRows = node.children.slice(1).map(transformNode).join(', ');
94
+ const thead = hyperscript("thead", "{}", hyperscript("tr", "{}", headerRows));
95
+ const tbody = hyperscript("tbody", "{}", bodyRows);
96
+ return hyperscript("table", "{}", [thead, tbody].join(","))
97
+ // console.log({thead, tbody})
98
+ // const thead = `h('thead', {}, h('tr', {}, ${headerRows})`;
99
+ // const tbody = `h('tbody', {}, ${bodyRows})`
100
+ // return `h('table', {}, ${thead}), ${tbody}).style({border : "1px solid darkblue", borderCollapse: "collapse"}`;
101
+ }
102
+ case 'tableRow': {
103
+ const cells = node.children.map(transformNode).join(', ');
104
+ return `${hyperscript("tr", "{}", cells)}.style({border : "1px solid darkblue", borderCollapse: "collapse"})`
105
+ // return `h('tr', {}, ${cells}).style({border : "1px solid darkblue", borderCollapse: "collapse"})`;
106
+ }
107
+ case 'tableCell': {
108
+ const childNodes = node.children.map(transformNode).join(', ');
109
+ return `${hyperscript("td", "{}", childNodes)}.style({border : "1px solid darkblue", borderCollapse: "collapse", padding : "5px"})`
110
+ // return `h('td', {}, ${childNodes}).style({border : "1px solid darkblue", borderCollapse: "collapse", padding : "5px"})`;
111
+ }
112
+ case 'yaml':{
113
+ const {props, attrs} = parseYml(node.value)
114
+ return {
115
+ type : "yaml",
116
+ props,
117
+ attrs
118
+ }
119
+ }
120
+ case 'mdxJsxFlowElement':{
121
+ const {name, attributes, children} = node;
122
+ const childNodes = children.map(transformNode).join(', ');
123
+ const hasChildren = childNodes.length > 0;
124
+ console.log({name})
125
+ console.log(componentType(name))
126
+ switch(componentType(name)){
127
+ case "jsx" : return `${name}(${processAttribute(attributes)}${hasChildren ?`, ${childNodes}`:""})`;
128
+ case "html" : return `h("${name}", ${processAttribute(attributes)}${hasChildren ?`, ${childNodes}`:""})`;
129
+ case "script" : {
130
+ const statements = [];
131
+ for(let i=0; i<node.children.length; i++) statements.push(node.children[i].children[0].value)
132
+ return {
133
+ type : "script",
134
+ isScript : true,
135
+ value : statements.join("\n")
136
+ }
137
+ }
138
+ }
139
+ }
140
+ }
141
+ return 'null';
142
+ };
143
+ let esm = [];
144
+ let props = "";
145
+ let attrs = "";
146
+
147
+ const statements = []
148
+ markdownAST.children.forEach((node) => {
149
+ switch(node.type){
150
+ case 'yaml' : {
151
+ const Transformed = transformNode(node)
152
+ props = Transformed.props,
153
+ attrs = Transformed.attrs
154
+ } break;
155
+ case 'mdxjsEsm' : esm.push(node.value); break;
156
+ default : {
157
+ const Transformed = transformNode(node);
158
+ if(Transformed.isScript) statements.push(Transformed.value);
159
+ else statements.push(`__items__.push(${Transformed})`)
160
+ }
161
+ }
162
+ });
163
+ return {
164
+ attrs,
165
+ props,
166
+ esm,
167
+ statements
168
+ }
169
+ };
170
+ export {
171
+ processMDZAST
172
+ }
@@ -0,0 +1,22 @@
1
+ import { parseMDZ } from "./parser.js";
2
+ import { processMDZAST } from "./process.js";
3
+
4
+ const transpileMDZ=(Markdown)=>{
5
+ const ast = parseMDZ(Markdown);
6
+ const {attrs, props, esm, statements}= processMDZAST(ast)
7
+ console.log({props})
8
+ const body = [
9
+ 'import {h, HTMLWrapper, Flex} from "ziko"',
10
+ attrs,
11
+ ...esm,
12
+ `export default (${props})=>{`,
13
+ 'const __items__ = []',
14
+ ...statements,
15
+ "const UI = Flex(...__items__).vertical(0, 0)",
16
+ "return UI }"
17
+ ]
18
+ return body.join("\n");
19
+ }
20
+ export{
21
+ transpileMDZ
22
+ }
@@ -0,0 +1,5 @@
1
+ export const componentType = tag => {
2
+ if(tag === "script") return "script";
3
+ if(tag.toLowerCase() !== tag || tag.includes(".")) return "jsx";
4
+ return "html"
5
+ }
@@ -0,0 +1,4 @@
1
+ export const hyperscript = (tag, attrs, children="") => {
2
+ const HasChildren = !!children;
3
+ return `h("${tag}", ${attrs}${HasChildren ?`, ${children}` : ""})`
4
+ }
@@ -0,0 +1,4 @@
1
+ export { componentType } from "./component-type.js";
2
+ export { processAttribute } from "./process-attributes.js";
3
+ export { parseYml } from "./parse-yml.js";
4
+ export { hyperscript } from "./hyperscript.js"
@@ -0,0 +1,19 @@
1
+ import { parse } from 'yaml';
2
+
3
+ const parseYml = yml => {
4
+ const {__props__, ...__attrs__} = parse(yml) ;
5
+ const HasAttributs = Object.keys(__attrs__).length > 0
6
+ return {
7
+ props : __props__
8
+ ?`{${Object.entries(__props__).map(([key, value]) => `${key} = ${JSON.stringify(value)}`).join(", ")}}={}`
9
+ :"",
10
+ attrs : HasAttributs
11
+ ?[
12
+ `const {${Object.keys(__attrs__).join(",")}} = ${JSON.stringify(__attrs__,"",2)}`,
13
+ `export {${Object.keys(__attrs__).join(", ")}}`
14
+ ].join("\n")
15
+ : ""
16
+ }
17
+ }
18
+
19
+ export {parseYml}
@@ -0,0 +1,13 @@
1
+ export const processAttribute = (attributes) =>{
2
+ if(attributes.length === 0) return "{}"
3
+ let attr = []
4
+ for(let i=0; i<attributes.length ; i++){
5
+ let {name, value} = attributes[i]
6
+ attr.push({
7
+ name,
8
+ value : typeof value === "string" ? value : value.value,
9
+ isExpression : typeof value !== "string"
10
+ })
11
+ }
12
+ return `{${attr.map(({name, value, isExpression})=>`${name}:${isExpression ? value : `"${value}"`}`).join(", ")}}`
13
+ }
@@ -1,93 +0,0 @@
1
- function cleanMD(str) {
2
- const result = [];
3
- let currentExpr = '';
4
- let currentText = '';
5
- let braceCount = 0;
6
- for (let i = 0; i < str.length; i++) {
7
- const char = str[i];
8
- if (char === '{') {
9
- if (braceCount === 0 && currentText) {
10
- result.push(currentText.trim());
11
- currentText = '';
12
- }
13
- braceCount++;
14
- currentExpr += char;
15
- } else if (char === '}') {
16
- braceCount--;
17
- currentExpr += char;
18
- if (braceCount === 0) {
19
- result.push(cleanExpression(currentExpr));
20
- currentExpr = '';
21
- }
22
- } else {
23
- if (braceCount === 0) {
24
- currentText += char;
25
- } else {
26
- currentExpr += char;
27
- }
28
- }
29
- }
30
- if (currentText) {
31
- result.push(currentText.trim());
32
- }
33
-
34
- return result.join('');
35
- }
36
-
37
- function cleanExpression(block) {
38
- const content = block.slice(1, -1);
39
- const cleanedContent = content
40
- .split('\n')
41
- .map(line => line.trim())
42
- .filter(line => line)
43
- .join('\n');
44
- return `{\n${cleanedContent}\n}`;
45
- }
46
-
47
- // const text = `
48
- // const obj = {
49
-
50
- // key1: 'value1',
51
-
52
-
53
- // key2: 'value2',
54
-
55
-
56
- // key3: {
57
- // nestedKey1: 'nestedValue1',
58
-
59
-
60
- // nestedKey2: 'nestedValue2',
61
-
62
-
63
- // nestedKey3: {
64
-
65
- // deepKey: 'deepValue'
66
-
67
- // }
68
-
69
- // }
70
-
71
-
72
- // };
73
-
74
- // export default {
75
-
76
-
77
- // keyA: 'valueA',
78
-
79
-
80
- // keyB: {
81
-
82
- // nestedKey: 'nestedValue'
83
-
84
- // }
85
-
86
- // };
87
- // `;
88
-
89
- // console.log(cleanMD(text));
90
-
91
- export{
92
- cleanMD
93
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes