@retikz/react 0.1.0-alpha.1 → 0.1.0-alpha.3
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/es/index.d.ts +5 -5
- package/dist/es/index.d.ts.map +1 -1
- package/dist/es/index.js +3 -1
- package/dist/es/kernel/Node.d.ts +59 -8
- package/dist/es/kernel/Node.d.ts.map +1 -1
- package/dist/es/kernel/Path.d.ts +12 -0
- package/dist/es/kernel/Path.d.ts.map +1 -1
- package/dist/es/kernel/Step.d.ts +86 -3
- package/dist/es/kernel/Step.d.ts.map +1 -1
- package/dist/es/kernel/Text.d.ts +31 -0
- package/dist/es/kernel/Text.d.ts.map +1 -0
- package/dist/es/kernel/Text.js +22 -0
- package/dist/es/kernel/_builder.d.ts.map +1 -1
- package/dist/es/kernel/_builder.js +215 -27
- package/dist/es/kernel/_displayNames.d.ts +4 -0
- package/dist/es/kernel/_displayNames.d.ts.map +1 -1
- package/dist/es/kernel/_displayNames.js +5 -1
- package/dist/es/kernel/_unbuilder.d.ts.map +1 -1
- package/dist/es/kernel/_unbuilder.js +78 -2
- package/dist/es/kernel/index.d.ts +1 -0
- package/dist/es/kernel/index.d.ts.map +1 -1
- package/dist/es/kernel/index.js +1 -0
- package/dist/es/render/renderPrim.d.ts.map +1 -1
- package/dist/es/render/renderPrim.js +31 -13
- package/dist/es/sugar/Draw.d.ts +20 -2
- package/dist/es/sugar/Draw.d.ts.map +1 -1
- package/dist/es/sugar/Draw.js +57 -3
- package/dist/es/sugar/EdgeLabel.d.ts +20 -0
- package/dist/es/sugar/EdgeLabel.d.ts.map +1 -0
- package/dist/es/sugar/EdgeLabel.js +13 -0
- package/dist/es/sugar/index.d.ts +1 -0
- package/dist/es/sugar/index.d.ts.map +1 -1
- package/dist/es/sugar/index.js +1 -0
- package/dist/lib/index.cjs +4 -0
- package/dist/lib/index.d.ts +5 -5
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/kernel/Node.d.ts +59 -8
- package/dist/lib/kernel/Node.d.ts.map +1 -1
- package/dist/lib/kernel/Path.d.ts +12 -0
- package/dist/lib/kernel/Path.d.ts.map +1 -1
- package/dist/lib/kernel/Step.d.ts +86 -3
- package/dist/lib/kernel/Step.d.ts.map +1 -1
- package/dist/lib/kernel/Text.cjs +22 -0
- package/dist/lib/kernel/Text.d.ts +31 -0
- package/dist/lib/kernel/Text.d.ts.map +1 -0
- package/dist/lib/kernel/_builder.cjs +214 -26
- package/dist/lib/kernel/_builder.d.ts.map +1 -1
- package/dist/lib/kernel/_displayNames.cjs +6 -0
- package/dist/lib/kernel/_displayNames.d.ts +4 -0
- package/dist/lib/kernel/_displayNames.d.ts.map +1 -1
- package/dist/lib/kernel/_unbuilder.cjs +78 -2
- package/dist/lib/kernel/_unbuilder.d.ts.map +1 -1
- package/dist/lib/kernel/index.cjs +1 -0
- package/dist/lib/kernel/index.d.ts +1 -0
- package/dist/lib/kernel/index.d.ts.map +1 -1
- package/dist/lib/render/renderPrim.cjs +31 -13
- package/dist/lib/render/renderPrim.d.ts.map +1 -1
- package/dist/lib/sugar/Draw.cjs +57 -3
- package/dist/lib/sugar/Draw.d.ts +20 -2
- package/dist/lib/sugar/Draw.d.ts.map +1 -1
- package/dist/lib/sugar/EdgeLabel.cjs +13 -0
- package/dist/lib/sugar/EdgeLabel.d.ts +20 -0
- package/dist/lib/sugar/EdgeLabel.d.ts.map +1 -0
- package/dist/lib/sugar/index.cjs +1 -0
- package/dist/lib/sugar/index.d.ts +1 -0
- package/dist/lib/sugar/index.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import { FC } from 'react';
|
|
2
|
-
import { IRTarget } from '@retikz/core';
|
|
1
|
+
import { FC, ReactNode } from 'react';
|
|
2
|
+
import { IRControlPoint, IRStepLabel, IRTarget } from '@retikz/core';
|
|
3
3
|
/**
|
|
4
4
|
* <Step> 组件的 props。
|
|
5
|
-
*
|
|
5
|
+
* alpha.3 起支持十种 kind:'move' / 'line' / 'step'(折角)/ 'cycle'(闭合)/
|
|
6
|
+
* 'curve'(二次贝塞尔)/ 'cubic'(三次贝塞尔)/ 'bend'(弧形简记)/
|
|
7
|
+
* 'arc'(圆弧段)/ 'circlePath'(整圆)/ 'ellipsePath'(整椭圆)。
|
|
6
8
|
* kind 默认 'line'。
|
|
9
|
+
*
|
|
10
|
+
* ADR-0004:除 'move' / 'cycle' 外的八种 kind 都可挂 `label?: IRStepLabel` 边标注;
|
|
11
|
+
* 等价的写法是用 sugar `<EdgeLabel>` 当 children。两者并存时 prop 优先。
|
|
7
12
|
*/
|
|
8
13
|
export type StepProps = {
|
|
9
14
|
/** 移动游标但不绘制(类似 SVG path "M") */
|
|
@@ -15,6 +20,10 @@ export type StepProps = {
|
|
|
15
20
|
kind?: 'line';
|
|
16
21
|
/** 直线终点 */
|
|
17
22
|
to: IRTarget;
|
|
23
|
+
/** 边标注(ADR-0004),等价于 <EdgeLabel> child */
|
|
24
|
+
label?: IRStepLabel;
|
|
25
|
+
/** sugar 形态:`<Step><EdgeLabel>...</EdgeLabel></Step>`;其它 children 静默忽略 */
|
|
26
|
+
children?: ReactNode;
|
|
18
27
|
} | {
|
|
19
28
|
/** 折角段:从游标经一个直角拐点到目标点(TikZ `-|` / `|-`) */
|
|
20
29
|
kind: 'step';
|
|
@@ -22,9 +31,83 @@ export type StepProps = {
|
|
|
22
31
|
via: '-|' | '|-';
|
|
23
32
|
/** 折角终点 */
|
|
24
33
|
to: IRTarget;
|
|
34
|
+
/** 边标注(ADR-0004) */
|
|
35
|
+
label?: IRStepLabel;
|
|
36
|
+
/** sugar 形态 */
|
|
37
|
+
children?: ReactNode;
|
|
25
38
|
} | {
|
|
26
39
|
/** 闭合:把当前子路径回到最近一个 move 起点(TikZ `cycle` / SVG `Z`) */
|
|
27
40
|
kind: 'cycle';
|
|
41
|
+
} | {
|
|
42
|
+
/** 二次贝塞尔:一个控制点(TikZ `.. controls (B) ..`) */
|
|
43
|
+
kind: 'curve';
|
|
44
|
+
/** 控制点(alpha.3 仅支持 [x, y],未来可能扩展) */
|
|
45
|
+
control: IRControlPoint;
|
|
46
|
+
/** 曲线终点 */
|
|
47
|
+
to: IRTarget;
|
|
48
|
+
/** 边标注(ADR-0004) */
|
|
49
|
+
label?: IRStepLabel;
|
|
50
|
+
/** sugar 形态 */
|
|
51
|
+
children?: ReactNode;
|
|
52
|
+
} | {
|
|
53
|
+
/** 三次贝塞尔:两个控制点(TikZ `.. controls (B) and (C) ..`) */
|
|
54
|
+
kind: 'cubic';
|
|
55
|
+
/** 第一控制点(影响起点切线) */
|
|
56
|
+
control1: IRControlPoint;
|
|
57
|
+
/** 第二控制点(影响终点切线) */
|
|
58
|
+
control2: IRControlPoint;
|
|
59
|
+
/** 曲线终点 */
|
|
60
|
+
to: IRTarget;
|
|
61
|
+
/** 边标注(ADR-0004) */
|
|
62
|
+
label?: IRStepLabel;
|
|
63
|
+
/** sugar 形态 */
|
|
64
|
+
children?: ReactNode;
|
|
65
|
+
} | {
|
|
66
|
+
/** 弧形简记:按方向 + 角度生成 cubic(TikZ `to[bend left=N]` / `to[bend right=N]`) */
|
|
67
|
+
kind: 'bend';
|
|
68
|
+
/** 弯向:'left' / 'right'(视觉左右,相对 from→to) */
|
|
69
|
+
bendDirection: 'left' | 'right';
|
|
70
|
+
/** 弯角度(度),缺省 30 */
|
|
71
|
+
bendAngle?: number;
|
|
72
|
+
/** 终点 */
|
|
73
|
+
to: IRTarget;
|
|
74
|
+
/** 边标注(ADR-0004) */
|
|
75
|
+
label?: IRStepLabel;
|
|
76
|
+
/** sugar 形态 */
|
|
77
|
+
children?: ReactNode;
|
|
78
|
+
} | {
|
|
79
|
+
/** 弧段:以游标为圆心,按起末角度 + 半径绘制(TikZ `arc[start angle=…, end angle=…, radius=…]`) */
|
|
80
|
+
kind: 'arc';
|
|
81
|
+
/** 弧的起始角度(度),CCW from +x(注意 retikz polar y 轴向下,角度 90 视觉朝下) */
|
|
82
|
+
startAngle: number;
|
|
83
|
+
/** 弧的终止角度(度) */
|
|
84
|
+
endAngle: number;
|
|
85
|
+
/** 弧的半径 */
|
|
86
|
+
radius: number;
|
|
87
|
+
/** 边标注(ADR-0004) */
|
|
88
|
+
label?: IRStepLabel;
|
|
89
|
+
/** sugar 形态 */
|
|
90
|
+
children?: ReactNode;
|
|
91
|
+
} | {
|
|
92
|
+
/** 整圆:以游标为圆心,按半径绘制;画完画笔留在圆心 */
|
|
93
|
+
kind: 'circlePath';
|
|
94
|
+
/** 圆的半径 */
|
|
95
|
+
radius: number;
|
|
96
|
+
/** 边标注(ADR-0004) */
|
|
97
|
+
label?: IRStepLabel;
|
|
98
|
+
/** sugar 形态 */
|
|
99
|
+
children?: ReactNode;
|
|
100
|
+
} | {
|
|
101
|
+
/** 整椭圆:以游标为圆心,按 x/y 轴半径绘制;画完画笔留在圆心 */
|
|
102
|
+
kind: 'ellipsePath';
|
|
103
|
+
/** 椭圆 x 轴半径 */
|
|
104
|
+
radiusX: number;
|
|
105
|
+
/** 椭圆 y 轴半径 */
|
|
106
|
+
radiusY: number;
|
|
107
|
+
/** 边标注(ADR-0004) */
|
|
108
|
+
label?: IRStepLabel;
|
|
109
|
+
/** sugar 形态 */
|
|
110
|
+
children?: ReactNode;
|
|
28
111
|
};
|
|
29
112
|
/**
|
|
30
113
|
* Step 是 DSL 标记组件——本身不渲染。
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Step.d.ts","sourceRoot":"","sources":["../../../src/kernel/Step.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"Step.d.ts","sourceRoot":"","sources":["../../../src/kernel/Step.tsx"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const require__displayNames = require("./_displayNames.cjs");
|
|
2
|
+
//#region src/kernel/Text.tsx
|
|
3
|
+
/**
|
|
4
|
+
* Text 是 Node 内的"行级"标记组件——本身不渲染,
|
|
5
|
+
* 由 buildIR 在扫描 Node children 时识别为 LineSpec。
|
|
6
|
+
*
|
|
7
|
+
* 和字符串 children 平等参与——String 按 `'\n'` 拆纯样式行;
|
|
8
|
+
* `<Text>` 一次贡献一行带样式行;保持 JSX 顺序。
|
|
9
|
+
*
|
|
10
|
+
* 用法:
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <Node>
|
|
13
|
+
* <Text fill="red" font={{ weight: 'bold' }}>Heading</Text>
|
|
14
|
+
* body line 1
|
|
15
|
+
* body line 2
|
|
16
|
+
* </Node>
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
var Text = () => null;
|
|
20
|
+
Text.displayName = require__displayNames.TIKZ_TEXT;
|
|
21
|
+
//#endregion
|
|
22
|
+
exports.Text = Text;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { IRFont } from '@retikz/core';
|
|
3
|
+
/** <Text> 组件的 props——Node 多行文本里给某一行带覆盖样式 */
|
|
4
|
+
export type TextProps = {
|
|
5
|
+
/** 行内容(必须是字符串) */
|
|
6
|
+
children: string;
|
|
7
|
+
/** 行级覆盖颜色;不填走 Node 块级默认 */
|
|
8
|
+
fill?: string;
|
|
9
|
+
/** 行级透明度 0~1;不填走 Node 块级默认 */
|
|
10
|
+
opacity?: number;
|
|
11
|
+
/** 行级字体覆盖;missing 字段继承 Node 的 `font` 块级值 */
|
|
12
|
+
font?: IRFont;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Text 是 Node 内的"行级"标记组件——本身不渲染,
|
|
16
|
+
* 由 buildIR 在扫描 Node children 时识别为 LineSpec。
|
|
17
|
+
*
|
|
18
|
+
* 和字符串 children 平等参与——String 按 `'\n'` 拆纯样式行;
|
|
19
|
+
* `<Text>` 一次贡献一行带样式行;保持 JSX 顺序。
|
|
20
|
+
*
|
|
21
|
+
* 用法:
|
|
22
|
+
* ```tsx
|
|
23
|
+
* <Node>
|
|
24
|
+
* <Text fill="red" font={{ weight: 'bold' }}>Heading</Text>
|
|
25
|
+
* body line 1
|
|
26
|
+
* body line 2
|
|
27
|
+
* </Node>
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare const Text: FC<TextProps>;
|
|
31
|
+
//# sourceMappingURL=Text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Text.d.ts","sourceRoot":"","sources":["../../../src/kernel/Text.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAG3C,4CAA4C;AAC5C,MAAM,MAAM,SAAS,GAAG;IACtB,kBAAkB;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,2BAA2B;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,8BAA8B;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,SAAS,CAAc,CAAC"}
|
|
@@ -8,25 +8,130 @@ var getDisplayName = (el) => {
|
|
|
8
8
|
if (typeof t === "string") return t;
|
|
9
9
|
return t.displayName;
|
|
10
10
|
};
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
/**
|
|
12
|
+
* 把 <Text> 元素的 props + children 串解析为 IRLineSpec 对象形式。
|
|
13
|
+
* children 必须是 string;非字符串 children 静默跳过此 <Text> 元素。
|
|
14
|
+
*/
|
|
15
|
+
var textElementToLineSpec = (el) => {
|
|
16
|
+
const props = el.props;
|
|
17
|
+
if (typeof props.children !== "string") return void 0;
|
|
18
|
+
if (props.fill === void 0 && props.opacity === void 0 && props.font === void 0) return props.children;
|
|
14
19
|
return {
|
|
15
|
-
|
|
16
|
-
id: props.id,
|
|
17
|
-
shape: props.shape,
|
|
18
|
-
position: props.position,
|
|
19
|
-
rotate: props.rotate,
|
|
20
|
-
text,
|
|
20
|
+
text: props.children,
|
|
21
21
|
fill: props.fill,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
padding: props.padding,
|
|
25
|
-
margin: props.margin,
|
|
26
|
-
fontSize: props.fontSize
|
|
22
|
+
opacity: props.opacity,
|
|
23
|
+
font: props.font
|
|
27
24
|
};
|
|
28
25
|
};
|
|
29
26
|
/**
|
|
27
|
+
* 递归收集 Node children 中的行:
|
|
28
|
+
* - 字符串按 `'\n'` 拆行(每段 → 字符串 LineSpec)
|
|
29
|
+
* - 数组(JSX 多 child 自动展平)逐项递归
|
|
30
|
+
* - <Text> 元素 → 对象 LineSpec(带覆盖样式)
|
|
31
|
+
* - 其它类型(其它 React 元素 / null / 数字等)忽略——附带让 `<br/>` 当软分段
|
|
32
|
+
*
|
|
33
|
+
* 顺序保留——按 JSX 写的顺序行就是 IR 行顺序。
|
|
34
|
+
*/
|
|
35
|
+
var collectChildLines = (children) => {
|
|
36
|
+
const out = [];
|
|
37
|
+
const visit = (node) => {
|
|
38
|
+
if (typeof node === "string") {
|
|
39
|
+
for (const part of node.split("\n")) out.push(part);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (Array.isArray(node)) {
|
|
43
|
+
for (const c of node) visit(c);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if ((0, react.isValidElement)(node) && getDisplayName(node) === "@retikz/Text") {
|
|
47
|
+
const spec = textElementToLineSpec(node);
|
|
48
|
+
if (spec !== void 0) out.push(spec);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
visit(children);
|
|
52
|
+
return out;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Node 文本读取顺序:
|
|
56
|
+
* 1. `props.text`(string / string[] / LineSpec[])— 显式优先,直接透传到 IR
|
|
57
|
+
* 2. `props.children` — 字符串按 `'\n'` 拆行;`<Text>` 元素带样式贡献一行;保持 JSX 顺序
|
|
58
|
+
*
|
|
59
|
+
* 用 children 写多行的几种姿势:
|
|
60
|
+
* - 字符串带换行:`<Node>{'Line 1\nLine 2'}</Node>`
|
|
61
|
+
* - 模板字面量:``<Node>{`Line 1\nLine 2`}</Node>``
|
|
62
|
+
* - 数组:`<Node>{['Line 1', 'Line 2']}</Node>`
|
|
63
|
+
* - <Text>(带样式):`<Node><Text fill="red">Heading</Text>body</Node>`
|
|
64
|
+
*/
|
|
65
|
+
var readNodeText = (props) => {
|
|
66
|
+
if (typeof props.text === "string") return props.text;
|
|
67
|
+
if (Array.isArray(props.text)) return props.text;
|
|
68
|
+
const lines = collectChildLines(props.children);
|
|
69
|
+
if (lines.length === 0) return void 0;
|
|
70
|
+
if (lines.length === 1 && typeof lines[0] === "string") return lines[0];
|
|
71
|
+
return lines;
|
|
72
|
+
};
|
|
73
|
+
/** 把 <Node> props 翻成 IRChild;text 优先取 props.text,其次取字符串 children */
|
|
74
|
+
var buildNode = (props) => ({
|
|
75
|
+
type: "node",
|
|
76
|
+
id: props.id,
|
|
77
|
+
shape: props.shape,
|
|
78
|
+
position: props.position,
|
|
79
|
+
rotate: props.rotate,
|
|
80
|
+
text: readNodeText(props),
|
|
81
|
+
align: props.align,
|
|
82
|
+
lineHeight: props.lineHeight,
|
|
83
|
+
fill: props.fill,
|
|
84
|
+
fillOpacity: props.fillOpacity,
|
|
85
|
+
stroke: props.stroke,
|
|
86
|
+
drawOpacity: props.drawOpacity,
|
|
87
|
+
strokeWidth: props.strokeWidth,
|
|
88
|
+
dashed: props.dashed,
|
|
89
|
+
dotted: props.dotted,
|
|
90
|
+
dashArray: props.dashArray,
|
|
91
|
+
roundedCorners: props.roundedCorners,
|
|
92
|
+
minimumWidth: props.minimumWidth,
|
|
93
|
+
minimumHeight: props.minimumHeight,
|
|
94
|
+
minimumSize: props.minimumSize,
|
|
95
|
+
scale: props.scale,
|
|
96
|
+
xScale: props.xScale,
|
|
97
|
+
yScale: props.yScale,
|
|
98
|
+
textColor: props.textColor,
|
|
99
|
+
opacity: props.opacity,
|
|
100
|
+
innerXSep: props.innerXSep,
|
|
101
|
+
innerYSep: props.innerYSep,
|
|
102
|
+
outerSep: props.outerSep,
|
|
103
|
+
padding: props.padding,
|
|
104
|
+
margin: props.margin,
|
|
105
|
+
font: props.font
|
|
106
|
+
});
|
|
107
|
+
/**
|
|
108
|
+
* 扫描 Step children,把首个 <EdgeLabel> 翻译为 IRStepLabel;
|
|
109
|
+
* 非字符串 children 静默跳过;多个 <EdgeLabel> 取首个。
|
|
110
|
+
*/
|
|
111
|
+
var readEdgeLabel = (children) => {
|
|
112
|
+
let result;
|
|
113
|
+
react.Children.forEach(children, (child) => {
|
|
114
|
+
if (result !== void 0) return;
|
|
115
|
+
if (!(0, react.isValidElement)(child)) return;
|
|
116
|
+
if (getDisplayName(child) !== "@retikz/EdgeLabel") return;
|
|
117
|
+
const props = child.props;
|
|
118
|
+
if (typeof props.children !== "string") return;
|
|
119
|
+
const out = { text: props.children };
|
|
120
|
+
if (props.position !== void 0) out.position = props.position;
|
|
121
|
+
if (props.side !== void 0) out.side = props.side;
|
|
122
|
+
result = out;
|
|
123
|
+
});
|
|
124
|
+
return result;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* 解析 Step 的 label 来源:prop `label` 优先于 sugar `<EdgeLabel>` child;
|
|
128
|
+
* 都缺省时返回 undefined。
|
|
129
|
+
*/
|
|
130
|
+
var resolveStepLabel = (props) => {
|
|
131
|
+
if (props.label !== void 0) return props.label;
|
|
132
|
+
return readEdgeLabel(props.children);
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
30
135
|
* 扫描 <Path> children 收集 <Step> 序列。
|
|
31
136
|
* 至少 2 段;首段不是 move 时强制改为 move(与 SVG path 的 "M …" 语义对齐);
|
|
32
137
|
* cycle 没有 to 字段,若用户把 cycle 放在首段,coerce 时降级到 move (0,0)。
|
|
@@ -45,32 +150,109 @@ var readPathChildren = (children) => {
|
|
|
45
150
|
});
|
|
46
151
|
return;
|
|
47
152
|
}
|
|
153
|
+
const label = kind === "move" ? void 0 : resolveStepLabel(props);
|
|
48
154
|
if (kind === "step") {
|
|
49
|
-
|
|
155
|
+
const step = {
|
|
50
156
|
type: "step",
|
|
51
157
|
kind: "step",
|
|
52
158
|
via: props.via,
|
|
53
|
-
to: props.to
|
|
159
|
+
to: (0, _retikz_core.parseTargetSugar)(props.to)
|
|
160
|
+
};
|
|
161
|
+
if (label) step.label = label;
|
|
162
|
+
out.push(step);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (kind === "curve") {
|
|
166
|
+
const step = {
|
|
167
|
+
type: "step",
|
|
168
|
+
kind: "curve",
|
|
169
|
+
to: (0, _retikz_core.parseTargetSugar)(props.to),
|
|
170
|
+
control: props.control
|
|
171
|
+
};
|
|
172
|
+
if (label) step.label = label;
|
|
173
|
+
out.push(step);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
if (kind === "cubic") {
|
|
177
|
+
const step = {
|
|
178
|
+
type: "step",
|
|
179
|
+
kind: "cubic",
|
|
180
|
+
to: (0, _retikz_core.parseTargetSugar)(props.to),
|
|
181
|
+
control1: props.control1,
|
|
182
|
+
control2: props.control2
|
|
183
|
+
};
|
|
184
|
+
if (label) step.label = label;
|
|
185
|
+
out.push(step);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (kind === "bend") {
|
|
189
|
+
const step = {
|
|
190
|
+
type: "step",
|
|
191
|
+
kind: "bend",
|
|
192
|
+
to: (0, _retikz_core.parseTargetSugar)(props.to),
|
|
193
|
+
bendDirection: props.bendDirection
|
|
194
|
+
};
|
|
195
|
+
if (props.bendAngle !== void 0) step.bendAngle = props.bendAngle;
|
|
196
|
+
if (label) step.label = label;
|
|
197
|
+
out.push(step);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if (kind === "arc") {
|
|
201
|
+
const step = {
|
|
202
|
+
type: "step",
|
|
203
|
+
kind: "arc",
|
|
204
|
+
startAngle: props.startAngle,
|
|
205
|
+
endAngle: props.endAngle,
|
|
206
|
+
radius: props.radius
|
|
207
|
+
};
|
|
208
|
+
if (label) step.label = label;
|
|
209
|
+
out.push(step);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if (kind === "circlePath") {
|
|
213
|
+
const step = {
|
|
214
|
+
type: "step",
|
|
215
|
+
kind: "circlePath",
|
|
216
|
+
radius: props.radius
|
|
217
|
+
};
|
|
218
|
+
if (label) step.label = label;
|
|
219
|
+
out.push(step);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (kind === "ellipsePath") {
|
|
223
|
+
const step = {
|
|
224
|
+
type: "step",
|
|
225
|
+
kind: "ellipsePath",
|
|
226
|
+
radiusX: props.radiusX,
|
|
227
|
+
radiusY: props.radiusY
|
|
228
|
+
};
|
|
229
|
+
if (label) step.label = label;
|
|
230
|
+
out.push(step);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
if (kind === "move") {
|
|
234
|
+
out.push({
|
|
235
|
+
type: "step",
|
|
236
|
+
kind: "move",
|
|
237
|
+
to: (0, _retikz_core.parseTargetSugar)(props.to)
|
|
54
238
|
});
|
|
55
239
|
return;
|
|
56
240
|
}
|
|
57
|
-
|
|
241
|
+
const step = {
|
|
58
242
|
type: "step",
|
|
59
|
-
kind,
|
|
60
|
-
to: props.to
|
|
61
|
-
}
|
|
243
|
+
kind: "line",
|
|
244
|
+
to: (0, _retikz_core.parseTargetSugar)(props.to)
|
|
245
|
+
};
|
|
246
|
+
if (label) step.label = label;
|
|
247
|
+
out.push(step);
|
|
62
248
|
});
|
|
63
249
|
if (out.length < 2) throw new Error("<Path> requires at least 2 <Step> children");
|
|
64
250
|
if (out[0].kind !== "move") {
|
|
65
251
|
const first = out[0];
|
|
66
|
-
out[0] =
|
|
67
|
-
type: "step",
|
|
68
|
-
kind: "move",
|
|
69
|
-
to: [0, 0]
|
|
70
|
-
} : {
|
|
252
|
+
out[0] = {
|
|
71
253
|
type: "step",
|
|
72
254
|
kind: "move",
|
|
73
|
-
to: first.to
|
|
255
|
+
to: first.kind === "cycle" || first.kind === "arc" || first.kind === "circlePath" || first.kind === "ellipsePath" ? [0, 0] : first.to
|
|
74
256
|
};
|
|
75
257
|
}
|
|
76
258
|
return out;
|
|
@@ -81,10 +263,16 @@ var buildPath = (props) => ({
|
|
|
81
263
|
stroke: props.stroke,
|
|
82
264
|
strokeWidth: props.strokeWidth,
|
|
83
265
|
strokeDasharray: props.strokeDasharray,
|
|
266
|
+
lineCap: props.lineCap,
|
|
267
|
+
lineJoin: props.lineJoin,
|
|
268
|
+
thickness: props.thickness,
|
|
84
269
|
arrow: props.arrow,
|
|
85
270
|
arrowShape: props.arrowShape,
|
|
86
271
|
fill: props.fill,
|
|
87
272
|
fillRule: props.fillRule,
|
|
273
|
+
opacity: props.opacity,
|
|
274
|
+
fillOpacity: props.fillOpacity,
|
|
275
|
+
drawOpacity: props.drawOpacity,
|
|
88
276
|
children: readPathChildren(props.children)
|
|
89
277
|
});
|
|
90
278
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_builder.d.ts","sourceRoot":"","sources":["../../../src/kernel/_builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,KAAK,SAAS,EAAkB,MAAM,OAAO,CAAC;AACpF,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"_builder.d.ts","sourceRoot":"","sources":["../../../src/kernel/_builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,KAAK,SAAS,EAAkB,MAAM,OAAO,CAAC;AACpF,OAAO,KAAK,EACV,EAAE,EAQH,MAAM,cAAc,CAAC;AAkXtB;;;GAGG;AACH,eAAO,MAAM,OAAO,GAAI,UAAU,SAAS,KAAG,EAI5C,CAAC"}
|
|
@@ -5,7 +5,13 @@ var TIKZ_NODE = "@retikz/Node";
|
|
|
5
5
|
var TIKZ_PATH = "@retikz/Path";
|
|
6
6
|
/** <Step> 组件的 displayName */
|
|
7
7
|
var TIKZ_STEP = "@retikz/Step";
|
|
8
|
+
/** <Text> 组件的 displayName(Node 内多行文本带样式) */
|
|
9
|
+
var TIKZ_TEXT = "@retikz/Text";
|
|
10
|
+
/** <EdgeLabel> 组件的 displayName(Step 内边标注,ADR-0004) */
|
|
11
|
+
var TIKZ_EDGE_LABEL = "@retikz/EdgeLabel";
|
|
8
12
|
//#endregion
|
|
13
|
+
exports.TIKZ_EDGE_LABEL = TIKZ_EDGE_LABEL;
|
|
9
14
|
exports.TIKZ_NODE = TIKZ_NODE;
|
|
10
15
|
exports.TIKZ_PATH = TIKZ_PATH;
|
|
11
16
|
exports.TIKZ_STEP = TIKZ_STEP;
|
|
17
|
+
exports.TIKZ_TEXT = TIKZ_TEXT;
|
|
@@ -4,4 +4,8 @@ export declare const TIKZ_NODE = "@retikz/Node";
|
|
|
4
4
|
export declare const TIKZ_PATH = "@retikz/Path";
|
|
5
5
|
/** <Step> 组件的 displayName */
|
|
6
6
|
export declare const TIKZ_STEP = "@retikz/Step";
|
|
7
|
+
/** <Text> 组件的 displayName(Node 内多行文本带样式) */
|
|
8
|
+
export declare const TIKZ_TEXT = "@retikz/Text";
|
|
9
|
+
/** <EdgeLabel> 组件的 displayName(Step 内边标注,ADR-0004) */
|
|
10
|
+
export declare const TIKZ_EDGE_LABEL = "@retikz/EdgeLabel";
|
|
7
11
|
//# sourceMappingURL=_displayNames.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_displayNames.d.ts","sourceRoot":"","sources":["../../../src/kernel/_displayNames.ts"],"names":[],"mappings":"AAKA,6BAA6B;AAC7B,eAAO,MAAM,SAAS,iBAAiB,CAAC;AAExC,6BAA6B;AAC7B,eAAO,MAAM,SAAS,iBAAiB,CAAC;AAExC,6BAA6B;AAC7B,eAAO,MAAM,SAAS,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"_displayNames.d.ts","sourceRoot":"","sources":["../../../src/kernel/_displayNames.ts"],"names":[],"mappings":"AAKA,6BAA6B;AAC7B,eAAO,MAAM,SAAS,iBAAiB,CAAC;AAExC,6BAA6B;AAC7B,eAAO,MAAM,SAAS,iBAAiB,CAAC;AAExC,6BAA6B;AAC7B,eAAO,MAAM,SAAS,iBAAiB,CAAC;AAExC,4CAA4C;AAC5C,eAAO,MAAM,SAAS,iBAAiB,CAAC;AAExC,sDAAsD;AACtD,eAAO,MAAM,eAAe,sBAAsB,CAAC"}
|
|
@@ -10,12 +10,31 @@ var nodePropsFromIR = (n) => {
|
|
|
10
10
|
if (n.shape !== void 0) props.shape = n.shape;
|
|
11
11
|
if (n.rotate !== void 0) props.rotate = n.rotate;
|
|
12
12
|
if (n.text !== void 0) props.text = n.text;
|
|
13
|
-
if (n.
|
|
13
|
+
if (n.align !== void 0) props.align = n.align;
|
|
14
|
+
if (n.lineHeight !== void 0) props.lineHeight = n.lineHeight;
|
|
15
|
+
if (n.font !== void 0) props.font = n.font;
|
|
16
|
+
if (n.innerXSep !== void 0) props.innerXSep = n.innerXSep;
|
|
17
|
+
if (n.innerYSep !== void 0) props.innerYSep = n.innerYSep;
|
|
18
|
+
if (n.outerSep !== void 0) props.outerSep = n.outerSep;
|
|
14
19
|
if (n.padding !== void 0) props.padding = n.padding;
|
|
15
20
|
if (n.margin !== void 0) props.margin = n.margin;
|
|
16
21
|
if (n.fill !== void 0) props.fill = n.fill;
|
|
22
|
+
if (n.fillOpacity !== void 0) props.fillOpacity = n.fillOpacity;
|
|
17
23
|
if (n.stroke !== void 0) props.stroke = n.stroke;
|
|
24
|
+
if (n.drawOpacity !== void 0) props.drawOpacity = n.drawOpacity;
|
|
18
25
|
if (n.strokeWidth !== void 0) props.strokeWidth = n.strokeWidth;
|
|
26
|
+
if (n.dashed !== void 0) props.dashed = n.dashed;
|
|
27
|
+
if (n.dotted !== void 0) props.dotted = n.dotted;
|
|
28
|
+
if (n.dashArray !== void 0) props.dashArray = n.dashArray;
|
|
29
|
+
if (n.roundedCorners !== void 0) props.roundedCorners = n.roundedCorners;
|
|
30
|
+
if (n.minimumWidth !== void 0) props.minimumWidth = n.minimumWidth;
|
|
31
|
+
if (n.minimumHeight !== void 0) props.minimumHeight = n.minimumHeight;
|
|
32
|
+
if (n.minimumSize !== void 0) props.minimumSize = n.minimumSize;
|
|
33
|
+
if (n.scale !== void 0) props.scale = n.scale;
|
|
34
|
+
if (n.xScale !== void 0) props.xScale = n.xScale;
|
|
35
|
+
if (n.yScale !== void 0) props.yScale = n.yScale;
|
|
36
|
+
if (n.textColor !== void 0) props.textColor = n.textColor;
|
|
37
|
+
if (n.opacity !== void 0) props.opacity = n.opacity;
|
|
19
38
|
return props;
|
|
20
39
|
};
|
|
21
40
|
/** 单个 IRStep → <Step /> element */
|
|
@@ -28,12 +47,63 @@ var stepToElement = (step, key) => {
|
|
|
28
47
|
key,
|
|
29
48
|
kind: "step",
|
|
30
49
|
via: step.via,
|
|
50
|
+
to: step.to,
|
|
51
|
+
...step.label !== void 0 && { label: step.label }
|
|
52
|
+
});
|
|
53
|
+
if (step.kind === "curve") return (0, react.createElement)(require_Step.Step, {
|
|
54
|
+
key,
|
|
55
|
+
kind: "curve",
|
|
56
|
+
to: step.to,
|
|
57
|
+
control: step.control,
|
|
58
|
+
...step.label !== void 0 && { label: step.label }
|
|
59
|
+
});
|
|
60
|
+
if (step.kind === "cubic") return (0, react.createElement)(require_Step.Step, {
|
|
61
|
+
key,
|
|
62
|
+
kind: "cubic",
|
|
63
|
+
to: step.to,
|
|
64
|
+
control1: step.control1,
|
|
65
|
+
control2: step.control2,
|
|
66
|
+
...step.label !== void 0 && { label: step.label }
|
|
67
|
+
});
|
|
68
|
+
if (step.kind === "bend") return (0, react.createElement)(require_Step.Step, {
|
|
69
|
+
key,
|
|
70
|
+
kind: "bend",
|
|
71
|
+
to: step.to,
|
|
72
|
+
bendDirection: step.bendDirection,
|
|
73
|
+
...step.bendAngle !== void 0 && { bendAngle: step.bendAngle },
|
|
74
|
+
...step.label !== void 0 && { label: step.label }
|
|
75
|
+
});
|
|
76
|
+
if (step.kind === "arc") return (0, react.createElement)(require_Step.Step, {
|
|
77
|
+
key,
|
|
78
|
+
kind: "arc",
|
|
79
|
+
startAngle: step.startAngle,
|
|
80
|
+
endAngle: step.endAngle,
|
|
81
|
+
radius: step.radius,
|
|
82
|
+
...step.label !== void 0 && { label: step.label }
|
|
83
|
+
});
|
|
84
|
+
if (step.kind === "circlePath") return (0, react.createElement)(require_Step.Step, {
|
|
85
|
+
key,
|
|
86
|
+
kind: "circlePath",
|
|
87
|
+
radius: step.radius,
|
|
88
|
+
...step.label !== void 0 && { label: step.label }
|
|
89
|
+
});
|
|
90
|
+
if (step.kind === "ellipsePath") return (0, react.createElement)(require_Step.Step, {
|
|
91
|
+
key,
|
|
92
|
+
kind: "ellipsePath",
|
|
93
|
+
radiusX: step.radiusX,
|
|
94
|
+
radiusY: step.radiusY,
|
|
95
|
+
...step.label !== void 0 && { label: step.label }
|
|
96
|
+
});
|
|
97
|
+
if (step.kind === "move") return (0, react.createElement)(require_Step.Step, {
|
|
98
|
+
key,
|
|
99
|
+
kind: "move",
|
|
31
100
|
to: step.to
|
|
32
101
|
});
|
|
33
102
|
return (0, react.createElement)(require_Step.Step, {
|
|
34
103
|
key,
|
|
35
104
|
kind: step.kind,
|
|
36
|
-
to: step.to
|
|
105
|
+
to: step.to,
|
|
106
|
+
...step.label !== void 0 && { label: step.label }
|
|
37
107
|
});
|
|
38
108
|
};
|
|
39
109
|
/** discriminated union 兜底:编译期保证不漏 case,运行时给出明确错误 */
|
|
@@ -52,10 +122,16 @@ var childToElement = (child, key) => {
|
|
|
52
122
|
stroke: child.stroke,
|
|
53
123
|
strokeWidth: child.strokeWidth,
|
|
54
124
|
strokeDasharray: child.strokeDasharray,
|
|
125
|
+
lineCap: child.lineCap,
|
|
126
|
+
lineJoin: child.lineJoin,
|
|
127
|
+
thickness: child.thickness,
|
|
55
128
|
arrow: child.arrow,
|
|
56
129
|
arrowShape: child.arrowShape,
|
|
57
130
|
fill: child.fill,
|
|
58
131
|
fillRule: child.fillRule,
|
|
132
|
+
opacity: child.opacity,
|
|
133
|
+
fillOpacity: child.fillOpacity,
|
|
134
|
+
drawOpacity: child.drawOpacity,
|
|
59
135
|
children: child.children.map((s, j) => stepToElement(s, j))
|
|
60
136
|
});
|
|
61
137
|
default: return assertNever(child);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_unbuilder.d.ts","sourceRoot":"","sources":["../../../src/kernel/_unbuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAiB,MAAM,OAAO,CAAC;AACtD,OAAO,KAAK,EAAE,EAAE,EAA2B,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"_unbuilder.d.ts","sourceRoot":"","sources":["../../../src/kernel/_unbuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAiB,MAAM,OAAO,CAAC;AACtD,OAAO,KAAK,EAAE,EAAE,EAA2B,MAAM,cAAc,CAAC;AA2JhE;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAAI,IAAI,EAAE,KAAG,SACW,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/kernel/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/kernel/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC"}
|