@retikz/core 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/compile/compile.js +3 -3
- package/dist/es/compile/node.d.ts +32 -6
- package/dist/es/compile/node.d.ts.map +1 -1
- package/dist/es/compile/node.js +112 -28
- package/dist/es/compile/path.d.ts +3 -2
- package/dist/es/compile/path.d.ts.map +1 -1
- package/dist/es/compile/path.js +333 -14
- package/dist/es/compile/text-metrics.d.ts +2 -2
- package/dist/es/compile/text-metrics.d.ts.map +1 -1
- package/dist/es/geometry/arc.d.ts +34 -0
- package/dist/es/geometry/arc.d.ts.map +1 -0
- package/dist/es/geometry/arc.js +53 -0
- package/dist/es/geometry/bend.d.ts +18 -0
- package/dist/es/geometry/bend.d.ts.map +1 -0
- package/dist/es/geometry/bend.js +29 -0
- package/dist/es/geometry/index.d.ts +3 -0
- package/dist/es/geometry/index.d.ts.map +1 -1
- package/dist/es/geometry/segment.d.ts +38 -0
- package/dist/es/geometry/segment.d.ts.map +1 -0
- package/dist/es/geometry/segment.js +82 -0
- package/dist/es/index.d.ts +6 -6
- package/dist/es/index.d.ts.map +1 -1
- package/dist/es/index.js +5 -4
- package/dist/es/ir/node.d.ts +286 -6
- package/dist/es/ir/node.d.ts.map +1 -1
- package/dist/es/ir/node.js +71 -5
- package/dist/es/ir/path/path.d.ts +625 -15
- package/dist/es/ir/path/path.d.ts.map +1 -1
- package/dist/es/ir/path/path.js +22 -0
- package/dist/es/ir/path/step.d.ts +872 -20
- package/dist/es/ir/path/step.d.ts.map +1 -1
- package/dist/es/ir/path/step.js +86 -4
- package/dist/es/ir/path/target.d.ts +32 -2
- package/dist/es/ir/path/target.d.ts.map +1 -1
- package/dist/es/ir/path/target.js +7 -3
- package/dist/es/ir/scene.d.ts +1836 -52
- package/dist/es/ir/scene.d.ts.map +1 -1
- package/dist/es/parsers/index.d.ts +1 -0
- package/dist/es/parsers/index.d.ts.map +1 -1
- package/dist/es/parsers/parseTargetSugar.d.ts +3 -0
- package/dist/es/parsers/parseTargetSugar.d.ts.map +1 -0
- package/dist/es/parsers/parseTargetSugar.js +31 -0
- package/dist/es/parsers/parseWay.d.ts +131 -22
- package/dist/es/parsers/parseWay.d.ts.map +1 -1
- package/dist/es/parsers/parseWay.js +149 -17
- package/dist/es/primitive/ellipse.d.ts +2 -0
- package/dist/es/primitive/ellipse.d.ts.map +1 -1
- package/dist/es/primitive/path.d.ts +4 -0
- package/dist/es/primitive/path.d.ts.map +1 -1
- package/dist/es/primitive/rect.d.ts +2 -0
- package/dist/es/primitive/rect.d.ts.map +1 -1
- package/dist/es/primitive/text.d.ts +43 -13
- package/dist/es/primitive/text.d.ts.map +1 -1
- package/dist/lib/compile/compile.cjs +3 -3
- package/dist/lib/compile/node.cjs +112 -28
- package/dist/lib/compile/node.d.ts +32 -6
- package/dist/lib/compile/node.d.ts.map +1 -1
- package/dist/lib/compile/path.cjs +333 -14
- package/dist/lib/compile/path.d.ts +3 -2
- package/dist/lib/compile/path.d.ts.map +1 -1
- package/dist/lib/compile/text-metrics.d.ts +2 -2
- package/dist/lib/compile/text-metrics.d.ts.map +1 -1
- package/dist/lib/geometry/arc.cjs +55 -0
- package/dist/lib/geometry/arc.d.ts +34 -0
- package/dist/lib/geometry/arc.d.ts.map +1 -0
- package/dist/lib/geometry/bend.cjs +29 -0
- package/dist/lib/geometry/bend.d.ts +18 -0
- package/dist/lib/geometry/bend.d.ts.map +1 -0
- package/dist/lib/geometry/index.d.ts +3 -0
- package/dist/lib/geometry/index.d.ts.map +1 -1
- package/dist/lib/geometry/segment.cjs +88 -0
- package/dist/lib/geometry/segment.d.ts +38 -0
- package/dist/lib/geometry/segment.d.ts.map +1 -0
- package/dist/lib/index.cjs +16 -0
- package/dist/lib/index.d.ts +6 -6
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/ir/node.cjs +74 -4
- package/dist/lib/ir/node.d.ts +286 -6
- package/dist/lib/ir/node.d.ts.map +1 -1
- package/dist/lib/ir/path/path.cjs +22 -0
- package/dist/lib/ir/path/path.d.ts +625 -15
- package/dist/lib/ir/path/path.d.ts.map +1 -1
- package/dist/lib/ir/path/step.cjs +93 -3
- package/dist/lib/ir/path/step.d.ts +872 -20
- package/dist/lib/ir/path/step.d.ts.map +1 -1
- package/dist/lib/ir/path/target.cjs +8 -2
- package/dist/lib/ir/path/target.d.ts +32 -2
- package/dist/lib/ir/path/target.d.ts.map +1 -1
- package/dist/lib/ir/scene.d.ts +1836 -52
- package/dist/lib/ir/scene.d.ts.map +1 -1
- package/dist/lib/parsers/index.d.ts +1 -0
- package/dist/lib/parsers/index.d.ts.map +1 -1
- package/dist/lib/parsers/parseTargetSugar.cjs +31 -0
- package/dist/lib/parsers/parseTargetSugar.d.ts +3 -0
- package/dist/lib/parsers/parseTargetSugar.d.ts.map +1 -0
- package/dist/lib/parsers/parseWay.cjs +149 -17
- package/dist/lib/parsers/parseWay.d.ts +131 -22
- package/dist/lib/parsers/parseWay.d.ts.map +1 -1
- package/dist/lib/primitive/ellipse.d.ts +2 -0
- package/dist/lib/primitive/ellipse.d.ts.map +1 -1
- package/dist/lib/primitive/path.d.ts +4 -0
- package/dist/lib/primitive/path.d.ts.map +1 -1
- package/dist/lib/primitive/rect.d.ts +2 -0
- package/dist/lib/primitive/rect.d.ts.map +1 -1
- package/dist/lib/primitive/text.d.ts +43 -13
- package/dist/lib/primitive/text.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { rect } from "../geometry/rect.js";
|
|
2
2
|
import { emitNodePrimitives, layoutNode } from "./node.js";
|
|
3
|
+
import { fallbackMeasurer } from "./text-metrics.js";
|
|
3
4
|
import { emitPathPrimitive } from "./path.js";
|
|
4
5
|
import { makeRound } from "./precision.js";
|
|
5
|
-
import { fallbackMeasurer } from "./text-metrics.js";
|
|
6
6
|
import { computeViewBox } from "./view-box.js";
|
|
7
7
|
//#region src/compile/compile.ts
|
|
8
8
|
/**
|
|
@@ -28,9 +28,9 @@ var compileToScene = (ir, options = {}) => {
|
|
|
28
28
|
allPoints.push(rect.anchor(layout.rect, "north-west"), rect.anchor(layout.rect, "north-east"), rect.anchor(layout.rect, "south-west"), rect.anchor(layout.rect, "south-east"));
|
|
29
29
|
}
|
|
30
30
|
for (const child of ir.children) if (child.type === "path") {
|
|
31
|
-
const result = emitPathPrimitive(child, nodeIndex, round);
|
|
31
|
+
const result = emitPathPrimitive(child, nodeIndex, round, measureText);
|
|
32
32
|
if (result) {
|
|
33
|
-
primitives.push(
|
|
33
|
+
for (const prim of result.primitives) primitives.push(prim);
|
|
34
34
|
for (const p of result.points) allPoints.push(p);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Position } from '../geometry/point';
|
|
2
2
|
import { Rect, RectAnchor } from '../geometry/rect';
|
|
3
3
|
import { IRNode, NodeShape } from '../ir';
|
|
4
|
-
import { ScenePrimitive } from '../primitive';
|
|
4
|
+
import { ScenePrimitive, TextLine } from '../primitive';
|
|
5
5
|
import { TextMeasurer } from './text-metrics';
|
|
6
6
|
export type NodeLayout = {
|
|
7
7
|
/** 节点 id(如 IR Node 提供);其他位置可通过 id 引用本节点 */
|
|
@@ -22,20 +22,46 @@ export type NodeLayout = {
|
|
|
22
22
|
rotateDeg: number;
|
|
23
23
|
/** 外边距(user units,≥ 0);path 附着到形状外扩 margin 的虚拟边界上 */
|
|
24
24
|
margin: number;
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
/**
|
|
26
|
+
* 节点文本行;undefined 表示无文本,否则非空数组。
|
|
27
|
+
* 每行可带覆盖样式(fill / opacity / fontSize / fontFamily / fontWeight / fontStyle);
|
|
28
|
+
* 未覆盖的字段在 emit 阶段不写出,由下游走 TextPrim 块级默认。
|
|
29
|
+
*/
|
|
30
|
+
lines?: Array<TextLine>;
|
|
31
|
+
/** 文本块宽度(user units)= max(per-line measureText.width) */
|
|
28
32
|
textWidth: number;
|
|
29
|
-
/**
|
|
33
|
+
/** 文本块高度(user units)≈ lines × lineHeight */
|
|
30
34
|
textHeight: number;
|
|
31
|
-
/**
|
|
35
|
+
/** 文本对齐(已映射到 SVG textAnchor 三态);emit 时透传给 TextPrim.align */
|
|
36
|
+
align: 'start' | 'middle' | 'end';
|
|
37
|
+
/** 行高(user units),已应用默认值;emit 时透传给 TextPrim.lineHeight */
|
|
38
|
+
lineHeight: number;
|
|
39
|
+
/** 文本字号(user units),已应用默认值 */
|
|
32
40
|
fontSize: number;
|
|
41
|
+
/** 字体族;CSS font-family;emit 时透传给 TextPrim */
|
|
42
|
+
fontFamily?: string;
|
|
43
|
+
/** 字重;emit 时透传给 TextPrim */
|
|
44
|
+
fontWeight?: string | number;
|
|
45
|
+
/** 字形:normal / italic / oblique;emit 时透传给 TextPrim */
|
|
46
|
+
fontStyle?: 'normal' | 'italic' | 'oblique';
|
|
33
47
|
/** 节点背景色,CSS 颜色字符串;emit 时用 'transparent' 兜底 */
|
|
34
48
|
fill?: string;
|
|
49
|
+
/** 节点填充透明度 0~1;透传 shape primitive */
|
|
50
|
+
fillOpacity?: number;
|
|
35
51
|
/** 节点边框色,CSS 颜色字符串;emit 时用 'currentColor' 兜底 */
|
|
36
52
|
stroke?: string;
|
|
53
|
+
/** 节点描边透明度 0~1;TikZ `draw opacity`,透传 shape primitive */
|
|
54
|
+
strokeOpacity?: number;
|
|
37
55
|
/** 节点边框宽度(user units);emit 时用 1 兜底 */
|
|
38
56
|
strokeWidth?: number;
|
|
57
|
+
/** SVG stroke-dasharray 字符串;compile 已把 dashed / dotted 预设解析为具体 pattern */
|
|
58
|
+
strokeDasharray?: string;
|
|
59
|
+
/** rectangle shape 的圆角半径(user units);非 rect shape 该字段无效 */
|
|
60
|
+
roundedCorners?: number;
|
|
61
|
+
/** 文字颜色;emit 时透传给 TextPrim.fill,兜底 'currentColor' */
|
|
62
|
+
textColor?: string;
|
|
63
|
+
/** 整节点透明度 0~1;emit 时同时挂 shape 与 text primitive */
|
|
64
|
+
opacity?: number;
|
|
39
65
|
};
|
|
40
66
|
/**
|
|
41
67
|
* 取节点 shape 在 toward 方向上的"附着点"——path 端点贴边用。
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../src/compile/node.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEzD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../src/compile/node.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEzD,OAAO,KAAK,EAAc,MAAM,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AA8BnD,MAAM,MAAM,UAAU,GAAG;IACvB,2CAA2C;IAC3C,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,8CAA8C;IAC9C,KAAK,EAAE,SAAS,CAAC;IACjB;;;;;;;;OAQG;IACH,IAAI,EAAE,IAAI,CAAC;IACX,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;IAClB,qDAAqD;IACrD,MAAM,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;IACxB,yDAAyD;IACzD,SAAS,EAAE,MAAM,CAAC;IAClB,4CAA4C;IAC5C,UAAU,EAAE,MAAM,CAAC;IACnB,4DAA4D;IAC5D,KAAK,EAAE,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAC;IAClC,0DAA0D;IAC1D,UAAU,EAAE,MAAM,CAAC;IACnB,8BAA8B;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,6CAA6C;IAC7C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4BAA4B;IAC5B,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,sDAAsD;IACtD,SAAS,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;IAC5C,+CAA+C;IAC/C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qCAAqC;IACrC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gDAAgD;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,yDAAyD;IACzD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,sCAAsC;IACtC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0EAA0E;IAC1E,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,2DAA2D;IAC3D,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,qDAAqD;IACrD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kDAAkD;IAClD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAsCF;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,UAAU,EAAE,QAAQ,QAAQ,KAAG,QAYtE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GAAI,QAAQ,UAAU,EAAE,MAAM,UAAU,KAAG,QAW/D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,UAAU,EAAE,UAAU,MAAM,KAAG,QActE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,GACrB,MAAM,MAAM,EACZ,aAAa,YAAY,EACzB,WAAW,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,KACjC,UAgJF,CAAC;AAsEF;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,GAC7B,QAAQ,UAAU,EAClB,OAAO,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,KAC3B,KAAK,CAAC,cAAc,CAoDtB,CAAC"}
|
package/dist/es/compile/node.js
CHANGED
|
@@ -6,8 +6,21 @@ import { resolvePosition } from "./position.js";
|
|
|
6
6
|
//#region src/compile/node.ts
|
|
7
7
|
var DEFAULT_FONT_SIZE = 14;
|
|
8
8
|
var DEFAULT_PADDING = 8;
|
|
9
|
+
var DEFAULT_LINE_HEIGHT_FACTOR = 1.2;
|
|
9
10
|
var DEG_TO_RAD = Math.PI / 180;
|
|
10
11
|
var SQRT2 = Math.SQRT2;
|
|
12
|
+
/** dashed 预设:SVG stroke-dasharray "4 2"——4 px 实线 + 2 px 间隙循环 */
|
|
13
|
+
var DASHED_PATTERN = "4 2";
|
|
14
|
+
/** dotted 预设:SVG stroke-dasharray "1 2"——1 px 圆点 + 2 px 间隙 */
|
|
15
|
+
var DOTTED_PATTERN = "1 2";
|
|
16
|
+
/** 解析 dashed / dotted / dashArray 优先级:dashArray > dashed > dotted */
|
|
17
|
+
var resolveDashArray = (dashArray, dashed, dotted) => {
|
|
18
|
+
if (dashArray !== void 0) return dashArray;
|
|
19
|
+
if (dashed) return DASHED_PATTERN;
|
|
20
|
+
if (dotted) return DOTTED_PATTERN;
|
|
21
|
+
};
|
|
22
|
+
/** IR `align` ('left' | 'center' | 'right') → SVG textAnchor ('start' | 'middle' | 'end') */
|
|
23
|
+
var alignToTextAnchor = (a) => a === "left" ? "start" : a === "right" ? "end" : "middle";
|
|
11
24
|
/** 由 layout 构造的 Rect(带 margin 扩张) */
|
|
12
25
|
var rectOf = (layout, marginAdd) => ({
|
|
13
26
|
x: layout.rect.x,
|
|
@@ -90,14 +103,52 @@ var angleBoundaryOf = (layout, angleDeg) => {
|
|
|
90
103
|
* - 透传 margin / 样式属性
|
|
91
104
|
*/
|
|
92
105
|
var layoutNode = (node, measureText, nodeIndex) => {
|
|
93
|
-
const
|
|
94
|
-
const
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
const
|
|
106
|
+
const sx = node.xScale ?? node.scale ?? 1;
|
|
107
|
+
const sy = node.yScale ?? node.scale ?? 1;
|
|
108
|
+
const fontScale = Math.min(sx, sy);
|
|
109
|
+
const baseFontSize = node.font?.size ?? DEFAULT_FONT_SIZE;
|
|
110
|
+
const fontSize = baseFontSize * fontScale;
|
|
111
|
+
const fontFamily = node.font?.family;
|
|
112
|
+
const fontWeight = node.font?.weight;
|
|
113
|
+
const fontStyle = node.font?.style;
|
|
114
|
+
const xSep = (node.innerXSep ?? node.padding ?? DEFAULT_PADDING) * sx;
|
|
115
|
+
const ySep = (node.innerYSep ?? node.padding ?? DEFAULT_PADDING) * sy;
|
|
116
|
+
const outerSep = (node.outerSep ?? node.margin ?? 0) * Math.max(sx, sy);
|
|
117
|
+
const lineHeight = (node.lineHeight ?? baseFontSize * DEFAULT_LINE_HEIGHT_FACTOR) * sy;
|
|
118
|
+
const align = alignToTextAnchor(node.align ?? "center");
|
|
119
|
+
const rawLines = node.text === void 0 ? void 0 : typeof node.text === "string" ? [node.text] : node.text;
|
|
120
|
+
let textWidth = 0;
|
|
121
|
+
let textHeight = 0;
|
|
122
|
+
let lines;
|
|
123
|
+
if (rawLines) {
|
|
124
|
+
lines = rawLines.map((spec) => {
|
|
125
|
+
const isObj = typeof spec !== "string";
|
|
126
|
+
const text = isObj ? spec.text : spec;
|
|
127
|
+
const lineFont = isObj ? spec.font : void 0;
|
|
128
|
+
const m = measureText(text, {
|
|
129
|
+
size: lineFont?.size ?? fontSize,
|
|
130
|
+
family: lineFont?.family ?? fontFamily,
|
|
131
|
+
weight: lineFont?.weight ?? fontWeight,
|
|
132
|
+
style: lineFont?.style ?? fontStyle
|
|
133
|
+
});
|
|
134
|
+
if (m.width > textWidth) textWidth = m.width;
|
|
135
|
+
const out = { text };
|
|
136
|
+
if (isObj) {
|
|
137
|
+
if (spec.fill !== void 0) out.fill = spec.fill;
|
|
138
|
+
if (spec.opacity !== void 0) out.opacity = spec.opacity;
|
|
139
|
+
if (lineFont?.size !== void 0) out.fontSize = lineFont.size;
|
|
140
|
+
if (lineFont?.family !== void 0) out.fontFamily = lineFont.family;
|
|
141
|
+
if (lineFont?.weight !== void 0) out.fontWeight = lineFont.weight;
|
|
142
|
+
if (lineFont?.style !== void 0) out.fontStyle = lineFont.style;
|
|
143
|
+
}
|
|
144
|
+
return out;
|
|
145
|
+
});
|
|
146
|
+
textHeight = lines.length * lineHeight;
|
|
147
|
+
}
|
|
148
|
+
const minW = node.minimumWidth ?? node.minimumSize ?? 0;
|
|
149
|
+
const minH = node.minimumHeight ?? node.minimumSize ?? 0;
|
|
150
|
+
const innerHalfW = Math.max(textWidth / 2 + xSep, xSep, minW / 2);
|
|
151
|
+
const innerHalfH = Math.max(textHeight / 2 + ySep, ySep, minH / 2);
|
|
101
152
|
const shape = node.shape ?? "rectangle";
|
|
102
153
|
let boundsHalfW;
|
|
103
154
|
let boundsHalfH;
|
|
@@ -135,14 +186,25 @@ var layoutNode = (node, measureText, nodeIndex) => {
|
|
|
135
186
|
rotate: rotateDeg * DEG_TO_RAD
|
|
136
187
|
},
|
|
137
188
|
rotateDeg,
|
|
138
|
-
margin:
|
|
139
|
-
|
|
140
|
-
textWidth
|
|
141
|
-
textHeight
|
|
189
|
+
margin: outerSep,
|
|
190
|
+
lines,
|
|
191
|
+
textWidth,
|
|
192
|
+
textHeight,
|
|
193
|
+
align,
|
|
194
|
+
lineHeight,
|
|
142
195
|
fontSize,
|
|
196
|
+
fontFamily,
|
|
197
|
+
fontWeight,
|
|
198
|
+
fontStyle,
|
|
143
199
|
fill: node.fill,
|
|
200
|
+
fillOpacity: node.fillOpacity,
|
|
144
201
|
stroke: node.stroke,
|
|
145
|
-
|
|
202
|
+
strokeOpacity: node.drawOpacity,
|
|
203
|
+
strokeWidth: node.strokeWidth,
|
|
204
|
+
strokeDasharray: resolveDashArray(node.dashArray, node.dashed, node.dotted),
|
|
205
|
+
roundedCorners: node.roundedCorners,
|
|
206
|
+
textColor: node.textColor,
|
|
207
|
+
opacity: node.opacity
|
|
146
208
|
};
|
|
147
209
|
};
|
|
148
210
|
/** rectangle shape 的 RectPrim */
|
|
@@ -156,8 +218,13 @@ var emitRectShape = (layout, round) => {
|
|
|
156
218
|
width: round(layout.rect.width),
|
|
157
219
|
height: round(layout.rect.height),
|
|
158
220
|
fill: layout.fill ?? "transparent",
|
|
221
|
+
fillOpacity: layout.fillOpacity,
|
|
159
222
|
stroke: layout.stroke ?? "currentColor",
|
|
160
|
-
|
|
223
|
+
strokeOpacity: layout.strokeOpacity,
|
|
224
|
+
strokeWidth: layout.strokeWidth ?? 1,
|
|
225
|
+
strokeDasharray: layout.strokeDasharray,
|
|
226
|
+
cornerRadius: layout.roundedCorners,
|
|
227
|
+
opacity: layout.opacity
|
|
161
228
|
};
|
|
162
229
|
};
|
|
163
230
|
/** circle / ellipse shape 的 EllipsePrim(圆形 rx=ry) */
|
|
@@ -168,8 +235,12 @@ var emitEllipseShape = (layout, round) => ({
|
|
|
168
235
|
rx: round(layout.rect.width / 2),
|
|
169
236
|
ry: round(layout.rect.height / 2),
|
|
170
237
|
fill: layout.fill ?? "transparent",
|
|
238
|
+
fillOpacity: layout.fillOpacity,
|
|
171
239
|
stroke: layout.stroke ?? "currentColor",
|
|
172
|
-
|
|
240
|
+
strokeOpacity: layout.strokeOpacity,
|
|
241
|
+
strokeWidth: layout.strokeWidth ?? 1,
|
|
242
|
+
strokeDasharray: layout.strokeDasharray,
|
|
243
|
+
opacity: layout.opacity
|
|
173
244
|
});
|
|
174
245
|
/** diamond shape 的 PathPrim(4 顶点 + Z 闭合) */
|
|
175
246
|
var emitDiamondShape = (layout, round) => {
|
|
@@ -182,8 +253,12 @@ var emitDiamondShape = (layout, round) => {
|
|
|
182
253
|
type: "path",
|
|
183
254
|
d: `M ${round(e[0])} ${round(e[1])} L ${round(n[0])} ${round(n[1])} L ${round(w[0])} ${round(w[1])} L ${round(s[0])} ${round(s[1])} Z`,
|
|
184
255
|
fill: layout.fill ?? "transparent",
|
|
256
|
+
fillOpacity: layout.fillOpacity,
|
|
185
257
|
stroke: layout.stroke ?? "currentColor",
|
|
186
|
-
|
|
258
|
+
strokeOpacity: layout.strokeOpacity,
|
|
259
|
+
strokeWidth: layout.strokeWidth ?? 1,
|
|
260
|
+
strokeDasharray: layout.strokeDasharray,
|
|
261
|
+
opacity: layout.opacity
|
|
187
262
|
};
|
|
188
263
|
};
|
|
189
264
|
/**
|
|
@@ -209,18 +284,27 @@ var emitNodePrimitives = (layout, round) => {
|
|
|
209
284
|
break;
|
|
210
285
|
}
|
|
211
286
|
const inner = [shapePrim];
|
|
212
|
-
if (layout.
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
287
|
+
if (layout.lines) {
|
|
288
|
+
const halfBlockW = layout.textWidth / 2;
|
|
289
|
+
const xOffset = layout.align === "start" ? -halfBlockW : layout.align === "end" ? halfBlockW : 0;
|
|
290
|
+
inner.push({
|
|
291
|
+
type: "text",
|
|
292
|
+
x: round(layout.rect.x + xOffset),
|
|
293
|
+
y: round(layout.rect.y),
|
|
294
|
+
lines: layout.lines,
|
|
295
|
+
fontSize: layout.fontSize,
|
|
296
|
+
fontFamily: layout.fontFamily,
|
|
297
|
+
fontWeight: layout.fontWeight,
|
|
298
|
+
fontStyle: layout.fontStyle,
|
|
299
|
+
align: layout.align,
|
|
300
|
+
baseline: "middle",
|
|
301
|
+
lineHeight: round(layout.lineHeight),
|
|
302
|
+
fill: layout.textColor ?? "currentColor",
|
|
303
|
+
opacity: layout.opacity,
|
|
304
|
+
measuredWidth: round(layout.textWidth),
|
|
305
|
+
measuredHeight: round(layout.textHeight)
|
|
306
|
+
});
|
|
307
|
+
}
|
|
224
308
|
if (layout.rotateDeg === 0) return inner;
|
|
225
309
|
return [{
|
|
226
310
|
type: "group",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IRPath, IRPosition } from '../ir';
|
|
2
2
|
import { ScenePrimitive } from '../primitive';
|
|
3
3
|
import { NodeLayout } from './node';
|
|
4
|
+
import { TextMeasurer } from './text-metrics';
|
|
4
5
|
/**
|
|
5
6
|
* 把 IR Path 翻译为单个 PathPrim。
|
|
6
7
|
*
|
|
@@ -22,8 +23,8 @@ import { NodeLayout } from './node';
|
|
|
22
23
|
*
|
|
23
24
|
* 引用未定义节点 / 解析失败时返回 null(path 整体跳过)。
|
|
24
25
|
*/
|
|
25
|
-
export declare const emitPathPrimitive: (path: IRPath, nodeIndex: Map<string, NodeLayout>, round: (n: number) => number) => {
|
|
26
|
-
|
|
26
|
+
export declare const emitPathPrimitive: (path: IRPath, nodeIndex: Map<string, NodeLayout>, round: (n: number) => number, measureText?: TextMeasurer) => {
|
|
27
|
+
primitives: Array<ScenePrimitive>;
|
|
27
28
|
points: Array<IRPosition>;
|
|
28
29
|
} | null;
|
|
29
30
|
//# sourceMappingURL=path.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../../src/compile/path.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../../src/compile/path.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAEV,MAAM,EACN,UAAU,EAIX,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAY,cAAc,EAAY,MAAM,cAAc,CAAC;AACvE,OAAO,EAAE,KAAK,UAAU,EAA8C,MAAM,QAAQ,CAAC;AAGrF,OAAO,EAAE,KAAK,YAAY,EAAoB,MAAM,gBAAgB,CAAC;AAoWrE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,iBAAiB,GAC5B,MAAM,MAAM,EACZ,WAAW,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,EAClC,OAAO,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,EAC5B,cAAa,YAA+B,KAC3C;IAAE,UAAU,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;IAAC,MAAM,EAAE,KAAK,CAAC,UAAU,CAAC,CAAA;CAAE,GAAG,IA8arE,CAAC"}
|