@yanqirenshi/d3.pad 0.1.2 → 0.2.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.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +8 -2
  3. package/dist/index.d.ts +5 -5
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +5 -5
  6. package/dist/renderers/D3PadRenderer.d.ts +1 -1
  7. package/dist/renderers/D3PadRenderer.d.ts.map +1 -1
  8. package/dist/renderers/D3PadRenderer.js +2 -2
  9. package/dist/renderers/PadNodeRenderer.d.ts +1 -1
  10. package/dist/renderers/PadNodeRenderer.d.ts.map +1 -1
  11. package/dist/renderers/PadNodeRenderer.js +6 -6
  12. package/dist/renderers/blocks/EndBlockGeometry.d.ts +1 -1
  13. package/dist/renderers/blocks/EndBlockGeometry.d.ts.map +1 -1
  14. package/dist/renderers/blocks/EndRenderer.js +1 -1
  15. package/dist/renderers/blocks/FunctionContainerGeometry.d.ts +1 -1
  16. package/dist/renderers/blocks/FunctionContainerGeometry.d.ts.map +1 -1
  17. package/dist/renderers/blocks/FunctionContainerRenderer.js +1 -1
  18. package/dist/renderers/blocks/FunctionHeaderGeometry.d.ts +1 -1
  19. package/dist/renderers/blocks/FunctionHeaderGeometry.d.ts.map +1 -1
  20. package/dist/renderers/blocks/FunctionHeaderRenderer.js +1 -1
  21. package/dist/renderers/blocks/IfBlockGeometry.d.ts +2 -2
  22. package/dist/renderers/blocks/IfBlockGeometry.d.ts.map +1 -1
  23. package/dist/renderers/blocks/IfRenderer.d.ts +1 -1
  24. package/dist/renderers/blocks/IfRenderer.d.ts.map +1 -1
  25. package/dist/renderers/blocks/IfRenderer.js +1 -1
  26. package/dist/renderers/blocks/IfRendererProps.d.ts +1 -1
  27. package/dist/renderers/blocks/IfRendererProps.d.ts.map +1 -1
  28. package/dist/renderers/blocks/StartBlockGeometry.d.ts +1 -1
  29. package/dist/renderers/blocks/StartBlockGeometry.d.ts.map +1 -1
  30. package/dist/renderers/blocks/StartRenderer.js +1 -1
  31. package/dist/utils/layout.d.ts +1 -1
  32. package/dist/utils/layout.d.ts.map +1 -1
  33. package/dist/utils/layout.js +2 -2
  34. package/package.json +16 -5
  35. package/src/index.ts +12 -12
  36. package/src/renderers/D3PadRenderer.tsx +145 -145
  37. package/src/renderers/PadNodeRenderer.ts +517 -517
  38. package/src/renderers/blocks/EndBlockGeometry.ts +52 -52
  39. package/src/renderers/blocks/EndRenderer.tsx +48 -48
  40. package/src/renderers/blocks/EndRendererProps.ts +5 -5
  41. package/src/renderers/blocks/FunctionContainerGeometry.ts +54 -54
  42. package/src/renderers/blocks/FunctionContainerRenderer.tsx +62 -62
  43. package/src/renderers/blocks/FunctionHeaderGeometry.ts +43 -43
  44. package/src/renderers/blocks/FunctionHeaderProps.ts +6 -6
  45. package/src/renderers/blocks/FunctionHeaderRenderer.tsx +47 -47
  46. package/src/renderers/blocks/IfBlockGeometry.ts +98 -98
  47. package/src/renderers/blocks/IfRenderer.tsx +88 -88
  48. package/src/renderers/blocks/IfRendererProps.ts +7 -7
  49. package/src/renderers/blocks/LoopRenderer.tsx +50 -50
  50. package/src/renderers/blocks/LoopRendererProps.ts +7 -7
  51. package/src/renderers/blocks/README.md +29 -29
  52. package/src/renderers/blocks/StartBlockGeometry.ts +66 -66
  53. package/src/renderers/blocks/StartRenderer.tsx +49 -49
  54. package/src/renderers/blocks/StartRendererProps.ts +5 -5
  55. package/src/utils/layout.ts +247 -247
  56. package/dist/parsers/jsParser.d.ts +0 -2
  57. package/dist/parsers/jsParser.d.ts.map +0 -1
  58. package/dist/parsers/jsParser.js +0 -101
  59. package/dist/types.d.ts +0 -24
  60. package/dist/types.d.ts.map +0 -1
  61. package/dist/types.js +0 -1
  62. package/src/parsers/jsParser.ts +0 -122
  63. package/src/types.ts +0 -7
