@yanqirenshi/model.pad 0.0.0-stage → 0.2.0

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/dist/ids.js ADDED
@@ -0,0 +1,34 @@
1
+ // ノードの配列に id を付ける(dhnDocumentToPadNodes と padTreeToPadNodes が使う。#307)。
2
+ //
3
+ // 最上位の要素: `${_class}-${通し番号}`(これまでどおり。GROUP-1 など)。
4
+ // 入れ子の要素(rows・tasks[].rows・whens[].body の中): 親の id を前に付けた `${親の id}.${_class}-${通し番号}`
5
+ // (GROUP-1.PROCESS-0 など)。通し番号は、親ごとに、入れ子の要素を上から順に数える(PARALLEL の task・SELECTION の when を
6
+ // またいで数えるので、同じ親の中で重ならない)。同じ入力なら、同じ id。
7
+ // 元のノードが id を持っていても、上書きする(これまでの最上位の動きと同じ)。
8
+ //
9
+ // CALL の callee(呼び出し先のノードの配列)は、利用側が別に変換して渡すものなので、ここでは触らない
10
+ // (呼び出し先の id は、呼び出し先の中での通し番号のまま)。
11
+ // 型は、動きを変えずに通すことを優先してゆるくしている(any)。
12
+ /* eslint-disable @typescript-eslint/no-explicit-any */
13
+ /** node(id は、すでに決まっている)の入れ子の要素に、id を付けた複製を返す。 */
14
+ function withNestedIds(node) {
15
+ let n = 0; // 親ごとの通し番号
16
+ const idOf = (child) => `${node.id}.${child._class || 'PROCESS'}-${n++}`;
17
+ const next = (list) => list.map((child) => {
18
+ const c = { ...child, id: idOf(child) };
19
+ return withNestedIds(c);
20
+ });
21
+ const out = { ...node };
22
+ // rows → tasks[].rows → whens[].body の順に、同じ通し番号で数える
23
+ if (Array.isArray(node.rows))
24
+ out.rows = next(node.rows);
25
+ if (Array.isArray(node.tasks))
26
+ out.tasks = node.tasks.map((task) => (task && Array.isArray(task.rows) ? { ...task, rows: next(task.rows) } : task));
27
+ if (Array.isArray(node.whens))
28
+ out.whens = node.whens.map((when) => (when && Array.isArray(when.body) ? { ...when, body: next(when.body) } : when));
29
+ return out;
30
+ }
31
+ /** 最上位の配列に id を付け、入れ子の要素にも、親の id を前にした id を付ける。 */
32
+ export function assignIds(nodes) {
33
+ return nodes.map((node, i) => withNestedIds({ ...node, id: `${node._class}-${i}` }));
34
+ }
@@ -0,0 +1,6 @@
1
+ export type { PadNode } from './types.js';
2
+ export { parse_js_code } from './parsers/jsParser.js';
3
+ export { PAD_NODE_SCHEMA, SCHEMAS } from './schema.js';
4
+ export { dhnDocumentToPadNodes, type DhnToPadOptions, type WbsLink } from './dhn/dhnDocumentToPadNodes.js';
5
+ export { padTreeToPadNodes } from './pad/padTreeToPadNodes.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAeA,YAAY,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,KAAK,eAAe,EAAE,KAAK,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAC3G,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ // model.pad — d3.pad(PAD = Problem Analysis Diagram)の「図ごとの知識」。描画はしない(react / d3 に依存しない)。
2
+ //
3
+ // パーサ: parse_js_code(code)(acorn で JS を読み、PadNode の木を JSON の文字列で返す)
4
+ // 型: PadNode(sequence / block / if / loop / command / error の 6 つ)
5
+ // スキーマ: SCHEMAS / PAD_NODE_SCHEMA(PadNode の木。JSON Schema 2020-12)
6
+ // PAD の変換: padTreeToPadNodes(PadNode の木を、d3.pad の Pad に渡す、汎用の要素のノードの配列にする。#302)
7
+ // .dhn の変換: dhnDocumentToPadNodes(dhn-parser の出力を、d3.pad の Pad に渡すノードの配列にする。#297。d3.pad.dhn から移した)
8
+ //
9
+ // d3.pad の src/parsers/jsParser.ts と src/types.ts を、動きを変えずに移した(#201)。d3.pad(0.2.0 から)は、ここから読んで再公開する。
10
+ // 描画は d3.pad(Pad)が担う。ここは、描く前のノードの配列までを作る(#302 で、d3.pad の古い描画 calculateLayout などは消えた)。
11
+ // ESM だけを出す。相対の import には .js を付けて、Node の ESM でもバンドラを通さずに読めるようにしている
12
+ // (d3 や React を入れずにパーサだけを使うためのパッケージなので)。
13
+ // parse_js_code の戻り値は、d3.pad 0.1.x と同じく JSON の文字列のまま(#201 の判断)。
14
+ // check・fieldsOf・applyPatch・movePatch は持たない。
15
+ export { parse_js_code } from './parsers/jsParser.js';
16
+ export { PAD_NODE_SCHEMA, SCHEMAS } from './schema.js';
17
+ export { dhnDocumentToPadNodes } from './dhn/dhnDocumentToPadNodes.js';
18
+ export { padTreeToPadNodes } from './pad/padTreeToPadNodes.js';
@@ -0,0 +1,8 @@
1
+ import type { PadNode } from '../types.js';
2
+ /**
3
+ * PadNode の木を、Pad に渡すノードの配列にする。開始・終了の TERMINAL は出さない。
4
+ * Pad は、center を付けずに作ると、関数(GROUP)どうしを縦線でつながない(全体の縦線は center: true のときだけ。#307)。
5
+ */
6
+ export declare function padTreeToPadNodes(tree: PadNode): any[];
7
+ export default padTreeToPadNodes;
8
+ //# sourceMappingURL=padTreeToPadNodes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"padTreeToPadNodes.d.ts","sourceRoot":"","sources":["../../src/pad/padTreeToPadNodes.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAgD3C;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,OAAO,GAAG,GAAG,EAAE,CAEtD;AAED,eAAe,iBAAiB,CAAC"}
@@ -0,0 +1,43 @@
1
+ import { assignIds } from '../ids.js';
2
+ /** if(else if の連なりも)を、1 つの SELECTION にする */
3
+ function selectionFrom(node) {
4
+ const whens = [];
5
+ let current = node;
6
+ while (current && current.type === 'if') {
7
+ whens.push({ condition: current.condition, body: convert(current.then_block) });
8
+ const next = current.else_block;
9
+ if (next && next.type !== 'if') {
10
+ whens.push({ else: true, body: convert(next) });
11
+ break;
12
+ }
13
+ current = next; // else if なら続ける。else が無ければ undefined で終わる
14
+ }
15
+ return { _class: 'SELECTION', whens };
16
+ }
17
+ /** 1 つの PadNode を、ノードの配列にする(sequence は、子を平らに並べるので、0 個以上になる) */
18
+ function convert(node) {
19
+ switch (node.type) {
20
+ case 'sequence':
21
+ return node.children.flatMap(convert);
22
+ case 'block':
23
+ return [{ _class: 'GROUP', label: node.label, rows: node.children.flatMap(convert) }];
24
+ case 'command':
25
+ return [{ _class: 'PROCESS', cells: [node.label], dividers: [] }];
26
+ case 'if':
27
+ return [selectionFrom(node)];
28
+ case 'loop':
29
+ return [{ _class: 'LOOP', condition: node.condition, test: 'pre', rows: convert(node.body) }];
30
+ case 'error':
31
+ return [{ _class: 'PROCESS', cells: ['error', node.message], dividers: ['dotted'] }];
32
+ default:
33
+ return []; // 知らない type(PadNode に無い)は、読み飛ばす
34
+ }
35
+ }
36
+ /**
37
+ * PadNode の木を、Pad に渡すノードの配列にする。開始・終了の TERMINAL は出さない。
38
+ * Pad は、center を付けずに作ると、関数(GROUP)どうしを縦線でつながない(全体の縦線は center: true のときだけ。#307)。
39
+ */
40
+ export function padTreeToPadNodes(tree) {
41
+ return assignIds(convert(tree));
42
+ }
43
+ export default padTreeToPadNodes;
@@ -0,0 +1,2 @@
1
+ export declare function parse_js_code(code: string): string;
2
+ //# sourceMappingURL=jsParser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsParser.d.ts","sourceRoot":"","sources":["../../src/parsers/jsParser.ts"],"names":[],"mappings":"AAGA,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGlD"}
@@ -0,0 +1,101 @@
1
+ import * as acorn from 'acorn';
2
+ export function parse_js_code(code) {
3
+ const parser = new JsParser(code);
4
+ return parser.parse();
5
+ }
6
+ class JsParser {
7
+ code;
8
+ constructor(code) {
9
+ this.code = code;
10
+ }
11
+ parse() {
12
+ try {
13
+ const ast = acorn.parse(this.code, { ecmaVersion: 2020 });
14
+ const nodes = [];
15
+ // @ts-ignore
16
+ for (const node of ast.body) {
17
+ if (node.type === 'FunctionDeclaration') {
18
+ nodes.push(this.parseFunction(node));
19
+ }
20
+ }
21
+ if (nodes.length === 0) {
22
+ return JSON.stringify({ type: 'error', message: 'No function found' });
23
+ }
24
+ return JSON.stringify({ type: 'sequence', children: nodes });
25
+ }
26
+ catch (e) {
27
+ return JSON.stringify({ type: 'error', message: `Parse error: ${e}` });
28
+ }
29
+ }
30
+ parseFunction(node) {
31
+ const name = node.id?.name || 'anonymous';
32
+ const body = this.parseBlock(node.body);
33
+ return {
34
+ type: 'block',
35
+ label: `fn ${name}()`, // Use 'fn' label to match Rust style or just 'function'
36
+ children: [body]
37
+ };
38
+ }
39
+ parseBlock(node) {
40
+ const children = [];
41
+ if (node.body) {
42
+ for (const stmt of node.body) {
43
+ children.push(this.parseStmt(stmt));
44
+ }
45
+ }
46
+ return { type: 'sequence', children };
47
+ }
48
+ parseStmt(stmt) {
49
+ switch (stmt.type) {
50
+ case 'VariableDeclaration':
51
+ return { type: 'command', label: this.snippet(stmt) };
52
+ case 'ExpressionStatement':
53
+ // Remove semicolon if present for cleaner display?
54
+ // Currently just taking snippet.
55
+ return { type: 'command', label: this.snippet(stmt) };
56
+ case 'IfStatement':
57
+ return this.parseIf(stmt);
58
+ case 'WhileStatement':
59
+ return {
60
+ type: 'loop',
61
+ condition: this.snippet(stmt.test),
62
+ body: this.parseStmt(stmt.body)
63
+ };
64
+ case 'ForStatement':
65
+ let condLabel = 'for (;;) ';
66
+ if (stmt.init || stmt.test || stmt.update) {
67
+ const init = stmt.init ? this.snippet(stmt.init) : '';
68
+ const test = stmt.test ? this.snippet(stmt.test) : '';
69
+ const update = stmt.update ? this.snippet(stmt.update) : '';
70
+ // Clean up init if it has semicolon?
71
+ // this.snippet(stmt.init) includes 'let i = 0', no semi usually if it's var decl node inside for
72
+ condLabel = `for (${init}; ${test}; ${update})`;
73
+ }
74
+ return {
75
+ type: 'loop',
76
+ condition: condLabel,
77
+ body: this.parseStmt(stmt.body)
78
+ };
79
+ case 'BlockStatement':
80
+ return this.parseBlock(stmt);
81
+ case 'ReturnStatement':
82
+ return { type: 'command', label: this.snippet(stmt) };
83
+ default:
84
+ return { type: 'command', label: this.snippet(stmt) };
85
+ }
86
+ }
87
+ parseIf(stmt) {
88
+ const condition = this.snippet(stmt.test);
89
+ const thenBlock = this.parseStmt(stmt.consequent);
90
+ const elseBlock = stmt.alternate ? this.parseStmt(stmt.alternate) : undefined;
91
+ return {
92
+ type: 'if',
93
+ condition,
94
+ then_block: thenBlock,
95
+ else_block: elseBlock
96
+ };
97
+ }
98
+ snippet(node) {
99
+ return this.code.substring(node.start, node.end);
100
+ }
101
+ }
@@ -0,0 +1,242 @@
1
+ export declare const PAD_NODE_SCHEMA: {
2
+ readonly $schema: "https://json-schema.org/draft/2020-12/schema";
3
+ readonly title: "PAD のノード(PadNode)";
4
+ readonly description: "parse_js_code が返す木。sequence(並び)・block(関数など、ラベル付きの並び)・if(条件と then / else)・loop(条件と本体)・command(1 文)・error(読めなかったとき)の 6 つ。";
5
+ readonly $ref: "#/$defs/node";
6
+ readonly $defs: {
7
+ readonly node: {
8
+ readonly oneOf: readonly [{
9
+ readonly $ref: "#/$defs/sequence";
10
+ }, {
11
+ readonly $ref: "#/$defs/block";
12
+ }, {
13
+ readonly $ref: "#/$defs/if";
14
+ }, {
15
+ readonly $ref: "#/$defs/loop";
16
+ }, {
17
+ readonly $ref: "#/$defs/command";
18
+ }, {
19
+ readonly $ref: "#/$defs/error";
20
+ }];
21
+ };
22
+ readonly sequence: {
23
+ readonly type: "object";
24
+ readonly properties: {
25
+ readonly type: {
26
+ readonly const: "sequence";
27
+ };
28
+ readonly children: {
29
+ readonly type: "array";
30
+ readonly items: {
31
+ readonly $ref: "#/$defs/node";
32
+ };
33
+ };
34
+ };
35
+ readonly required: readonly ["type", "children"];
36
+ readonly additionalProperties: true;
37
+ };
38
+ readonly block: {
39
+ readonly type: "object";
40
+ readonly properties: {
41
+ readonly type: {
42
+ readonly const: "block";
43
+ };
44
+ readonly label: {
45
+ readonly type: "string";
46
+ };
47
+ readonly children: {
48
+ readonly type: "array";
49
+ readonly items: {
50
+ readonly $ref: "#/$defs/node";
51
+ };
52
+ };
53
+ };
54
+ readonly required: readonly ["type", "label", "children"];
55
+ readonly additionalProperties: true;
56
+ };
57
+ readonly if: {
58
+ readonly type: "object";
59
+ readonly properties: {
60
+ readonly type: {
61
+ readonly const: "if";
62
+ };
63
+ readonly condition: {
64
+ readonly type: "string";
65
+ };
66
+ readonly then_block: {
67
+ readonly $ref: "#/$defs/node";
68
+ };
69
+ readonly else_block: {
70
+ readonly $ref: "#/$defs/node";
71
+ };
72
+ };
73
+ readonly required: readonly ["type", "condition", "then_block"];
74
+ readonly additionalProperties: true;
75
+ };
76
+ readonly loop: {
77
+ readonly type: "object";
78
+ readonly properties: {
79
+ readonly type: {
80
+ readonly const: "loop";
81
+ };
82
+ readonly condition: {
83
+ readonly type: "string";
84
+ };
85
+ readonly body: {
86
+ readonly $ref: "#/$defs/node";
87
+ };
88
+ };
89
+ readonly required: readonly ["type", "condition", "body"];
90
+ readonly additionalProperties: true;
91
+ };
92
+ readonly command: {
93
+ readonly type: "object";
94
+ readonly properties: {
95
+ readonly type: {
96
+ readonly const: "command";
97
+ };
98
+ readonly label: {
99
+ readonly type: "string";
100
+ };
101
+ };
102
+ readonly required: readonly ["type", "label"];
103
+ readonly additionalProperties: true;
104
+ };
105
+ readonly error: {
106
+ readonly type: "object";
107
+ readonly properties: {
108
+ readonly type: {
109
+ readonly const: "error";
110
+ };
111
+ readonly message: {
112
+ readonly type: "string";
113
+ };
114
+ };
115
+ readonly required: readonly ["type", "message"];
116
+ readonly additionalProperties: true;
117
+ };
118
+ };
119
+ };
120
+ /** 名前 → JSON Schema(PadNode は 1 つの木なので、コレクションではなく node の 1 つだけ) */
121
+ export declare const SCHEMAS: {
122
+ readonly node: {
123
+ readonly $schema: "https://json-schema.org/draft/2020-12/schema";
124
+ readonly title: "PAD のノード(PadNode)";
125
+ readonly description: "parse_js_code が返す木。sequence(並び)・block(関数など、ラベル付きの並び)・if(条件と then / else)・loop(条件と本体)・command(1 文)・error(読めなかったとき)の 6 つ。";
126
+ readonly $ref: "#/$defs/node";
127
+ readonly $defs: {
128
+ readonly node: {
129
+ readonly oneOf: readonly [{
130
+ readonly $ref: "#/$defs/sequence";
131
+ }, {
132
+ readonly $ref: "#/$defs/block";
133
+ }, {
134
+ readonly $ref: "#/$defs/if";
135
+ }, {
136
+ readonly $ref: "#/$defs/loop";
137
+ }, {
138
+ readonly $ref: "#/$defs/command";
139
+ }, {
140
+ readonly $ref: "#/$defs/error";
141
+ }];
142
+ };
143
+ readonly sequence: {
144
+ readonly type: "object";
145
+ readonly properties: {
146
+ readonly type: {
147
+ readonly const: "sequence";
148
+ };
149
+ readonly children: {
150
+ readonly type: "array";
151
+ readonly items: {
152
+ readonly $ref: "#/$defs/node";
153
+ };
154
+ };
155
+ };
156
+ readonly required: readonly ["type", "children"];
157
+ readonly additionalProperties: true;
158
+ };
159
+ readonly block: {
160
+ readonly type: "object";
161
+ readonly properties: {
162
+ readonly type: {
163
+ readonly const: "block";
164
+ };
165
+ readonly label: {
166
+ readonly type: "string";
167
+ };
168
+ readonly children: {
169
+ readonly type: "array";
170
+ readonly items: {
171
+ readonly $ref: "#/$defs/node";
172
+ };
173
+ };
174
+ };
175
+ readonly required: readonly ["type", "label", "children"];
176
+ readonly additionalProperties: true;
177
+ };
178
+ readonly if: {
179
+ readonly type: "object";
180
+ readonly properties: {
181
+ readonly type: {
182
+ readonly const: "if";
183
+ };
184
+ readonly condition: {
185
+ readonly type: "string";
186
+ };
187
+ readonly then_block: {
188
+ readonly $ref: "#/$defs/node";
189
+ };
190
+ readonly else_block: {
191
+ readonly $ref: "#/$defs/node";
192
+ };
193
+ };
194
+ readonly required: readonly ["type", "condition", "then_block"];
195
+ readonly additionalProperties: true;
196
+ };
197
+ readonly loop: {
198
+ readonly type: "object";
199
+ readonly properties: {
200
+ readonly type: {
201
+ readonly const: "loop";
202
+ };
203
+ readonly condition: {
204
+ readonly type: "string";
205
+ };
206
+ readonly body: {
207
+ readonly $ref: "#/$defs/node";
208
+ };
209
+ };
210
+ readonly required: readonly ["type", "condition", "body"];
211
+ readonly additionalProperties: true;
212
+ };
213
+ readonly command: {
214
+ readonly type: "object";
215
+ readonly properties: {
216
+ readonly type: {
217
+ readonly const: "command";
218
+ };
219
+ readonly label: {
220
+ readonly type: "string";
221
+ };
222
+ };
223
+ readonly required: readonly ["type", "label"];
224
+ readonly additionalProperties: true;
225
+ };
226
+ readonly error: {
227
+ readonly type: "object";
228
+ readonly properties: {
229
+ readonly type: {
230
+ readonly const: "error";
231
+ };
232
+ readonly message: {
233
+ readonly type: "string";
234
+ };
235
+ };
236
+ readonly required: readonly ["type", "message"];
237
+ readonly additionalProperties: true;
238
+ };
239
+ };
240
+ };
241
+ };
242
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2ElB,CAAC;AAEX,mEAAmE;AACnE,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAEV,CAAC"}
package/dist/schema.js ADDED
@@ -0,0 +1,86 @@
1
+ // PadNode(parse_js_code の戻り値を JSON.parse したもの)の JSON Schema(2020-12)。
2
+ // type で分かれる 6 つの形(sequence / block / if / loop / command / error)を $defs に書き、入れ子は $ref で読む。
3
+ //
4
+ // 項目は PadNode の型(src/types.ts)に合わせる。else_block だけが省ける(parse_js_code は else が無いと書かない)。
5
+ // 利用側の項目は、additionalProperties を閉じずに通す(ほかの model.* と同じ)。
6
+ const node = { $ref: '#/$defs/node' };
7
+ export const PAD_NODE_SCHEMA = {
8
+ $schema: 'https://json-schema.org/draft/2020-12/schema',
9
+ title: 'PAD のノード(PadNode)',
10
+ description: 'parse_js_code が返す木。sequence(並び)・block(関数など、ラベル付きの並び)・if(条件と then / else)・loop(条件と本体)・command(1 文)・error(読めなかったとき)の 6 つ。',
11
+ $ref: '#/$defs/node',
12
+ $defs: {
13
+ node: {
14
+ oneOf: [
15
+ { $ref: '#/$defs/sequence' },
16
+ { $ref: '#/$defs/block' },
17
+ { $ref: '#/$defs/if' },
18
+ { $ref: '#/$defs/loop' },
19
+ { $ref: '#/$defs/command' },
20
+ { $ref: '#/$defs/error' },
21
+ ],
22
+ },
23
+ sequence: {
24
+ type: 'object',
25
+ properties: {
26
+ type: { const: 'sequence' },
27
+ children: { type: 'array', items: node },
28
+ },
29
+ required: ['type', 'children'],
30
+ additionalProperties: true,
31
+ },
32
+ block: {
33
+ type: 'object',
34
+ properties: {
35
+ type: { const: 'block' },
36
+ label: { type: 'string' },
37
+ children: { type: 'array', items: node },
38
+ },
39
+ required: ['type', 'label', 'children'],
40
+ additionalProperties: true,
41
+ },
42
+ if: {
43
+ type: 'object',
44
+ properties: {
45
+ type: { const: 'if' },
46
+ condition: { type: 'string' },
47
+ then_block: node,
48
+ else_block: node,
49
+ },
50
+ required: ['type', 'condition', 'then_block'],
51
+ additionalProperties: true,
52
+ },
53
+ loop: {
54
+ type: 'object',
55
+ properties: {
56
+ type: { const: 'loop' },
57
+ condition: { type: 'string' },
58
+ body: node,
59
+ },
60
+ required: ['type', 'condition', 'body'],
61
+ additionalProperties: true,
62
+ },
63
+ command: {
64
+ type: 'object',
65
+ properties: {
66
+ type: { const: 'command' },
67
+ label: { type: 'string' },
68
+ },
69
+ required: ['type', 'label'],
70
+ additionalProperties: true,
71
+ },
72
+ error: {
73
+ type: 'object',
74
+ properties: {
75
+ type: { const: 'error' },
76
+ message: { type: 'string' },
77
+ },
78
+ required: ['type', 'message'],
79
+ additionalProperties: true,
80
+ },
81
+ },
82
+ };
83
+ /** 名前 → JSON Schema(PadNode は 1 つの木なので、コレクションではなく node の 1 つだけ) */
84
+ export const SCHEMAS = {
85
+ node: PAD_NODE_SCHEMA,
86
+ };
@@ -0,0 +1,24 @@
1
+ export type PadNode = {
2
+ type: 'sequence';
3
+ children: PadNode[];
4
+ } | {
5
+ type: 'block';
6
+ label: string;
7
+ children: PadNode[];
8
+ } | {
9
+ type: 'if';
10
+ condition: string;
11
+ then_block: PadNode;
12
+ else_block?: PadNode;
13
+ } | {
14
+ type: 'loop';
15
+ condition: string;
16
+ body: PadNode;
17
+ } | {
18
+ type: 'command';
19
+ label: string;
20
+ } | {
21
+ type: 'error';
22
+ message: string;
23
+ };
24
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GACb;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,EAAE,OAAO,EAAE,CAAA;CAAE,GACzC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,EAAE,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,OAAO,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAAE,GAC5E;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAClD;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,55 @@
1
1
  {
2
- "name": "@yanqirenshi/model.pad",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@yanqirenshi/model.pad",
3
+ "version": "0.2.0",
4
+ "description": "Diagram model for PAD (Problem Analysis Diagram, d3.pad) — JS code parser (acorn) into a PadNode tree, and its JSON Schema. ESM only, loadable by Node as is. No React / d3 dependency",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "src"
18
+ ],
19
+ "scripts": {
20
+ "prebuild": "node ../../scripts/clean-dist.cjs",
21
+ "build": "tsc",
22
+ "typecheck": "tsc --noEmit",
23
+ "test": "vitest run",
24
+ "prepublishOnly": "npm run build"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/Foolsgolds/Assholes.git",
29
+ "directory": "packages/model.pad"
30
+ },
31
+ "bugs": {
32
+ "url": "https://github.com/Foolsgolds/Assholes/issues"
33
+ },
34
+ "homepage": "https://github.com/Foolsgolds/Assholes/tree/main/packages/model.pad#readme",
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "dependencies": {
39
+ "acorn": "^8.15.0"
40
+ },
41
+ "devDependencies": {
42
+ "typescript": "~5.9.3",
43
+ "vitest": "^2.1.8"
44
+ },
45
+ "author": "yanqirenshi@gmail.com",
46
+ "keywords": [
47
+ "diagram",
48
+ "model",
49
+ "json-schema",
50
+ "d3.pad",
51
+ "pad",
52
+ "acorn"
53
+ ],
54
+ "license": "MIT"
55
+ }