@retikz/react 0.1.0-alpha.0 → 0.1.0-alpha.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.
- package/dist/es/index.d.ts +2 -0
- package/dist/es/index.d.ts.map +1 -1
- package/dist/es/index.js +2 -1
- package/dist/es/kernel/Node.d.ts +2 -0
- package/dist/es/kernel/Node.d.ts.map +1 -1
- package/dist/es/kernel/Path.d.ts +14 -0
- package/dist/es/kernel/Path.d.ts.map +1 -1
- package/dist/es/kernel/Step.d.ts +12 -1
- package/dist/es/kernel/Step.d.ts.map +1 -1
- package/dist/es/kernel/Tikz.d.ts +5 -1
- package/dist/es/kernel/Tikz.d.ts.map +1 -1
- package/dist/es/kernel/Tikz.js +25 -5
- package/dist/es/kernel/_builder.d.ts.map +1 -1
- package/dist/es/kernel/_builder.js +35 -6
- package/dist/es/kernel/_unbuilder.d.ts.map +1 -1
- package/dist/es/kernel/_unbuilder.js +22 -5
- package/dist/es/render/arrowMarkers.d.ts +11 -0
- package/dist/es/render/arrowMarkers.d.ts.map +1 -0
- package/dist/es/render/arrowMarkers.js +81 -0
- package/dist/es/render/renderPrim.d.ts +11 -3
- package/dist/es/render/renderPrim.d.ts.map +1 -1
- package/dist/es/render/renderPrim.js +36 -13
- package/dist/es/sugar/Draw.d.ts +14 -1
- package/dist/es/sugar/Draw.d.ts.map +1 -1
- package/dist/es/sugar/Draw.js +21 -8
- package/dist/lib/index.cjs +7 -0
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/kernel/Node.d.ts +2 -0
- package/dist/lib/kernel/Node.d.ts.map +1 -1
- package/dist/lib/kernel/Path.d.ts +14 -0
- package/dist/lib/kernel/Path.d.ts.map +1 -1
- package/dist/lib/kernel/Step.d.ts +12 -1
- package/dist/lib/kernel/Step.d.ts.map +1 -1
- package/dist/lib/kernel/Tikz.cjs +23 -3
- package/dist/lib/kernel/Tikz.d.ts +5 -1
- package/dist/lib/kernel/Tikz.d.ts.map +1 -1
- package/dist/lib/kernel/_builder.cjs +35 -6
- package/dist/lib/kernel/_builder.d.ts.map +1 -1
- package/dist/lib/kernel/_unbuilder.cjs +22 -5
- package/dist/lib/kernel/_unbuilder.d.ts.map +1 -1
- package/dist/lib/render/arrowMarkers.cjs +81 -0
- package/dist/lib/render/arrowMarkers.d.ts +11 -0
- package/dist/lib/render/arrowMarkers.d.ts.map +1 -0
- package/dist/lib/render/renderPrim.cjs +36 -13
- package/dist/lib/render/renderPrim.d.ts +11 -3
- package/dist/lib/render/renderPrim.d.ts.map +1 -1
- package/dist/lib/sugar/Draw.cjs +21 -8
- package/dist/lib/sugar/Draw.d.ts +14 -1
- package/dist/lib/sugar/Draw.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/es/index.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ export { Tikz, Node, Path, Step } from './kernel';
|
|
|
10
10
|
export type { TikzProps, NodeProps, PathProps, StepProps } from './kernel';
|
|
11
11
|
export { Draw } from './sugar';
|
|
12
12
|
export type { DrawProps } from './sugar';
|
|
13
|
+
export { DrawWay } from '@retikz/core';
|
|
14
|
+
export type { WayItem, WayDSL, WayCycle, WayVia } from '@retikz/core';
|
|
13
15
|
export { buildIR as convertReactNodeToIR } from './kernel/_builder';
|
|
14
16
|
export { convertIRToReactNode } from './kernel/_unbuilder';
|
|
15
17
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/es/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAClD,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE3E,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGzC,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAClD,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE3E,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGzC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtE,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/es/index.js
CHANGED
|
@@ -7,4 +7,5 @@ import "./kernel/index.js";
|
|
|
7
7
|
import { Draw } from "./sugar/Draw.js";
|
|
8
8
|
import "./sugar/index.js";
|
|
9
9
|
import { convertIRToReactNode } from "./kernel/_unbuilder.js";
|
|
10
|
-
|
|
10
|
+
import { DrawWay } from "@retikz/core";
|
|
11
|
+
export { Draw, DrawWay, Node, Path, Step, Tikz, convertIRToReactNode, buildIR as convertReactNodeToIR };
|
package/dist/es/kernel/Node.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ import { IRNode, IRPosition, PolarPosition } from '@retikz/core';
|
|
|
4
4
|
export type NodeProps = {
|
|
5
5
|
/** 节点 id;其他 Path/Draw 通过这个 id 引用本节点 */
|
|
6
6
|
id?: string;
|
|
7
|
+
/** 节点形状:rectangle(默认)/ circle / ellipse / diamond */
|
|
8
|
+
shape?: IRNode['shape'];
|
|
7
9
|
/** 节点中心位置;笛卡尔 [x, y] 或极坐标(编译时解析) */
|
|
8
10
|
position: IRPosition | PolarPosition;
|
|
9
11
|
/** 旋转角度(度数,与 TikZ 一致),绕节点中心;正值顺时针 */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Node.d.ts","sourceRoot":"","sources":["../../../src/kernel/Node.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAGtE,uBAAuB;AACvB,MAAM,MAAM,SAAS,GAAG;IACtB,uCAAuC;IACvC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,oCAAoC;IACpC,QAAQ,EAAE,UAAU,GAAG,aAAa,CAAC;IACrC,qCAAqC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iCAAiC;IACjC,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,6BAA6B;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gBAAgB;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,yBAAyB;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oDAAoD;IACpD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU;IACV,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACtB,UAAU;IACV,MAAM,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC1B,WAAW;IACX,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,SAAS,CAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"Node.d.ts","sourceRoot":"","sources":["../../../src/kernel/Node.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAGtE,uBAAuB;AACvB,MAAM,MAAM,SAAS,GAAG;IACtB,uCAAuC;IACvC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,qDAAqD;IACrD,KAAK,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IACxB,oCAAoC;IACpC,QAAQ,EAAE,UAAU,GAAG,aAAa,CAAC;IACrC,qCAAqC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iCAAiC;IACjC,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,6BAA6B;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gBAAgB;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,yBAAyB;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oDAAoD;IACpD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU;IACV,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACtB,UAAU;IACV,MAAM,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC1B,WAAW;IACX,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,SAAS,CAAc,CAAC"}
|
package/dist/es/kernel/Path.d.ts
CHANGED
|
@@ -8,6 +8,20 @@ export type PathProps = {
|
|
|
8
8
|
strokeWidth?: IRPath['strokeWidth'];
|
|
9
9
|
/** SVG stroke-dasharray 模式(如 "4 2") */
|
|
10
10
|
strokeDasharray?: IRPath['strokeDasharray'];
|
|
11
|
+
/**
|
|
12
|
+
* 路径级箭头方向。`'->'` = 终点;`'<-'` = 起点;`'<->'` = 两端;
|
|
13
|
+
* 省略或 `'none'` = 无箭头。
|
|
14
|
+
*/
|
|
15
|
+
arrow?: IRPath['arrow'];
|
|
16
|
+
/**
|
|
17
|
+
* 箭头形状。默认 `'normal'`(实心三角)。其他:`'open'` 空心三角、
|
|
18
|
+
* `'stealth'` 倒钩、`'diamond'` 菱形、`'circle'` 圆点。
|
|
19
|
+
*/
|
|
20
|
+
arrowShape?: IRPath['arrowShape'];
|
|
21
|
+
/** 闭合区域填充色,CSS 颜色字符串;省略 = 不填充(仅描边)。配合 cycle step 画填充形状 */
|
|
22
|
+
fill?: IRPath['fill'];
|
|
23
|
+
/** SVG fill-rule:`'nonzero'`(默认)/ `'evenodd'`(环形 / 孔洞) */
|
|
24
|
+
fillRule?: IRPath['fillRule'];
|
|
11
25
|
/** 应当全部是 <Step /> */
|
|
12
26
|
children: ReactNode;
|
|
13
27
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Path.d.ts","sourceRoot":"","sources":["../../../src/kernel/Path.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAG3C,uBAAuB;AACvB,MAAM,MAAM,SAAS,GAAG;IACtB,4BAA4B;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC1B,kBAAkB;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;IACpC,uCAAuC;IACvC,eAAe,CAAC,EAAE,MAAM,CAAC,iBAAiB,CAAC,CAAC;IAC5C,qBAAqB;IACrB,QAAQ,EAAE,SAAS,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,SAAS,CAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"Path.d.ts","sourceRoot":"","sources":["../../../src/kernel/Path.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAG3C,uBAAuB;AACvB,MAAM,MAAM,SAAS,GAAG;IACtB,4BAA4B;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC1B,kBAAkB;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;IACpC,uCAAuC;IACvC,eAAe,CAAC,EAAE,MAAM,CAAC,iBAAiB,CAAC,CAAC;IAC5C;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IACxB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;IAClC,0DAA0D;IAC1D,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACtB,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;IAC9B,qBAAqB;IACrB,QAAQ,EAAE,SAAS,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,SAAS,CAAc,CAAC"}
|
package/dist/es/kernel/Step.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { FC } from 'react';
|
|
|
2
2
|
import { IRTarget } from '@retikz/core';
|
|
3
3
|
/**
|
|
4
4
|
* <Step> 组件的 props。
|
|
5
|
-
* v0.1.0-alpha
|
|
5
|
+
* v0.1.0-alpha.1 支持四种 kind:'move' / 'line' / 'step'(折角)/ 'cycle'(闭合)。
|
|
6
|
+
* kind 默认 'line'。
|
|
6
7
|
*/
|
|
7
8
|
export type StepProps = {
|
|
8
9
|
/** 移动游标但不绘制(类似 SVG path "M") */
|
|
@@ -14,6 +15,16 @@ export type StepProps = {
|
|
|
14
15
|
kind?: 'line';
|
|
15
16
|
/** 直线终点 */
|
|
16
17
|
to: IRTarget;
|
|
18
|
+
} | {
|
|
19
|
+
/** 折角段:从游标经一个直角拐点到目标点(TikZ `-|` / `|-`) */
|
|
20
|
+
kind: 'step';
|
|
21
|
+
/** 折角走向:`-|` 先水平后垂直;`|-` 先垂直后水平 */
|
|
22
|
+
via: '-|' | '|-';
|
|
23
|
+
/** 折角终点 */
|
|
24
|
+
to: IRTarget;
|
|
25
|
+
} | {
|
|
26
|
+
/** 闭合:把当前子路径回到最近一个 move 起点(TikZ `cycle` / SVG `Z`) */
|
|
27
|
+
kind: 'cycle';
|
|
17
28
|
};
|
|
18
29
|
/**
|
|
19
30
|
* 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;AAChC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7C
|
|
1
|
+
{"version":3,"file":"Step.d.ts","sourceRoot":"","sources":["../../../src/kernel/Step.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7C;;;;GAIG;AACH,MAAM,MAAM,SAAS,GACjB;IACE,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,YAAY;IACZ,EAAE,EAAE,QAAQ,CAAC;CACd,GACD;IACE,wBAAwB;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW;IACX,EAAE,EAAE,QAAQ,CAAC;CACd,GACD;IACE,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,mCAAmC;IACnC,GAAG,EAAE,IAAI,GAAG,IAAI,CAAC;IACjB,WAAW;IACX,EAAE,EAAE,QAAQ,CAAC;CACd,GACD;IACE,sDAAsD;IACtD,IAAI,EAAE,OAAO,CAAC;CACf,CAAC;AAEN;;;GAGG;AACH,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,SAAS,CAAc,CAAC"}
|
package/dist/es/kernel/Tikz.d.ts
CHANGED
|
@@ -19,7 +19,11 @@ export type TikzProps = {
|
|
|
19
19
|
* <Tikz> 顶层容器。
|
|
20
20
|
* 1. 从 children 构造 IR(或直接接受外部 IR)
|
|
21
21
|
* 2. 调 compileToScene 得 Scene
|
|
22
|
-
* 3. 把 Scene primitives 渲染为 SVG
|
|
22
|
+
* 3. 把 Scene primitives 渲染为 SVG 元素;按需注入 `<defs>` 与每种 arrow 形状的 `<marker>`
|
|
23
|
+
*
|
|
24
|
+
* 箭头 marker 用 `useId()` 派生稳定前缀(多个 Tikz 实例共存不冲突);
|
|
25
|
+
* 每种用到的 shape 一个 marker 定义,id 形如 `${prefix}-${shape}`,
|
|
26
|
+
* marker 内 path 借 `context-stroke` / `context-fill` 让颜色随 path 同步。
|
|
23
27
|
*/
|
|
24
28
|
export declare const Tikz: FC<TikzProps>;
|
|
25
29
|
//# sourceMappingURL=Tikz.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tikz.d.ts","sourceRoot":"","sources":["../../../src/kernel/Tikz.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,EAAE,EAAE,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"Tikz.d.ts","sourceRoot":"","sources":["../../../src/kernel/Tikz.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,EAAE,EAAE,KAAK,SAAS,EAAkB,MAAM,OAAO,CAAC;AACpF,OAAO,EAAmB,KAAK,EAAE,EAAuC,MAAM,cAAc,CAAC;AAO7F,uBAAuB;AACvB,MAAM,MAAM,SAAS,GAAG;IACtB,mDAAmD;IACnD,EAAE,CAAC,EAAE,EAAE,CAAC;IACR,gCAAgC;IAChC,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,0BAA0B;IAC1B,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,0BAA0B;IAC1B,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,4BAA4B;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sBAAsB;IACtB,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB,CAAC;AAgBF;;;;;;;;;GASG;AACH,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,SAAS,CAuB9B,CAAC"}
|
package/dist/es/kernel/Tikz.js
CHANGED
|
@@ -1,27 +1,47 @@
|
|
|
1
1
|
import { buildIR } from "./_builder.js";
|
|
2
|
+
import { ArrowMarker } from "../render/arrowMarkers.js";
|
|
2
3
|
import { browserMeasurer } from "../render/browser-measurer.js";
|
|
3
4
|
import { renderPrim } from "../render/renderPrim.js";
|
|
4
5
|
import { formatViewBox } from "../render/viewBox.js";
|
|
5
|
-
import { useMemo } from "react";
|
|
6
|
+
import { useId, useMemo } from "react";
|
|
6
7
|
import { compileToScene } from "@retikz/core";
|
|
7
|
-
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
9
|
//#region src/kernel/Tikz.tsx
|
|
10
|
+
/** 递归收集 scene 里所有 PathPrim 用到的 arrow 形状——按需注入 marker defs */
|
|
11
|
+
var collectArrowShapes = (prims) => {
|
|
12
|
+
const shapes = /* @__PURE__ */ new Set();
|
|
13
|
+
for (const p of prims) if (p.type === "path") {
|
|
14
|
+
if (p.arrowStart) shapes.add(p.arrowStart);
|
|
15
|
+
if (p.arrowEnd) shapes.add(p.arrowEnd);
|
|
16
|
+
} else if (p.type === "group") for (const s of collectArrowShapes(p.children)) shapes.add(s);
|
|
17
|
+
return shapes;
|
|
18
|
+
};
|
|
9
19
|
/**
|
|
10
20
|
* <Tikz> 顶层容器。
|
|
11
21
|
* 1. 从 children 构造 IR(或直接接受外部 IR)
|
|
12
22
|
* 2. 调 compileToScene 得 Scene
|
|
13
|
-
* 3. 把 Scene primitives 渲染为 SVG
|
|
23
|
+
* 3. 把 Scene primitives 渲染为 SVG 元素;按需注入 `<defs>` 与每种 arrow 形状的 `<marker>`
|
|
24
|
+
*
|
|
25
|
+
* 箭头 marker 用 `useId()` 派生稳定前缀(多个 Tikz 实例共存不冲突);
|
|
26
|
+
* 每种用到的 shape 一个 marker 定义,id 形如 `${prefix}-${shape}`,
|
|
27
|
+
* marker 内 path 借 `context-stroke` / `context-fill` 让颜色随 path 同步。
|
|
14
28
|
*/
|
|
15
29
|
var Tikz = ({ ir: irFromProp, children, width, height, className, style }) => {
|
|
16
30
|
const ir = useMemo(() => irFromProp ?? buildIR(children), [irFromProp, children]);
|
|
17
31
|
const scene = useMemo(() => compileToScene(ir, { measureText: browserMeasurer }), [ir]);
|
|
18
|
-
|
|
32
|
+
const arrowMarkerPrefix = `retikz-arrow-${useId().replace(/[^a-zA-Z0-9]/g, "")}`;
|
|
33
|
+
const usedShapes = collectArrowShapes(scene.primitives);
|
|
34
|
+
const arrowMarkerIdFor = (shape) => `${arrowMarkerPrefix}-${shape}`;
|
|
35
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
19
36
|
viewBox: formatViewBox(scene.viewBox),
|
|
20
37
|
width,
|
|
21
38
|
height,
|
|
22
39
|
className,
|
|
23
40
|
style,
|
|
24
|
-
children:
|
|
41
|
+
children: [usedShapes.size > 0 && /* @__PURE__ */ jsx("defs", { children: Array.from(usedShapes).map((shape) => /* @__PURE__ */ jsx(ArrowMarker, {
|
|
42
|
+
id: arrowMarkerIdFor(shape),
|
|
43
|
+
shape
|
|
44
|
+
}, shape)) }), scene.primitives.map((p, i) => renderPrim(p, i, { arrowMarkerIdFor }))]
|
|
25
45
|
});
|
|
26
46
|
};
|
|
27
47
|
//#endregion
|
|
@@ -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,EAAE,EAAE,EAA2B,MAAM,cAAc,CAAC;
|
|
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,EAAE,EAAE,EAA2B,MAAM,cAAc,CAAC;AAoIhE;;;GAGG;AACH,eAAO,MAAM,OAAO,GAAI,UAAU,SAAS,KAAG,EAI5C,CAAC"}
|
|
@@ -14,6 +14,7 @@ var buildNode = (props) => {
|
|
|
14
14
|
return {
|
|
15
15
|
type: "node",
|
|
16
16
|
id: props.id,
|
|
17
|
+
shape: props.shape,
|
|
17
18
|
position: props.position,
|
|
18
19
|
rotate: props.rotate,
|
|
19
20
|
text,
|
|
@@ -27,7 +28,8 @@ var buildNode = (props) => {
|
|
|
27
28
|
};
|
|
28
29
|
/**
|
|
29
30
|
* 扫描 <Path> children 收集 <Step> 序列。
|
|
30
|
-
* 至少 2 段;首段不是 move 时强制改为 move(与 SVG path 的 "M …"
|
|
31
|
+
* 至少 2 段;首段不是 move 时强制改为 move(与 SVG path 的 "M …" 语义对齐);
|
|
32
|
+
* cycle 没有 to 字段,若用户把 cycle 放在首段,coerce 时降级到 move (0,0)。
|
|
31
33
|
*/
|
|
32
34
|
var readPathChildren = (children) => {
|
|
33
35
|
const out = [];
|
|
@@ -36,6 +38,22 @@ var readPathChildren = (children) => {
|
|
|
36
38
|
if (getDisplayName(child) !== "@retikz/Step") return;
|
|
37
39
|
const props = child.props;
|
|
38
40
|
const kind = props.kind ?? "line";
|
|
41
|
+
if (kind === "cycle") {
|
|
42
|
+
out.push({
|
|
43
|
+
type: "step",
|
|
44
|
+
kind: "cycle"
|
|
45
|
+
});
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (kind === "step") {
|
|
49
|
+
out.push({
|
|
50
|
+
type: "step",
|
|
51
|
+
kind: "step",
|
|
52
|
+
via: props.via,
|
|
53
|
+
to: props.to
|
|
54
|
+
});
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
39
57
|
out.push({
|
|
40
58
|
type: "step",
|
|
41
59
|
kind,
|
|
@@ -43,11 +61,18 @@ var readPathChildren = (children) => {
|
|
|
43
61
|
});
|
|
44
62
|
});
|
|
45
63
|
if (out.length < 2) throw new Error("<Path> requires at least 2 <Step> children");
|
|
46
|
-
if (out[0].kind !== "move")
|
|
47
|
-
|
|
48
|
-
kind
|
|
49
|
-
|
|
50
|
-
|
|
64
|
+
if (out[0].kind !== "move") {
|
|
65
|
+
const first = out[0];
|
|
66
|
+
out[0] = first.kind === "cycle" ? {
|
|
67
|
+
type: "step",
|
|
68
|
+
kind: "move",
|
|
69
|
+
to: [0, 0]
|
|
70
|
+
} : {
|
|
71
|
+
type: "step",
|
|
72
|
+
kind: "move",
|
|
73
|
+
to: first.to
|
|
74
|
+
};
|
|
75
|
+
}
|
|
51
76
|
return out;
|
|
52
77
|
};
|
|
53
78
|
/** 把 <Path> props 翻成 IRChild;step 序列由 readPathChildren 收集 */
|
|
@@ -56,6 +81,10 @@ var buildPath = (props) => ({
|
|
|
56
81
|
stroke: props.stroke,
|
|
57
82
|
strokeWidth: props.strokeWidth,
|
|
58
83
|
strokeDasharray: props.strokeDasharray,
|
|
84
|
+
arrow: props.arrow,
|
|
85
|
+
arrowShape: props.arrowShape,
|
|
86
|
+
fill: props.fill,
|
|
87
|
+
fillRule: props.fillRule,
|
|
59
88
|
children: readPathChildren(props.children)
|
|
60
89
|
});
|
|
61
90
|
/**
|
|
@@ -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;AA2DhE;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAAI,IAAI,EAAE,KAAG,SACW,CAAC"}
|
|
@@ -7,6 +7,7 @@ import { createElement } from "react";
|
|
|
7
7
|
var nodePropsFromIR = (n) => {
|
|
8
8
|
const props = { position: n.position };
|
|
9
9
|
if (n.id !== void 0) props.id = n.id;
|
|
10
|
+
if (n.shape !== void 0) props.shape = n.shape;
|
|
10
11
|
if (n.rotate !== void 0) props.rotate = n.rotate;
|
|
11
12
|
if (n.text !== void 0) props.text = n.text;
|
|
12
13
|
if (n.fontSize !== void 0) props.fontSize = n.fontSize;
|
|
@@ -18,11 +19,23 @@ var nodePropsFromIR = (n) => {
|
|
|
18
19
|
return props;
|
|
19
20
|
};
|
|
20
21
|
/** 单个 IRStep → <Step /> element */
|
|
21
|
-
var stepToElement = (step, key) =>
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
});
|
|
22
|
+
var stepToElement = (step, key) => {
|
|
23
|
+
if (step.kind === "cycle") return createElement(Step, {
|
|
24
|
+
key,
|
|
25
|
+
kind: "cycle"
|
|
26
|
+
});
|
|
27
|
+
if (step.kind === "step") return createElement(Step, {
|
|
28
|
+
key,
|
|
29
|
+
kind: "step",
|
|
30
|
+
via: step.via,
|
|
31
|
+
to: step.to
|
|
32
|
+
});
|
|
33
|
+
return createElement(Step, {
|
|
34
|
+
key,
|
|
35
|
+
kind: step.kind,
|
|
36
|
+
to: step.to
|
|
37
|
+
});
|
|
38
|
+
};
|
|
26
39
|
/** discriminated union 兜底:编译期保证不漏 case,运行时给出明确错误 */
|
|
27
40
|
var assertNever = (x) => {
|
|
28
41
|
throw new Error(`convertIRToReactNode: unknown IR child type: ${JSON.stringify(x)}`);
|
|
@@ -39,6 +52,10 @@ var childToElement = (child, key) => {
|
|
|
39
52
|
stroke: child.stroke,
|
|
40
53
|
strokeWidth: child.strokeWidth,
|
|
41
54
|
strokeDasharray: child.strokeDasharray,
|
|
55
|
+
arrow: child.arrow,
|
|
56
|
+
arrowShape: child.arrowShape,
|
|
57
|
+
fill: child.fill,
|
|
58
|
+
fillRule: child.fillRule,
|
|
42
59
|
children: child.children.map((s, j) => stepToElement(s, j))
|
|
43
60
|
});
|
|
44
61
|
default: return assertNever(child);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { ArrowShape } from '@retikz/core';
|
|
3
|
+
export type ArrowMarkerProps = {
|
|
4
|
+
/** marker 元素 id,用于 path markerStart / markerEnd 引用 */
|
|
5
|
+
id: string;
|
|
6
|
+
/** 形状名 */
|
|
7
|
+
shape: ArrowShape;
|
|
8
|
+
};
|
|
9
|
+
/** 单个 `<marker>` 元素,由 `<defs>` 包起来 */
|
|
10
|
+
export declare const ArrowMarker: FC<ArrowMarkerProps>;
|
|
11
|
+
//# sourceMappingURL=arrowMarkers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arrowMarkers.d.ts","sourceRoot":"","sources":["../../../src/render/arrowMarkers.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAgB,MAAM,OAAO,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAqF/C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,sDAAsD;IACtD,EAAE,EAAE,MAAM,CAAC;IACX,UAAU;IACV,KAAK,EAAE,UAAU,CAAC;CACnB,CAAC;AAEF,sCAAsC;AACtC,eAAO,MAAM,WAAW,EAAE,EAAE,CAAC,gBAAgB,CAgB5C,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
//#region src/render/arrowMarkers.tsx
|
|
3
|
+
var MARKERS = {
|
|
4
|
+
normal: {
|
|
5
|
+
refX: 10,
|
|
6
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
7
|
+
d: "M 0 0 L 10 5 L 0 10 Z",
|
|
8
|
+
fill: "context-stroke"
|
|
9
|
+
})
|
|
10
|
+
},
|
|
11
|
+
open: {
|
|
12
|
+
refX: 1,
|
|
13
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
14
|
+
d: "M 1 1 L 9 5 L 1 9 Z",
|
|
15
|
+
fill: "none",
|
|
16
|
+
stroke: "context-stroke",
|
|
17
|
+
strokeWidth: 1.5
|
|
18
|
+
})
|
|
19
|
+
},
|
|
20
|
+
stealth: {
|
|
21
|
+
refX: 10,
|
|
22
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
23
|
+
d: "M 0 0 L 10 5 L 0 10 L 3 5 Z",
|
|
24
|
+
fill: "context-stroke"
|
|
25
|
+
})
|
|
26
|
+
},
|
|
27
|
+
diamond: {
|
|
28
|
+
refX: 10,
|
|
29
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
30
|
+
d: "M 0 5 L 5 0 L 10 5 L 5 10 Z",
|
|
31
|
+
fill: "context-stroke"
|
|
32
|
+
})
|
|
33
|
+
},
|
|
34
|
+
openDiamond: {
|
|
35
|
+
refX: 1,
|
|
36
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
37
|
+
d: "M 1 5 L 5 1 L 9 5 L 5 9 Z",
|
|
38
|
+
fill: "none",
|
|
39
|
+
stroke: "context-stroke",
|
|
40
|
+
strokeWidth: 1.5,
|
|
41
|
+
strokeLinejoin: "round"
|
|
42
|
+
})
|
|
43
|
+
},
|
|
44
|
+
circle: {
|
|
45
|
+
refX: 10,
|
|
46
|
+
children: /* @__PURE__ */ jsx("circle", {
|
|
47
|
+
cx: 5,
|
|
48
|
+
cy: 5,
|
|
49
|
+
r: 5,
|
|
50
|
+
fill: "context-stroke"
|
|
51
|
+
})
|
|
52
|
+
},
|
|
53
|
+
openCircle: {
|
|
54
|
+
refX: 0,
|
|
55
|
+
children: /* @__PURE__ */ jsx("circle", {
|
|
56
|
+
cx: 5,
|
|
57
|
+
cy: 5,
|
|
58
|
+
r: 4.25,
|
|
59
|
+
fill: "none",
|
|
60
|
+
stroke: "context-stroke",
|
|
61
|
+
strokeWidth: 1.5
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
/** 单个 `<marker>` 元素,由 `<defs>` 包起来 */
|
|
66
|
+
var ArrowMarker = ({ id, shape }) => {
|
|
67
|
+
const spec = MARKERS[shape];
|
|
68
|
+
return /* @__PURE__ */ jsx("marker", {
|
|
69
|
+
id,
|
|
70
|
+
viewBox: "0 0 10 10",
|
|
71
|
+
refX: spec.refX,
|
|
72
|
+
refY: 5,
|
|
73
|
+
markerWidth: 6,
|
|
74
|
+
markerHeight: 6,
|
|
75
|
+
orient: "auto-start-reverse",
|
|
76
|
+
markerUnits: "strokeWidth",
|
|
77
|
+
children: spec.children
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
//#endregion
|
|
81
|
+
export { ArrowMarker };
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { Key, ReactElement } from 'react';
|
|
2
|
-
import { ScenePrimitive } from '@retikz/core';
|
|
2
|
+
import { ArrowShape, ScenePrimitive } from '@retikz/core';
|
|
3
|
+
/**
|
|
4
|
+
* 渲染上下文——Tikz 容器侧把 marker id 等"全 SVG 共享"的资源向下传给 renderPrim。
|
|
5
|
+
* 资源若不存在就传 undefined,对应路径 prim 不会引用 marker。
|
|
6
|
+
*/
|
|
7
|
+
export type RenderContext = {
|
|
8
|
+
/** 按 arrow 形状查 SVG `<defs><marker id>` id 的回调 */
|
|
9
|
+
arrowMarkerIdFor?: (shape: ArrowShape) => string;
|
|
10
|
+
};
|
|
3
11
|
/**
|
|
4
12
|
* Scene primitive → SVG React 元素。
|
|
5
|
-
* 不读 IR,只读 Scene
|
|
13
|
+
* 不读 IR,只读 Scene。
|
|
6
14
|
*/
|
|
7
|
-
export declare const renderPrim: (p: ScenePrimitive, key: Key) => ReactElement;
|
|
15
|
+
export declare const renderPrim: (p: ScenePrimitive, key: Key, ctx?: RenderContext) => ReactElement;
|
|
8
16
|
//# sourceMappingURL=renderPrim.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderPrim.d.ts","sourceRoot":"","sources":["../../../src/render/renderPrim.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"renderPrim.d.ts","sourceRoot":"","sources":["../../../src/render/renderPrim.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AA6B/D;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,iDAAiD;IACjD,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,MAAM,CAAC;CAClD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,UAAU,GACrB,GAAG,cAAc,EACjB,KAAK,GAAG,EACR,MAAK,aAAkB,KACtB,YAsFF,CAAC"}
|
|
@@ -13,9 +13,9 @@ var baselineToDominant = (b) => {
|
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
15
15
|
* Scene primitive → SVG React 元素。
|
|
16
|
-
* 不读 IR,只读 Scene
|
|
16
|
+
* 不读 IR,只读 Scene。
|
|
17
17
|
*/
|
|
18
|
-
var renderPrim = (p, key) => {
|
|
18
|
+
var renderPrim = (p, key, ctx = {}) => {
|
|
19
19
|
switch (p.type) {
|
|
20
20
|
case "rect": return /* @__PURE__ */ jsx("rect", {
|
|
21
21
|
x: p.x,
|
|
@@ -31,6 +31,22 @@ var renderPrim = (p, key) => {
|
|
|
31
31
|
ry: p.cornerRadius,
|
|
32
32
|
opacity: p.opacity
|
|
33
33
|
}, key);
|
|
34
|
+
case "ellipse": {
|
|
35
|
+
const transform = p.rotate ? `rotate(${p.rotate} ${p.cx} ${p.cy})` : void 0;
|
|
36
|
+
return /* @__PURE__ */ jsx("ellipse", {
|
|
37
|
+
cx: p.cx,
|
|
38
|
+
cy: p.cy,
|
|
39
|
+
rx: p.rx,
|
|
40
|
+
ry: p.ry,
|
|
41
|
+
transform,
|
|
42
|
+
fill: p.fill,
|
|
43
|
+
fillOpacity: p.fillOpacity,
|
|
44
|
+
stroke: p.stroke,
|
|
45
|
+
strokeWidth: p.strokeWidth,
|
|
46
|
+
strokeDasharray: p.strokeDasharray,
|
|
47
|
+
opacity: p.opacity
|
|
48
|
+
}, key);
|
|
49
|
+
}
|
|
34
50
|
case "text": return /* @__PURE__ */ jsx("text", {
|
|
35
51
|
x: p.x,
|
|
36
52
|
y: p.y,
|
|
@@ -44,19 +60,26 @@ var renderPrim = (p, key) => {
|
|
|
44
60
|
opacity: p.opacity,
|
|
45
61
|
children: p.content
|
|
46
62
|
}, key);
|
|
47
|
-
case "path":
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
63
|
+
case "path": {
|
|
64
|
+
const startId = p.arrowStart && ctx.arrowMarkerIdFor ? ctx.arrowMarkerIdFor(p.arrowStart) : void 0;
|
|
65
|
+
const endId = p.arrowEnd && ctx.arrowMarkerIdFor ? ctx.arrowMarkerIdFor(p.arrowEnd) : void 0;
|
|
66
|
+
return /* @__PURE__ */ jsx("path", {
|
|
67
|
+
d: p.d,
|
|
68
|
+
fill: p.fill,
|
|
69
|
+
fillRule: p.fillRule,
|
|
70
|
+
stroke: p.stroke,
|
|
71
|
+
strokeWidth: p.strokeWidth,
|
|
72
|
+
strokeDasharray: p.strokeDasharray,
|
|
73
|
+
strokeLinecap: p.strokeLinecap,
|
|
74
|
+
strokeLinejoin: p.strokeLinejoin,
|
|
75
|
+
markerStart: startId ? `url(#${startId})` : void 0,
|
|
76
|
+
markerEnd: endId ? `url(#${endId})` : void 0,
|
|
77
|
+
opacity: p.opacity
|
|
78
|
+
}, key);
|
|
79
|
+
}
|
|
57
80
|
case "group": return /* @__PURE__ */ jsx("g", {
|
|
58
81
|
transform: p.transform,
|
|
59
|
-
children: p.children.map((c, i) => renderPrim(c, i))
|
|
82
|
+
children: p.children.map((c, i) => renderPrim(c, i, ctx))
|
|
60
83
|
}, key);
|
|
61
84
|
}
|
|
62
85
|
};
|
package/dist/es/sugar/Draw.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { FC } from 'react';
|
|
|
2
2
|
import { IRPath, WayDSL } from '@retikz/core';
|
|
3
3
|
/** <Draw> 组件的 props */
|
|
4
4
|
export type DrawProps = {
|
|
5
|
-
/** way 数组 DSL:节点 id
|
|
5
|
+
/** way 数组 DSL:节点 id / 坐标 / 极坐标 / 折角算子 `'-|'` `'|-'` / 闭合 `DrawWay.cycle` */
|
|
6
6
|
way: WayDSL;
|
|
7
7
|
/** 描边色,省略时用 currentColor */
|
|
8
8
|
stroke?: IRPath['stroke'];
|
|
@@ -10,6 +10,19 @@ export type DrawProps = {
|
|
|
10
10
|
strokeWidth?: IRPath['strokeWidth'];
|
|
11
11
|
/** SVG stroke-dasharray 模式(如 "4 2") */
|
|
12
12
|
strokeDasharray?: IRPath['strokeDasharray'];
|
|
13
|
+
/**
|
|
14
|
+
* 路径级箭头方向。`'->'` = 终点;`'<-'` = 起点;`'<->'` = 两端;
|
|
15
|
+
* 省略或 `'none'` = 无箭头。
|
|
16
|
+
*/
|
|
17
|
+
arrow?: IRPath['arrow'];
|
|
18
|
+
/**
|
|
19
|
+
* 箭头形状。默认 `'normal'`。其他:`'open'` / `'stealth'` / `'diamond'` / `'circle'`。
|
|
20
|
+
*/
|
|
21
|
+
arrowShape?: IRPath['arrowShape'];
|
|
22
|
+
/** 闭合区域填充色,省略 = 不填充。配合 way 末尾的 `DrawWay.cycle` 画填充形状 */
|
|
23
|
+
fill?: IRPath['fill'];
|
|
24
|
+
/** SVG fill-rule:`'nonzero'`(默认)/ `'evenodd'` */
|
|
25
|
+
fillRule?: IRPath['fillRule'];
|
|
13
26
|
};
|
|
14
27
|
/**
|
|
15
28
|
* Sugar 组件——展开为等价的 <Path><Step.../></Path> Kernel 子树。
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Draw.d.ts","sourceRoot":"","sources":["../../../src/sugar/Draw.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAKnD,uBAAuB;AACvB,MAAM,MAAM,SAAS,GAAG;IACtB,
|
|
1
|
+
{"version":3,"file":"Draw.d.ts","sourceRoot":"","sources":["../../../src/sugar/Draw.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAKnD,uBAAuB;AACvB,MAAM,MAAM,SAAS,GAAG;IACtB,4EAA4E;IAC5E,GAAG,EAAE,MAAM,CAAC;IACZ,4BAA4B;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC1B,kBAAkB;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;IACpC,uCAAuC;IACvC,eAAe,CAAC,EAAE,MAAM,CAAC,iBAAiB,CAAC,CAAC;IAC5C;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IACxB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;IAClC,wDAAwD;IACxD,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACtB,iDAAiD;IACjD,QAAQ,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;CAC/B,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,SAAS,CAsB9B,CAAC"}
|
package/dist/es/sugar/Draw.js
CHANGED
|
@@ -12,18 +12,31 @@ import { jsx } from "react/jsx-runtime";
|
|
|
12
12
|
* (useState / useMemo / useEffect 等会抛 "Invalid hook call")。
|
|
13
13
|
*/
|
|
14
14
|
var Draw = (props) => {
|
|
15
|
-
const { way, stroke, strokeWidth, strokeDasharray } = props;
|
|
15
|
+
const { way, stroke, strokeWidth, strokeDasharray, arrow, arrowShape, fill, fillRule } = props;
|
|
16
16
|
return /* @__PURE__ */ jsx(Path, {
|
|
17
17
|
stroke,
|
|
18
18
|
strokeWidth,
|
|
19
19
|
strokeDasharray,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
arrow,
|
|
21
|
+
arrowShape,
|
|
22
|
+
fill,
|
|
23
|
+
fillRule,
|
|
24
|
+
children: parseWay(way).map((s, i) => {
|
|
25
|
+
if (s.kind === "cycle") return /* @__PURE__ */ jsx(Step, { kind: "cycle" }, i);
|
|
26
|
+
if (s.kind === "move") return /* @__PURE__ */ jsx(Step, {
|
|
27
|
+
kind: "move",
|
|
28
|
+
to: s.to
|
|
29
|
+
}, i);
|
|
30
|
+
if (s.kind === "step") return /* @__PURE__ */ jsx(Step, {
|
|
31
|
+
kind: "step",
|
|
32
|
+
via: s.via,
|
|
33
|
+
to: s.to
|
|
34
|
+
}, i);
|
|
35
|
+
return /* @__PURE__ */ jsx(Step, {
|
|
36
|
+
kind: "line",
|
|
37
|
+
to: s.to
|
|
38
|
+
}, i);
|
|
39
|
+
})
|
|
27
40
|
});
|
|
28
41
|
};
|
|
29
42
|
//#endregion
|
package/dist/lib/index.cjs
CHANGED
|
@@ -8,7 +8,14 @@ require("./kernel/index.cjs");
|
|
|
8
8
|
const require_Draw = require("./sugar/Draw.cjs");
|
|
9
9
|
require("./sugar/index.cjs");
|
|
10
10
|
const require__unbuilder = require("./kernel/_unbuilder.cjs");
|
|
11
|
+
let _retikz_core = require("@retikz/core");
|
|
11
12
|
exports.Draw = require_Draw.Draw;
|
|
13
|
+
Object.defineProperty(exports, "DrawWay", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function() {
|
|
16
|
+
return _retikz_core.DrawWay;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
12
19
|
exports.Node = require_Node.Node;
|
|
13
20
|
exports.Path = require_Path.Path;
|
|
14
21
|
exports.Step = require_Step.Step;
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ export { Tikz, Node, Path, Step } from './kernel';
|
|
|
10
10
|
export type { TikzProps, NodeProps, PathProps, StepProps } from './kernel';
|
|
11
11
|
export { Draw } from './sugar';
|
|
12
12
|
export type { DrawProps } from './sugar';
|
|
13
|
+
export { DrawWay } from '@retikz/core';
|
|
14
|
+
export type { WayItem, WayDSL, WayCycle, WayVia } from '@retikz/core';
|
|
13
15
|
export { buildIR as convertReactNodeToIR } from './kernel/_builder';
|
|
14
16
|
export { convertIRToReactNode } from './kernel/_unbuilder';
|
|
15
17
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAClD,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE3E,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGzC,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAClD,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE3E,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGzC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtE,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -4,6 +4,8 @@ import { IRNode, IRPosition, PolarPosition } from '@retikz/core';
|
|
|
4
4
|
export type NodeProps = {
|
|
5
5
|
/** 节点 id;其他 Path/Draw 通过这个 id 引用本节点 */
|
|
6
6
|
id?: string;
|
|
7
|
+
/** 节点形状:rectangle(默认)/ circle / ellipse / diamond */
|
|
8
|
+
shape?: IRNode['shape'];
|
|
7
9
|
/** 节点中心位置;笛卡尔 [x, y] 或极坐标(编译时解析) */
|
|
8
10
|
position: IRPosition | PolarPosition;
|
|
9
11
|
/** 旋转角度(度数,与 TikZ 一致),绕节点中心;正值顺时针 */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Node.d.ts","sourceRoot":"","sources":["../../../src/kernel/Node.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAGtE,uBAAuB;AACvB,MAAM,MAAM,SAAS,GAAG;IACtB,uCAAuC;IACvC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,oCAAoC;IACpC,QAAQ,EAAE,UAAU,GAAG,aAAa,CAAC;IACrC,qCAAqC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iCAAiC;IACjC,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,6BAA6B;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gBAAgB;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,yBAAyB;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oDAAoD;IACpD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU;IACV,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACtB,UAAU;IACV,MAAM,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC1B,WAAW;IACX,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,SAAS,CAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"Node.d.ts","sourceRoot":"","sources":["../../../src/kernel/Node.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAGtE,uBAAuB;AACvB,MAAM,MAAM,SAAS,GAAG;IACtB,uCAAuC;IACvC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,qDAAqD;IACrD,KAAK,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IACxB,oCAAoC;IACpC,QAAQ,EAAE,UAAU,GAAG,aAAa,CAAC;IACrC,qCAAqC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iCAAiC;IACjC,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,6BAA6B;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gBAAgB;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,yBAAyB;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oDAAoD;IACpD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU;IACV,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACtB,UAAU;IACV,MAAM,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC1B,WAAW;IACX,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,SAAS,CAAc,CAAC"}
|
|
@@ -8,6 +8,20 @@ export type PathProps = {
|
|
|
8
8
|
strokeWidth?: IRPath['strokeWidth'];
|
|
9
9
|
/** SVG stroke-dasharray 模式(如 "4 2") */
|
|
10
10
|
strokeDasharray?: IRPath['strokeDasharray'];
|
|
11
|
+
/**
|
|
12
|
+
* 路径级箭头方向。`'->'` = 终点;`'<-'` = 起点;`'<->'` = 两端;
|
|
13
|
+
* 省略或 `'none'` = 无箭头。
|
|
14
|
+
*/
|
|
15
|
+
arrow?: IRPath['arrow'];
|
|
16
|
+
/**
|
|
17
|
+
* 箭头形状。默认 `'normal'`(实心三角)。其他:`'open'` 空心三角、
|
|
18
|
+
* `'stealth'` 倒钩、`'diamond'` 菱形、`'circle'` 圆点。
|
|
19
|
+
*/
|
|
20
|
+
arrowShape?: IRPath['arrowShape'];
|
|
21
|
+
/** 闭合区域填充色,CSS 颜色字符串;省略 = 不填充(仅描边)。配合 cycle step 画填充形状 */
|
|
22
|
+
fill?: IRPath['fill'];
|
|
23
|
+
/** SVG fill-rule:`'nonzero'`(默认)/ `'evenodd'`(环形 / 孔洞) */
|
|
24
|
+
fillRule?: IRPath['fillRule'];
|
|
11
25
|
/** 应当全部是 <Step /> */
|
|
12
26
|
children: ReactNode;
|
|
13
27
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Path.d.ts","sourceRoot":"","sources":["../../../src/kernel/Path.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAG3C,uBAAuB;AACvB,MAAM,MAAM,SAAS,GAAG;IACtB,4BAA4B;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC1B,kBAAkB;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;IACpC,uCAAuC;IACvC,eAAe,CAAC,EAAE,MAAM,CAAC,iBAAiB,CAAC,CAAC;IAC5C,qBAAqB;IACrB,QAAQ,EAAE,SAAS,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,SAAS,CAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"Path.d.ts","sourceRoot":"","sources":["../../../src/kernel/Path.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAG3C,uBAAuB;AACvB,MAAM,MAAM,SAAS,GAAG;IACtB,4BAA4B;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC1B,kBAAkB;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;IACpC,uCAAuC;IACvC,eAAe,CAAC,EAAE,MAAM,CAAC,iBAAiB,CAAC,CAAC;IAC5C;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IACxB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;IAClC,0DAA0D;IAC1D,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACtB,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;IAC9B,qBAAqB;IACrB,QAAQ,EAAE,SAAS,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,SAAS,CAAc,CAAC"}
|
|
@@ -2,7 +2,8 @@ import { FC } from 'react';
|
|
|
2
2
|
import { IRTarget } from '@retikz/core';
|
|
3
3
|
/**
|
|
4
4
|
* <Step> 组件的 props。
|
|
5
|
-
* v0.1.0-alpha
|
|
5
|
+
* v0.1.0-alpha.1 支持四种 kind:'move' / 'line' / 'step'(折角)/ 'cycle'(闭合)。
|
|
6
|
+
* kind 默认 'line'。
|
|
6
7
|
*/
|
|
7
8
|
export type StepProps = {
|
|
8
9
|
/** 移动游标但不绘制(类似 SVG path "M") */
|
|
@@ -14,6 +15,16 @@ export type StepProps = {
|
|
|
14
15
|
kind?: 'line';
|
|
15
16
|
/** 直线终点 */
|
|
16
17
|
to: IRTarget;
|
|
18
|
+
} | {
|
|
19
|
+
/** 折角段:从游标经一个直角拐点到目标点(TikZ `-|` / `|-`) */
|
|
20
|
+
kind: 'step';
|
|
21
|
+
/** 折角走向:`-|` 先水平后垂直;`|-` 先垂直后水平 */
|
|
22
|
+
via: '-|' | '|-';
|
|
23
|
+
/** 折角终点 */
|
|
24
|
+
to: IRTarget;
|
|
25
|
+
} | {
|
|
26
|
+
/** 闭合:把当前子路径回到最近一个 move 起点(TikZ `cycle` / SVG `Z`) */
|
|
27
|
+
kind: 'cycle';
|
|
17
28
|
};
|
|
18
29
|
/**
|
|
19
30
|
* 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;AAChC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7C
|
|
1
|
+
{"version":3,"file":"Step.d.ts","sourceRoot":"","sources":["../../../src/kernel/Step.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7C;;;;GAIG;AACH,MAAM,MAAM,SAAS,GACjB;IACE,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,YAAY;IACZ,EAAE,EAAE,QAAQ,CAAC;CACd,GACD;IACE,wBAAwB;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW;IACX,EAAE,EAAE,QAAQ,CAAC;CACd,GACD;IACE,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,mCAAmC;IACnC,GAAG,EAAE,IAAI,GAAG,IAAI,CAAC;IACjB,WAAW;IACX,EAAE,EAAE,QAAQ,CAAC;CACd,GACD;IACE,sDAAsD;IACtD,IAAI,EAAE,OAAO,CAAC;CACf,CAAC;AAEN;;;GAGG;AACH,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,SAAS,CAAc,CAAC"}
|
package/dist/lib/kernel/Tikz.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const require__builder = require("./_builder.cjs");
|
|
2
|
+
const require_arrowMarkers = require("../render/arrowMarkers.cjs");
|
|
2
3
|
const require_browser_measurer = require("../render/browser-measurer.cjs");
|
|
3
4
|
const require_renderPrim = require("../render/renderPrim.cjs");
|
|
4
5
|
const require_viewBox = require("../render/viewBox.cjs");
|
|
@@ -6,22 +7,41 @@ let react = require("react");
|
|
|
6
7
|
let _retikz_core = require("@retikz/core");
|
|
7
8
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
8
9
|
//#region src/kernel/Tikz.tsx
|
|
10
|
+
/** 递归收集 scene 里所有 PathPrim 用到的 arrow 形状——按需注入 marker defs */
|
|
11
|
+
var collectArrowShapes = (prims) => {
|
|
12
|
+
const shapes = /* @__PURE__ */ new Set();
|
|
13
|
+
for (const p of prims) if (p.type === "path") {
|
|
14
|
+
if (p.arrowStart) shapes.add(p.arrowStart);
|
|
15
|
+
if (p.arrowEnd) shapes.add(p.arrowEnd);
|
|
16
|
+
} else if (p.type === "group") for (const s of collectArrowShapes(p.children)) shapes.add(s);
|
|
17
|
+
return shapes;
|
|
18
|
+
};
|
|
9
19
|
/**
|
|
10
20
|
* <Tikz> 顶层容器。
|
|
11
21
|
* 1. 从 children 构造 IR(或直接接受外部 IR)
|
|
12
22
|
* 2. 调 compileToScene 得 Scene
|
|
13
|
-
* 3. 把 Scene primitives 渲染为 SVG
|
|
23
|
+
* 3. 把 Scene primitives 渲染为 SVG 元素;按需注入 `<defs>` 与每种 arrow 形状的 `<marker>`
|
|
24
|
+
*
|
|
25
|
+
* 箭头 marker 用 `useId()` 派生稳定前缀(多个 Tikz 实例共存不冲突);
|
|
26
|
+
* 每种用到的 shape 一个 marker 定义,id 形如 `${prefix}-${shape}`,
|
|
27
|
+
* marker 内 path 借 `context-stroke` / `context-fill` 让颜色随 path 同步。
|
|
14
28
|
*/
|
|
15
29
|
var Tikz = ({ ir: irFromProp, children, width, height, className, style }) => {
|
|
16
30
|
const ir = (0, react.useMemo)(() => irFromProp ?? require__builder.buildIR(children), [irFromProp, children]);
|
|
17
31
|
const scene = (0, react.useMemo)(() => (0, _retikz_core.compileToScene)(ir, { measureText: require_browser_measurer.browserMeasurer }), [ir]);
|
|
18
|
-
|
|
32
|
+
const arrowMarkerPrefix = `retikz-arrow-${(0, react.useId)().replace(/[^a-zA-Z0-9]/g, "")}`;
|
|
33
|
+
const usedShapes = collectArrowShapes(scene.primitives);
|
|
34
|
+
const arrowMarkerIdFor = (shape) => `${arrowMarkerPrefix}-${shape}`;
|
|
35
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
|
|
19
36
|
viewBox: require_viewBox.formatViewBox(scene.viewBox),
|
|
20
37
|
width,
|
|
21
38
|
height,
|
|
22
39
|
className,
|
|
23
40
|
style,
|
|
24
|
-
children:
|
|
41
|
+
children: [usedShapes.size > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("defs", { children: Array.from(usedShapes).map((shape) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_arrowMarkers.ArrowMarker, {
|
|
42
|
+
id: arrowMarkerIdFor(shape),
|
|
43
|
+
shape
|
|
44
|
+
}, shape)) }), scene.primitives.map((p, i) => require_renderPrim.renderPrim(p, i, { arrowMarkerIdFor }))]
|
|
25
45
|
});
|
|
26
46
|
};
|
|
27
47
|
//#endregion
|
|
@@ -19,7 +19,11 @@ export type TikzProps = {
|
|
|
19
19
|
* <Tikz> 顶层容器。
|
|
20
20
|
* 1. 从 children 构造 IR(或直接接受外部 IR)
|
|
21
21
|
* 2. 调 compileToScene 得 Scene
|
|
22
|
-
* 3. 把 Scene primitives 渲染为 SVG
|
|
22
|
+
* 3. 把 Scene primitives 渲染为 SVG 元素;按需注入 `<defs>` 与每种 arrow 形状的 `<marker>`
|
|
23
|
+
*
|
|
24
|
+
* 箭头 marker 用 `useId()` 派生稳定前缀(多个 Tikz 实例共存不冲突);
|
|
25
|
+
* 每种用到的 shape 一个 marker 定义,id 形如 `${prefix}-${shape}`,
|
|
26
|
+
* marker 内 path 借 `context-stroke` / `context-fill` 让颜色随 path 同步。
|
|
23
27
|
*/
|
|
24
28
|
export declare const Tikz: FC<TikzProps>;
|
|
25
29
|
//# sourceMappingURL=Tikz.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tikz.d.ts","sourceRoot":"","sources":["../../../src/kernel/Tikz.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,EAAE,EAAE,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"Tikz.d.ts","sourceRoot":"","sources":["../../../src/kernel/Tikz.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,EAAE,EAAE,KAAK,SAAS,EAAkB,MAAM,OAAO,CAAC;AACpF,OAAO,EAAmB,KAAK,EAAE,EAAuC,MAAM,cAAc,CAAC;AAO7F,uBAAuB;AACvB,MAAM,MAAM,SAAS,GAAG;IACtB,mDAAmD;IACnD,EAAE,CAAC,EAAE,EAAE,CAAC;IACR,gCAAgC;IAChC,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,0BAA0B;IAC1B,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,0BAA0B;IAC1B,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,4BAA4B;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sBAAsB;IACtB,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB,CAAC;AAgBF;;;;;;;;;GASG;AACH,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,SAAS,CAuB9B,CAAC"}
|
|
@@ -14,6 +14,7 @@ var buildNode = (props) => {
|
|
|
14
14
|
return {
|
|
15
15
|
type: "node",
|
|
16
16
|
id: props.id,
|
|
17
|
+
shape: props.shape,
|
|
17
18
|
position: props.position,
|
|
18
19
|
rotate: props.rotate,
|
|
19
20
|
text,
|
|
@@ -27,7 +28,8 @@ var buildNode = (props) => {
|
|
|
27
28
|
};
|
|
28
29
|
/**
|
|
29
30
|
* 扫描 <Path> children 收集 <Step> 序列。
|
|
30
|
-
* 至少 2 段;首段不是 move 时强制改为 move(与 SVG path 的 "M …"
|
|
31
|
+
* 至少 2 段;首段不是 move 时强制改为 move(与 SVG path 的 "M …" 语义对齐);
|
|
32
|
+
* cycle 没有 to 字段,若用户把 cycle 放在首段,coerce 时降级到 move (0,0)。
|
|
31
33
|
*/
|
|
32
34
|
var readPathChildren = (children) => {
|
|
33
35
|
const out = [];
|
|
@@ -36,6 +38,22 @@ var readPathChildren = (children) => {
|
|
|
36
38
|
if (getDisplayName(child) !== "@retikz/Step") return;
|
|
37
39
|
const props = child.props;
|
|
38
40
|
const kind = props.kind ?? "line";
|
|
41
|
+
if (kind === "cycle") {
|
|
42
|
+
out.push({
|
|
43
|
+
type: "step",
|
|
44
|
+
kind: "cycle"
|
|
45
|
+
});
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (kind === "step") {
|
|
49
|
+
out.push({
|
|
50
|
+
type: "step",
|
|
51
|
+
kind: "step",
|
|
52
|
+
via: props.via,
|
|
53
|
+
to: props.to
|
|
54
|
+
});
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
39
57
|
out.push({
|
|
40
58
|
type: "step",
|
|
41
59
|
kind,
|
|
@@ -43,11 +61,18 @@ var readPathChildren = (children) => {
|
|
|
43
61
|
});
|
|
44
62
|
});
|
|
45
63
|
if (out.length < 2) throw new Error("<Path> requires at least 2 <Step> children");
|
|
46
|
-
if (out[0].kind !== "move")
|
|
47
|
-
|
|
48
|
-
kind
|
|
49
|
-
|
|
50
|
-
|
|
64
|
+
if (out[0].kind !== "move") {
|
|
65
|
+
const first = out[0];
|
|
66
|
+
out[0] = first.kind === "cycle" ? {
|
|
67
|
+
type: "step",
|
|
68
|
+
kind: "move",
|
|
69
|
+
to: [0, 0]
|
|
70
|
+
} : {
|
|
71
|
+
type: "step",
|
|
72
|
+
kind: "move",
|
|
73
|
+
to: first.to
|
|
74
|
+
};
|
|
75
|
+
}
|
|
51
76
|
return out;
|
|
52
77
|
};
|
|
53
78
|
/** 把 <Path> props 翻成 IRChild;step 序列由 readPathChildren 收集 */
|
|
@@ -56,6 +81,10 @@ var buildPath = (props) => ({
|
|
|
56
81
|
stroke: props.stroke,
|
|
57
82
|
strokeWidth: props.strokeWidth,
|
|
58
83
|
strokeDasharray: props.strokeDasharray,
|
|
84
|
+
arrow: props.arrow,
|
|
85
|
+
arrowShape: props.arrowShape,
|
|
86
|
+
fill: props.fill,
|
|
87
|
+
fillRule: props.fillRule,
|
|
59
88
|
children: readPathChildren(props.children)
|
|
60
89
|
});
|
|
61
90
|
/**
|
|
@@ -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,EAAE,EAAE,EAA2B,MAAM,cAAc,CAAC;
|
|
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,EAAE,EAAE,EAA2B,MAAM,cAAc,CAAC;AAoIhE;;;GAGG;AACH,eAAO,MAAM,OAAO,GAAI,UAAU,SAAS,KAAG,EAI5C,CAAC"}
|
|
@@ -7,6 +7,7 @@ let react = require("react");
|
|
|
7
7
|
var nodePropsFromIR = (n) => {
|
|
8
8
|
const props = { position: n.position };
|
|
9
9
|
if (n.id !== void 0) props.id = n.id;
|
|
10
|
+
if (n.shape !== void 0) props.shape = n.shape;
|
|
10
11
|
if (n.rotate !== void 0) props.rotate = n.rotate;
|
|
11
12
|
if (n.text !== void 0) props.text = n.text;
|
|
12
13
|
if (n.fontSize !== void 0) props.fontSize = n.fontSize;
|
|
@@ -18,11 +19,23 @@ var nodePropsFromIR = (n) => {
|
|
|
18
19
|
return props;
|
|
19
20
|
};
|
|
20
21
|
/** 单个 IRStep → <Step /> element */
|
|
21
|
-
var stepToElement = (step, key) =>
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
});
|
|
22
|
+
var stepToElement = (step, key) => {
|
|
23
|
+
if (step.kind === "cycle") return (0, react.createElement)(require_Step.Step, {
|
|
24
|
+
key,
|
|
25
|
+
kind: "cycle"
|
|
26
|
+
});
|
|
27
|
+
if (step.kind === "step") return (0, react.createElement)(require_Step.Step, {
|
|
28
|
+
key,
|
|
29
|
+
kind: "step",
|
|
30
|
+
via: step.via,
|
|
31
|
+
to: step.to
|
|
32
|
+
});
|
|
33
|
+
return (0, react.createElement)(require_Step.Step, {
|
|
34
|
+
key,
|
|
35
|
+
kind: step.kind,
|
|
36
|
+
to: step.to
|
|
37
|
+
});
|
|
38
|
+
};
|
|
26
39
|
/** discriminated union 兜底:编译期保证不漏 case,运行时给出明确错误 */
|
|
27
40
|
var assertNever = (x) => {
|
|
28
41
|
throw new Error(`convertIRToReactNode: unknown IR child type: ${JSON.stringify(x)}`);
|
|
@@ -39,6 +52,10 @@ var childToElement = (child, key) => {
|
|
|
39
52
|
stroke: child.stroke,
|
|
40
53
|
strokeWidth: child.strokeWidth,
|
|
41
54
|
strokeDasharray: child.strokeDasharray,
|
|
55
|
+
arrow: child.arrow,
|
|
56
|
+
arrowShape: child.arrowShape,
|
|
57
|
+
fill: child.fill,
|
|
58
|
+
fillRule: child.fillRule,
|
|
42
59
|
children: child.children.map((s, j) => stepToElement(s, j))
|
|
43
60
|
});
|
|
44
61
|
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;AA2DhE;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAAI,IAAI,EAAE,KAAG,SACW,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
2
|
+
//#region src/render/arrowMarkers.tsx
|
|
3
|
+
var MARKERS = {
|
|
4
|
+
normal: {
|
|
5
|
+
refX: 10,
|
|
6
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
7
|
+
d: "M 0 0 L 10 5 L 0 10 Z",
|
|
8
|
+
fill: "context-stroke"
|
|
9
|
+
})
|
|
10
|
+
},
|
|
11
|
+
open: {
|
|
12
|
+
refX: 1,
|
|
13
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
14
|
+
d: "M 1 1 L 9 5 L 1 9 Z",
|
|
15
|
+
fill: "none",
|
|
16
|
+
stroke: "context-stroke",
|
|
17
|
+
strokeWidth: 1.5
|
|
18
|
+
})
|
|
19
|
+
},
|
|
20
|
+
stealth: {
|
|
21
|
+
refX: 10,
|
|
22
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
23
|
+
d: "M 0 0 L 10 5 L 0 10 L 3 5 Z",
|
|
24
|
+
fill: "context-stroke"
|
|
25
|
+
})
|
|
26
|
+
},
|
|
27
|
+
diamond: {
|
|
28
|
+
refX: 10,
|
|
29
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
30
|
+
d: "M 0 5 L 5 0 L 10 5 L 5 10 Z",
|
|
31
|
+
fill: "context-stroke"
|
|
32
|
+
})
|
|
33
|
+
},
|
|
34
|
+
openDiamond: {
|
|
35
|
+
refX: 1,
|
|
36
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
37
|
+
d: "M 1 5 L 5 1 L 9 5 L 5 9 Z",
|
|
38
|
+
fill: "none",
|
|
39
|
+
stroke: "context-stroke",
|
|
40
|
+
strokeWidth: 1.5,
|
|
41
|
+
strokeLinejoin: "round"
|
|
42
|
+
})
|
|
43
|
+
},
|
|
44
|
+
circle: {
|
|
45
|
+
refX: 10,
|
|
46
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
47
|
+
cx: 5,
|
|
48
|
+
cy: 5,
|
|
49
|
+
r: 5,
|
|
50
|
+
fill: "context-stroke"
|
|
51
|
+
})
|
|
52
|
+
},
|
|
53
|
+
openCircle: {
|
|
54
|
+
refX: 0,
|
|
55
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
56
|
+
cx: 5,
|
|
57
|
+
cy: 5,
|
|
58
|
+
r: 4.25,
|
|
59
|
+
fill: "none",
|
|
60
|
+
stroke: "context-stroke",
|
|
61
|
+
strokeWidth: 1.5
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
/** 单个 `<marker>` 元素,由 `<defs>` 包起来 */
|
|
66
|
+
var ArrowMarker = ({ id, shape }) => {
|
|
67
|
+
const spec = MARKERS[shape];
|
|
68
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("marker", {
|
|
69
|
+
id,
|
|
70
|
+
viewBox: "0 0 10 10",
|
|
71
|
+
refX: spec.refX,
|
|
72
|
+
refY: 5,
|
|
73
|
+
markerWidth: 6,
|
|
74
|
+
markerHeight: 6,
|
|
75
|
+
orient: "auto-start-reverse",
|
|
76
|
+
markerUnits: "strokeWidth",
|
|
77
|
+
children: spec.children
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
//#endregion
|
|
81
|
+
exports.ArrowMarker = ArrowMarker;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { ArrowShape } from '@retikz/core';
|
|
3
|
+
export type ArrowMarkerProps = {
|
|
4
|
+
/** marker 元素 id,用于 path markerStart / markerEnd 引用 */
|
|
5
|
+
id: string;
|
|
6
|
+
/** 形状名 */
|
|
7
|
+
shape: ArrowShape;
|
|
8
|
+
};
|
|
9
|
+
/** 单个 `<marker>` 元素,由 `<defs>` 包起来 */
|
|
10
|
+
export declare const ArrowMarker: FC<ArrowMarkerProps>;
|
|
11
|
+
//# sourceMappingURL=arrowMarkers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arrowMarkers.d.ts","sourceRoot":"","sources":["../../../src/render/arrowMarkers.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAgB,MAAM,OAAO,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAqF/C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,sDAAsD;IACtD,EAAE,EAAE,MAAM,CAAC;IACX,UAAU;IACV,KAAK,EAAE,UAAU,CAAC;CACnB,CAAC;AAEF,sCAAsC;AACtC,eAAO,MAAM,WAAW,EAAE,EAAE,CAAC,gBAAgB,CAgB5C,CAAC"}
|
|
@@ -13,9 +13,9 @@ var baselineToDominant = (b) => {
|
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
15
15
|
* Scene primitive → SVG React 元素。
|
|
16
|
-
* 不读 IR,只读 Scene
|
|
16
|
+
* 不读 IR,只读 Scene。
|
|
17
17
|
*/
|
|
18
|
-
var renderPrim = (p, key) => {
|
|
18
|
+
var renderPrim = (p, key, ctx = {}) => {
|
|
19
19
|
switch (p.type) {
|
|
20
20
|
case "rect": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
|
|
21
21
|
x: p.x,
|
|
@@ -31,6 +31,22 @@ var renderPrim = (p, key) => {
|
|
|
31
31
|
ry: p.cornerRadius,
|
|
32
32
|
opacity: p.opacity
|
|
33
33
|
}, key);
|
|
34
|
+
case "ellipse": {
|
|
35
|
+
const transform = p.rotate ? `rotate(${p.rotate} ${p.cx} ${p.cy})` : void 0;
|
|
36
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ellipse", {
|
|
37
|
+
cx: p.cx,
|
|
38
|
+
cy: p.cy,
|
|
39
|
+
rx: p.rx,
|
|
40
|
+
ry: p.ry,
|
|
41
|
+
transform,
|
|
42
|
+
fill: p.fill,
|
|
43
|
+
fillOpacity: p.fillOpacity,
|
|
44
|
+
stroke: p.stroke,
|
|
45
|
+
strokeWidth: p.strokeWidth,
|
|
46
|
+
strokeDasharray: p.strokeDasharray,
|
|
47
|
+
opacity: p.opacity
|
|
48
|
+
}, key);
|
|
49
|
+
}
|
|
34
50
|
case "text": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("text", {
|
|
35
51
|
x: p.x,
|
|
36
52
|
y: p.y,
|
|
@@ -44,19 +60,26 @@ var renderPrim = (p, key) => {
|
|
|
44
60
|
opacity: p.opacity,
|
|
45
61
|
children: p.content
|
|
46
62
|
}, key);
|
|
47
|
-
case "path":
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
63
|
+
case "path": {
|
|
64
|
+
const startId = p.arrowStart && ctx.arrowMarkerIdFor ? ctx.arrowMarkerIdFor(p.arrowStart) : void 0;
|
|
65
|
+
const endId = p.arrowEnd && ctx.arrowMarkerIdFor ? ctx.arrowMarkerIdFor(p.arrowEnd) : void 0;
|
|
66
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
67
|
+
d: p.d,
|
|
68
|
+
fill: p.fill,
|
|
69
|
+
fillRule: p.fillRule,
|
|
70
|
+
stroke: p.stroke,
|
|
71
|
+
strokeWidth: p.strokeWidth,
|
|
72
|
+
strokeDasharray: p.strokeDasharray,
|
|
73
|
+
strokeLinecap: p.strokeLinecap,
|
|
74
|
+
strokeLinejoin: p.strokeLinejoin,
|
|
75
|
+
markerStart: startId ? `url(#${startId})` : void 0,
|
|
76
|
+
markerEnd: endId ? `url(#${endId})` : void 0,
|
|
77
|
+
opacity: p.opacity
|
|
78
|
+
}, key);
|
|
79
|
+
}
|
|
57
80
|
case "group": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("g", {
|
|
58
81
|
transform: p.transform,
|
|
59
|
-
children: p.children.map((c, i) => renderPrim(c, i))
|
|
82
|
+
children: p.children.map((c, i) => renderPrim(c, i, ctx))
|
|
60
83
|
}, key);
|
|
61
84
|
}
|
|
62
85
|
};
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { Key, ReactElement } from 'react';
|
|
2
|
-
import { ScenePrimitive } from '@retikz/core';
|
|
2
|
+
import { ArrowShape, ScenePrimitive } from '@retikz/core';
|
|
3
|
+
/**
|
|
4
|
+
* 渲染上下文——Tikz 容器侧把 marker id 等"全 SVG 共享"的资源向下传给 renderPrim。
|
|
5
|
+
* 资源若不存在就传 undefined,对应路径 prim 不会引用 marker。
|
|
6
|
+
*/
|
|
7
|
+
export type RenderContext = {
|
|
8
|
+
/** 按 arrow 形状查 SVG `<defs><marker id>` id 的回调 */
|
|
9
|
+
arrowMarkerIdFor?: (shape: ArrowShape) => string;
|
|
10
|
+
};
|
|
3
11
|
/**
|
|
4
12
|
* Scene primitive → SVG React 元素。
|
|
5
|
-
* 不读 IR,只读 Scene
|
|
13
|
+
* 不读 IR,只读 Scene。
|
|
6
14
|
*/
|
|
7
|
-
export declare const renderPrim: (p: ScenePrimitive, key: Key) => ReactElement;
|
|
15
|
+
export declare const renderPrim: (p: ScenePrimitive, key: Key, ctx?: RenderContext) => ReactElement;
|
|
8
16
|
//# sourceMappingURL=renderPrim.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderPrim.d.ts","sourceRoot":"","sources":["../../../src/render/renderPrim.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"renderPrim.d.ts","sourceRoot":"","sources":["../../../src/render/renderPrim.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AA6B/D;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,iDAAiD;IACjD,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,MAAM,CAAC;CAClD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,UAAU,GACrB,GAAG,cAAc,EACjB,KAAK,GAAG,EACR,MAAK,aAAkB,KACtB,YAsFF,CAAC"}
|
package/dist/lib/sugar/Draw.cjs
CHANGED
|
@@ -12,18 +12,31 @@ let react_jsx_runtime = require("react/jsx-runtime");
|
|
|
12
12
|
* (useState / useMemo / useEffect 等会抛 "Invalid hook call")。
|
|
13
13
|
*/
|
|
14
14
|
var Draw = (props) => {
|
|
15
|
-
const { way, stroke, strokeWidth, strokeDasharray } = props;
|
|
15
|
+
const { way, stroke, strokeWidth, strokeDasharray, arrow, arrowShape, fill, fillRule } = props;
|
|
16
16
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Path.Path, {
|
|
17
17
|
stroke,
|
|
18
18
|
strokeWidth,
|
|
19
19
|
strokeDasharray,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
arrow,
|
|
21
|
+
arrowShape,
|
|
22
|
+
fill,
|
|
23
|
+
fillRule,
|
|
24
|
+
children: (0, _retikz_core.parseWay)(way).map((s, i) => {
|
|
25
|
+
if (s.kind === "cycle") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Step.Step, { kind: "cycle" }, i);
|
|
26
|
+
if (s.kind === "move") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Step.Step, {
|
|
27
|
+
kind: "move",
|
|
28
|
+
to: s.to
|
|
29
|
+
}, i);
|
|
30
|
+
if (s.kind === "step") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Step.Step, {
|
|
31
|
+
kind: "step",
|
|
32
|
+
via: s.via,
|
|
33
|
+
to: s.to
|
|
34
|
+
}, i);
|
|
35
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Step.Step, {
|
|
36
|
+
kind: "line",
|
|
37
|
+
to: s.to
|
|
38
|
+
}, i);
|
|
39
|
+
})
|
|
27
40
|
});
|
|
28
41
|
};
|
|
29
42
|
//#endregion
|
package/dist/lib/sugar/Draw.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { FC } from 'react';
|
|
|
2
2
|
import { IRPath, WayDSL } from '@retikz/core';
|
|
3
3
|
/** <Draw> 组件的 props */
|
|
4
4
|
export type DrawProps = {
|
|
5
|
-
/** way 数组 DSL:节点 id
|
|
5
|
+
/** way 数组 DSL:节点 id / 坐标 / 极坐标 / 折角算子 `'-|'` `'|-'` / 闭合 `DrawWay.cycle` */
|
|
6
6
|
way: WayDSL;
|
|
7
7
|
/** 描边色,省略时用 currentColor */
|
|
8
8
|
stroke?: IRPath['stroke'];
|
|
@@ -10,6 +10,19 @@ export type DrawProps = {
|
|
|
10
10
|
strokeWidth?: IRPath['strokeWidth'];
|
|
11
11
|
/** SVG stroke-dasharray 模式(如 "4 2") */
|
|
12
12
|
strokeDasharray?: IRPath['strokeDasharray'];
|
|
13
|
+
/**
|
|
14
|
+
* 路径级箭头方向。`'->'` = 终点;`'<-'` = 起点;`'<->'` = 两端;
|
|
15
|
+
* 省略或 `'none'` = 无箭头。
|
|
16
|
+
*/
|
|
17
|
+
arrow?: IRPath['arrow'];
|
|
18
|
+
/**
|
|
19
|
+
* 箭头形状。默认 `'normal'`。其他:`'open'` / `'stealth'` / `'diamond'` / `'circle'`。
|
|
20
|
+
*/
|
|
21
|
+
arrowShape?: IRPath['arrowShape'];
|
|
22
|
+
/** 闭合区域填充色,省略 = 不填充。配合 way 末尾的 `DrawWay.cycle` 画填充形状 */
|
|
23
|
+
fill?: IRPath['fill'];
|
|
24
|
+
/** SVG fill-rule:`'nonzero'`(默认)/ `'evenodd'` */
|
|
25
|
+
fillRule?: IRPath['fillRule'];
|
|
13
26
|
};
|
|
14
27
|
/**
|
|
15
28
|
* Sugar 组件——展开为等价的 <Path><Step.../></Path> Kernel 子树。
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Draw.d.ts","sourceRoot":"","sources":["../../../src/sugar/Draw.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAKnD,uBAAuB;AACvB,MAAM,MAAM,SAAS,GAAG;IACtB,
|
|
1
|
+
{"version":3,"file":"Draw.d.ts","sourceRoot":"","sources":["../../../src/sugar/Draw.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAKnD,uBAAuB;AACvB,MAAM,MAAM,SAAS,GAAG;IACtB,4EAA4E;IAC5E,GAAG,EAAE,MAAM,CAAC;IACZ,4BAA4B;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC1B,kBAAkB;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;IACpC,uCAAuC;IACvC,eAAe,CAAC,EAAE,MAAM,CAAC,iBAAiB,CAAC,CAAC;IAC5C;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IACxB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;IAClC,wDAAwD;IACxD,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACtB,iDAAiD;IACjD,QAAQ,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;CAC/B,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,SAAS,CAsB9B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@retikz/react",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
4
|
"description": "React adapter for retikz: Kernel/Sugar JSX components and SVG renderer.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/lib/index.cjs",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"react-dom": ">=18"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@retikz/core": "0.1.0-alpha.
|
|
27
|
+
"@retikz/core": "0.1.0-alpha.1"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/node": "^25.6.0",
|