@@ -1,122 +0,0 @@
1
- import * as acorn from 'acorn';
2
- import type { PadNode } from '../types';
3
-
4
- export function parse_js_code(code: string): string {
5
- const parser = new JsParser(code);
6
- return parser.parse();
7
- }
8
-
9
- class JsParser {
10
- private code: string;
11
-
12
- constructor(code: string) {
13
- this.code = code;
14
- }
15
-
16
- parse(): string {
17
- try {
18
- const ast = acorn.parse(this.code, { ecmaVersion: 2020 });
19
- const nodes: PadNode[] = [];
20
-
21
- // @ts-ignore
22
- for (const node of ast.body) {
23
- if (node.type === 'FunctionDeclaration') {
24
- nodes.push(this.parseFunction(node));
25
- }
26
- }
27
-
28
- if (nodes.length === 0) {
29
- return JSON.stringify({ type: 'error', message: 'No function found' });
30
- }
31
-
32
- return JSON.stringify({ type: 'sequence', children: nodes });
33
- } catch (e) {
34
- return JSON.stringify({ type: 'error', message: `Parse error: ${e}` });
35
- }
36
- }
37
-
38
- private parseFunction(node: any): PadNode {
39
- const name = node.id?.name || 'anonymous';
40
- const body = this.parseBlock(node.body);
41
- return {
42
- type: 'block',
43
- label: `fn ${name}()`, // Use 'fn' label to match Rust style or just 'function'
44
- children: [body]
45
- };
46
- }
47
-
48
- private parseBlock(node: any): PadNode {
49
- const children: PadNode[] = [];
50
- if (node.body) {
51
- for (const stmt of node.body) {
52
- children.push(this.parseStmt(stmt));
53
- }
54
- }
55
- return { type: 'sequence', children };
56
- }
57
-
58
- private parseStmt(stmt: any): PadNode {
59
- switch (stmt.type) {
60
- case 'VariableDeclaration':
61
- return { type: 'command', label: this.snippet(stmt) };
62
-
63
- case 'ExpressionStatement':
64
- // Remove semicolon if present for cleaner display?
65
- // Currently just taking snippet.
66
- return { type: 'command', label: this.snippet(stmt) };
67
-
68
- case 'IfStatement':
69
- return this.parseIf(stmt);
70
-
71
- case 'WhileStatement':
72
- return {
73
- type: 'loop',
74
- condition: this.snippet(stmt.test),
75
- body: this.parseStmt(stmt.body)
76
- };
77
-
78
- case 'ForStatement':
79
- let condLabel = 'for (;;) ';
80
- if (stmt.init || stmt.test || stmt.update) {
81
- const init = stmt.init ? this.snippet(stmt.init) : '';
82
- const test = stmt.test ? this.snippet(stmt.test) : '';
83
- const update = stmt.update ? this.snippet(stmt.update) : '';
84
- // Clean up init if it has semicolon?
85
- // this.snippet(stmt.init) includes 'let i = 0', no semi usually if it's var decl node inside for
86
- condLabel = `for (${init}; ${test}; ${update})`;
87
- }
88
-
89
- return {
90
- type: 'loop',
91
- condition: condLabel,
92
- body: this.parseStmt(stmt.body)
93
- };
94
-
95
- case 'BlockStatement':
96
- return this.parseBlock(stmt);
97
-
98
- case 'ReturnStatement':
99
- return { type: 'command', label: this.snippet(stmt) };
100
-
101
- default:
102
- return { type: 'command', label: this.snippet(stmt) };
103
- }
104
- }
105
-
106
- private parseIf(stmt: any): PadNode {
107
- const condition = this.snippet(stmt.test);
108
- const thenBlock = this.parseStmt(stmt.consequent);
109
- const elseBlock = stmt.alternate ? this.parseStmt(stmt.alternate) : undefined;
110
-
111
- return {
112
- type: 'if',
113
- condition,
114
- then_block: thenBlock,
115
- else_block: elseBlock
116
- };
117
- }
118
-
119
- private snippet(node: any): string {
120
- return this.code.substring(node.start, node.end);
121
- }
122
- }
package/src/types.ts DELETED
@@ -1,7 +0,0 @@
1
- export type PadNode =
2
- | { type: 'sequence'; children: PadNode[] }
3
- | { type: 'block'; label: string; children: PadNode[] }
4
- | { type: 'if'; condition: string; then_block: PadNode; else_block?: PadNode }
5
- | { type: 'loop'; condition: string; body: PadNode }
6
- | { type: 'command'; label: string }
7
- | { type: 'error'; message: string };