@retikz/core 0.2.0-alpha.6 → 0.2.0-alpha.7
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.d.ts.map +1 -1
- package/dist/es/compile/compile.js +10 -4
- package/dist/es/compile/node.d.ts +19 -4
- package/dist/es/compile/node.d.ts.map +1 -1
- package/dist/es/compile/node.js +159 -29
- package/dist/es/compile/paint.d.ts +16 -0
- package/dist/es/compile/paint.d.ts.map +1 -0
- package/dist/es/compile/paint.js +37 -0
- package/dist/es/compile/path/index.d.ts +3 -0
- package/dist/es/compile/path/index.d.ts.map +1 -1
- package/dist/es/compile/path/index.js +2 -1
- package/dist/es/index.d.ts +3 -3
- package/dist/es/index.d.ts.map +1 -1
- package/dist/es/index.js +2 -1
- package/dist/es/ir/index.d.ts +1 -0
- package/dist/es/ir/index.d.ts.map +1 -1
- package/dist/es/ir/node.d.ts +262 -9
- package/dist/es/ir/node.d.ts.map +1 -1
- package/dist/es/ir/node.js +9 -2
- package/dist/es/ir/paint.d.ts +132 -0
- package/dist/es/ir/paint.d.ts.map +1 -0
- package/dist/es/ir/paint.js +53 -0
- package/dist/es/ir/path/arrow.d.ts +24 -24
- package/dist/es/ir/path/path.d.ts +198 -37
- package/dist/es/ir/path/path.d.ts.map +1 -1
- package/dist/es/ir/path/path.js +2 -1
- package/dist/es/ir/scope.d.ts +1187 -165
- package/dist/es/ir/scope.d.ts.map +1 -1
- package/dist/es/ir/scope.js +2 -1
- package/dist/es/primitive/ellipse.d.ts +3 -5
- package/dist/es/primitive/ellipse.d.ts.map +1 -1
- package/dist/es/primitive/paint.d.ts +24 -0
- package/dist/es/primitive/paint.d.ts.map +1 -0
- package/dist/es/primitive/path.d.ts +3 -2
- package/dist/es/primitive/path.d.ts.map +1 -1
- package/dist/es/primitive/rect.d.ts +3 -2
- package/dist/es/primitive/rect.d.ts.map +1 -1
- package/dist/es/primitive/scene.d.ts +4 -0
- package/dist/es/primitive/scene.d.ts.map +1 -1
- package/dist/es/shapes/types.d.ts +2 -2
- package/dist/es/shapes/types.d.ts.map +1 -1
- package/dist/lib/compile/compile.cjs +9 -3
- package/dist/lib/compile/compile.d.ts.map +1 -1
- package/dist/lib/compile/node.cjs +159 -28
- package/dist/lib/compile/node.d.ts +19 -4
- package/dist/lib/compile/node.d.ts.map +1 -1
- package/dist/lib/compile/paint.cjs +37 -0
- package/dist/lib/compile/paint.d.ts +16 -0
- package/dist/lib/compile/paint.d.ts.map +1 -0
- package/dist/lib/compile/path/index.cjs +2 -1
- package/dist/lib/compile/path/index.d.ts +3 -0
- package/dist/lib/compile/path/index.d.ts.map +1 -1
- package/dist/lib/index.cjs +3 -0
- package/dist/lib/index.d.ts +3 -3
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/ir/index.d.ts +1 -0
- package/dist/lib/ir/index.d.ts.map +1 -1
- package/dist/lib/ir/node.cjs +9 -2
- package/dist/lib/ir/node.d.ts +262 -9
- package/dist/lib/ir/node.d.ts.map +1 -1
- package/dist/lib/ir/paint.cjs +54 -0
- package/dist/lib/ir/paint.d.ts +132 -0
- package/dist/lib/ir/paint.d.ts.map +1 -0
- package/dist/lib/ir/path/arrow.d.ts +24 -24
- package/dist/lib/ir/path/path.cjs +2 -1
- package/dist/lib/ir/path/path.d.ts +198 -37
- package/dist/lib/ir/path/path.d.ts.map +1 -1
- package/dist/lib/ir/scope.cjs +2 -1
- package/dist/lib/ir/scope.d.ts +1187 -165
- package/dist/lib/ir/scope.d.ts.map +1 -1
- package/dist/lib/primitive/ellipse.d.ts +3 -5
- package/dist/lib/primitive/ellipse.d.ts.map +1 -1
- package/dist/lib/primitive/paint.d.ts +24 -0
- package/dist/lib/primitive/paint.d.ts.map +1 -0
- package/dist/lib/primitive/path.d.ts +3 -2
- package/dist/lib/primitive/path.d.ts.map +1 -1
- package/dist/lib/primitive/rect.d.ts +3 -2
- package/dist/lib/primitive/rect.d.ts.map +1 -1
- package/dist/lib/primitive/scene.d.ts +4 -0
- package/dist/lib/primitive/scene.d.ts.map +1 -1
- package/dist/lib/shapes/types.d.ts +2 -2
- package/dist/lib/shapes/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../../src/compile/compile.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAwC,MAAM,OAAO,CAAC;AACtE,OAAO,KAAK,EAAa,KAAK,EAA6B,MAAM,cAAc,CAAC;AAEhF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../../src/compile/compile.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAwC,MAAM,OAAO,CAAC;AACtE,OAAO,KAAK,EAAa,KAAK,EAA6B,MAAM,cAAc,CAAC;AAEhF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAqBjD,OAAO,EAAE,KAAK,YAAY,EAAoB,MAAM,gBAAgB,CAAC;AA4CrE,uEAAuE;AACvE,MAAM,MAAM,cAAc,GAAG;IAC3B;;;OAGG;IACH,IAAI,EACA,2BAA2B,GAC3B,gBAAgB,GAChB,0BAA0B,GAC1B,wBAAwB,GACxB,yBAAyB,GACzB,sBAAsB,GACtB,8BAA8B,GAC9B,oBAAoB,GACpB,mBAAmB,GACnB,yBAAyB,GACzB,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;IAClB,iBAAiB;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,mEAAmE;IACnE,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,2BAA2B;AAC3B,MAAM,MAAM,cAAc,GAAG;IAC3B,oCAAoC;IACpC,WAAW,CAAC,EAAE,YAAY,CAAC;IAC3B,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;IAC3C;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;CAC1C,CAAC;AA6FF;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAI,IAAI,EAAE,EAAE,UAAS,cAAmB,KAAG,KAoSrE,CAAC"}
|
|
@@ -3,7 +3,8 @@ import { BUILTIN_SHAPES } from "../shapes/index.js";
|
|
|
3
3
|
import { NameStack } from "./name-stack.js";
|
|
4
4
|
import { applyTransformChain, computeScopeBoundingBox, lowerScopeTransforms, projectLayoutToGlobal, registerScopeAsLayout } from "./scope.js";
|
|
5
5
|
import { resolvePosition } from "./position.js";
|
|
6
|
-
import { emitNodePrimitives, layoutNode } from "./node.js";
|
|
6
|
+
import { emitNodePrimitives, labelExtentPoints, layoutNode } from "./node.js";
|
|
7
|
+
import { createPaintRegistry } from "./paint.js";
|
|
7
8
|
import { fallbackMeasurer } from "./text-metrics.js";
|
|
8
9
|
import { emitPathPrimitive } from "./path/index.js";
|
|
9
10
|
import { makeRound } from "./precision.js";
|
|
@@ -133,6 +134,7 @@ var compileToScene = (ir, options = {}) => {
|
|
|
133
134
|
};
|
|
134
135
|
const nameStack = new NameStack({ onDuplicate: (info) => onWarn(formatDuplicateWarning(info)) });
|
|
135
136
|
const allPoints = [];
|
|
137
|
+
const paint = createPaintRegistry();
|
|
136
138
|
/**
|
|
137
139
|
* 解析一批本层收集的 pending paths(lookup-only 阶段)
|
|
138
140
|
* @description 两种落点:有 `slot`(scopeChain 为空)→ 原位 splice 回填该 path 在本层 sink 占的位(按引用定位免索引漂移),保住与同层 node 的 IR 声明序;无 `slot`(scopeChain 非空)→ hoist 到顶层 `primitives`,因端点已是全局坐标、进 transformed GroupPrim 会被 scope.transform 二次 apply。NameStack 切到 pass2 守门:path 解析中误调 register 抛 internal error;解析完切回 pass1 让上层 scope 子树继续 register 子节点。
|
|
@@ -147,7 +149,8 @@ var compileToScene = (ir, options = {}) => {
|
|
|
147
149
|
const result = emitPathPrimitive(item.path, nameStack, round, measureText, {
|
|
148
150
|
onWarn,
|
|
149
151
|
irPath: item.irPath,
|
|
150
|
-
scopeChain: item.scopeChain
|
|
152
|
+
scopeChain: item.scopeChain,
|
|
153
|
+
resolveFill: paint.resolve
|
|
151
154
|
});
|
|
152
155
|
if (item.slot) {
|
|
153
156
|
const idx = item.slot.sink.indexOf(item.slot.placeholder);
|
|
@@ -184,11 +187,12 @@ var compileToScene = (ir, options = {}) => {
|
|
|
184
187
|
const layout = layoutNode(resolveNodeStyle(child, styleStack), measureText, nameStack, nodeDistance, chain, resolveLabelDefault(styleStack), effectiveShapes);
|
|
185
188
|
const globalLayout = chain.length === 0 ? layout : projectLayoutToGlobal(layout, chain);
|
|
186
189
|
if (child.id) nameStack.register(child.id, globalLayout, `${locatorPrefix}children[${i}].node.id`);
|
|
187
|
-
for (const prim of emitNodePrimitives(layout, round)) {
|
|
190
|
+
for (const prim of emitNodePrimitives(layout, round, paint.resolve)) {
|
|
188
191
|
sink.push(prim);
|
|
189
192
|
if (child.zIndex !== void 0) zIndexOf.set(prim, child.zIndex);
|
|
190
193
|
}
|
|
191
194
|
allPoints.push(rect.anchor(globalLayout.rect, "north-west"), rect.anchor(globalLayout.rect, "north-east"), rect.anchor(globalLayout.rect, "south-west"), rect.anchor(globalLayout.rect, "south-east"));
|
|
195
|
+
for (const p of labelExtentPoints(globalLayout)) allPoints.push(p);
|
|
192
196
|
layoutsAccumulator.push(globalLayout);
|
|
193
197
|
} else if (child.type === "coordinate") {
|
|
194
198
|
const localCenter = resolvePosition(child.position, nameStack, nodeDistance, chain);
|
|
@@ -272,9 +276,11 @@ var compileToScene = (ir, options = {}) => {
|
|
|
272
276
|
const detail = typeof process !== "undefined" && process.env.NODE_ENV !== "production" ? ` at ${collectPlaceholderLocators(primitives).join(", ")}` : "";
|
|
273
277
|
throw new Error(`internal: ${placeholderBalance} unresolved path placeholder(s) leaked into Scene output${detail}`);
|
|
274
278
|
}
|
|
279
|
+
const resources = paint.resources();
|
|
275
280
|
return {
|
|
276
281
|
primitives: stableSortByZIndex(sealSink(primitives)),
|
|
277
|
-
layout: computeLayout(allPoints, layoutPadding, round)
|
|
282
|
+
layout: computeLayout(allPoints, layoutPadding, round),
|
|
283
|
+
...resources.length > 0 ? { resources } : {}
|
|
278
284
|
};
|
|
279
285
|
};
|
|
280
286
|
//#endregion
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Position } from '../geometry/point';
|
|
2
2
|
import { Rect } from '../geometry/rect';
|
|
3
|
-
import { AtDirection, IRLabelDefault, IRNode } from '../ir';
|
|
3
|
+
import { AtDirection, IRLabelDefault, IRNode, IRPaintSpec } from '../ir';
|
|
4
|
+
import { PaintResolver } from './paint';
|
|
4
5
|
import { ScenePrimitive, TextLine, Transform } from '../primitive';
|
|
5
6
|
import { ShapeDefinition } from '../shapes';
|
|
6
7
|
import { NameStack } from './name-stack';
|
|
@@ -42,8 +43,8 @@ export type NodeLayout = {
|
|
|
42
43
|
fontWeight?: string | number;
|
|
43
44
|
/** 字形 */
|
|
44
45
|
fontStyle?: 'normal' | 'italic' | 'oblique';
|
|
45
|
-
/**
|
|
46
|
-
fill?: string;
|
|
46
|
+
/** 节点背景填充(纯色 / PaintSpec gradient),emit 时经 resolveFill → PaintValue、'transparent' 兜底 */
|
|
47
|
+
fill?: string | IRPaintSpec;
|
|
47
48
|
/** 填充透明度 0~1 */
|
|
48
49
|
fillOpacity?: number;
|
|
49
50
|
/** 节点边框色,emit 时 'currentColor' 兜底 */
|
|
@@ -83,6 +84,14 @@ export type NodeLabelLayout = {
|
|
|
83
84
|
rotate?: 'none' | 'radial' | 'tangent' | number;
|
|
84
85
|
/** 自旋后若文字倒置则翻 180°;缺省 false */
|
|
85
86
|
keepUpright?: boolean;
|
|
87
|
+
/** label 文本测量宽度(pin leader 算 label 框近边用) */
|
|
88
|
+
measuredWidth: number;
|
|
89
|
+
/** pin:true = 默认引线;对象 = 带样式引线(stroke / strokeWidth / dashPattern);缺省 / false = 无引线 */
|
|
90
|
+
pin?: boolean | {
|
|
91
|
+
stroke?: string;
|
|
92
|
+
strokeWidth?: number;
|
|
93
|
+
dashPattern?: Array<number>;
|
|
94
|
+
};
|
|
86
95
|
};
|
|
87
96
|
/**
|
|
88
97
|
* 取节点 shape 在 toward 方向的附着点(path 端点贴边用)
|
|
@@ -113,5 +122,11 @@ export declare const layoutNode: (node: IRNode, measureText: TextMeasurer, nameS
|
|
|
113
122
|
* @description shape 主体走 `shapeDef.emit`(收轴对齐 rect、可出多 primitive);text 始终走 TextPrim;
|
|
114
123
|
* 有旋转时外层 GroupPrim 用 `rotate(deg cx cy)` 统一包裹 shape + text(diamond 顶点 / text 都靠 group 旋转)
|
|
115
124
|
*/
|
|
116
|
-
|
|
125
|
+
/**
|
|
126
|
+
* 节点 label 的外接点(供顶层 bbox / viewBox 计算,让 label 不被裁——与 step.label 进 bbox 一致)
|
|
127
|
+
* @description 每个 label 取其文本框四角;label 中心走 labelCenter(轴对齐系),node 自身 rotate 时绕 node 中心旋转
|
|
128
|
+
* (与 emit 的 group rotate 同步)。pin 引线起点在 node 边界内、已被 node 四角覆盖,无需额外。
|
|
129
|
+
*/
|
|
130
|
+
export declare const labelExtentPoints: (layout: NodeLayout) => Array<Position>;
|
|
131
|
+
export declare const emitNodePrimitives: (layout: NodeLayout, round: (n: number) => number, resolveFill: PaintResolver) => Array<ScenePrimitive>;
|
|
117
132
|
//# sourceMappingURL=node.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../src/compile/node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO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}
|
package/dist/es/compile/node.js
CHANGED
|
@@ -5,6 +5,49 @@ var DEFAULT_FONT_SIZE = 14;
|
|
|
5
5
|
var DEFAULT_PADDING = 8;
|
|
6
6
|
var DEFAULT_LINE_HEIGHT_FACTOR = 1.2;
|
|
7
7
|
var DEG_TO_RAD = Math.PI / 180;
|
|
8
|
+
/** CJK / fullwidth ranges: break per-character (no whitespace needed) */
|
|
9
|
+
var isCjk = (ch) => {
|
|
10
|
+
const c = ch.codePointAt(0) ?? 0;
|
|
11
|
+
return c >= 12288 && c <= 12351 || c >= 12352 && c <= 12543 || c >= 13312 && c <= 19903 || c >= 19968 && c <= 40959 || c >= 63744 && c <= 64255 || c >= 65280 && c <= 65519;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* 按 maxWidth 贪心折行:西文按词(空白分割)、CJK 按字;长不可断 token 溢出不硬断
|
|
15
|
+
* @description 用注入的 measureText 度量;连续空白归一为单空格分隔。空文本返回 [''].
|
|
16
|
+
*/
|
|
17
|
+
var wrapText = (text, font, maxWidth, measure) => {
|
|
18
|
+
const units = [];
|
|
19
|
+
for (const seg of text.split(/(\s+)/)) {
|
|
20
|
+
if (seg === "") continue;
|
|
21
|
+
if (/^\s+$/.test(seg)) {
|
|
22
|
+
units.push(" ");
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
let run = "";
|
|
26
|
+
for (const ch of seg) if (isCjk(ch)) {
|
|
27
|
+
if (run) {
|
|
28
|
+
units.push(run);
|
|
29
|
+
run = "";
|
|
30
|
+
}
|
|
31
|
+
units.push(ch);
|
|
32
|
+
} else run += ch;
|
|
33
|
+
if (run) units.push(run);
|
|
34
|
+
}
|
|
35
|
+
const lines = [];
|
|
36
|
+
let cur = "";
|
|
37
|
+
for (const u of units) {
|
|
38
|
+
if (u === " ") {
|
|
39
|
+
if (cur !== "") cur += " ";
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const candidate = cur === "" ? u : cur + u;
|
|
43
|
+
if (cur !== "" && measure(candidate, font).width > maxWidth) {
|
|
44
|
+
lines.push(cur.trimEnd());
|
|
45
|
+
cur = u;
|
|
46
|
+
} else cur = candidate;
|
|
47
|
+
}
|
|
48
|
+
if (cur.trimEnd() !== "") lines.push(cur.trimEnd());
|
|
49
|
+
return lines.length > 0 ? lines : [""];
|
|
50
|
+
};
|
|
8
51
|
/** Node label 与 node 边界默认距离(TikZ 默认 0pt 视觉太贴) */
|
|
9
52
|
var DEFAULT_LABEL_DISTANCE = 12;
|
|
10
53
|
/** dashed 预设:4 px 实线 + 2 px 间隙循环 */
|
|
@@ -84,7 +127,8 @@ var LABEL_DIRECTION_MAP = {
|
|
|
84
127
|
* 若用带 rotate 的 rect,label 位置会被 anchorOf / angleBoundaryOf 旋转一次、再被外层 group 旋转一次(双重旋转)。
|
|
85
128
|
* anchorOf / angleBoundaryOf 本身不改(path anchor `'A.north'` / `'A.30'` 仍需带 rotate 的 rect)。
|
|
86
129
|
*/
|
|
87
|
-
|
|
130
|
+
/** label 在 node 边界上的附着点(未旋转局部系;pin 引线起点 = 此点) */
|
|
131
|
+
var labelBorderPoint = (layout, label) => {
|
|
88
132
|
const aaLayout = {
|
|
89
133
|
...layout,
|
|
90
134
|
rect: {
|
|
@@ -92,15 +136,32 @@ var labelCenter = (layout, label) => {
|
|
|
92
136
|
rotate: 0
|
|
93
137
|
}
|
|
94
138
|
};
|
|
139
|
+
if (typeof label.position === "number") return angleBoundaryOf(aaLayout, label.position);
|
|
140
|
+
const { anchor } = LABEL_DIRECTION_MAP[label.position];
|
|
141
|
+
return anchorOf(aaLayout, anchor);
|
|
142
|
+
};
|
|
143
|
+
var labelCenter = (layout, label) => {
|
|
144
|
+
const [bx, by] = labelBorderPoint(layout, label);
|
|
95
145
|
if (typeof label.position === "number") {
|
|
96
146
|
const rad = label.position * Math.PI / 180;
|
|
97
|
-
const [bx, by] = angleBoundaryOf(aaLayout, label.position);
|
|
98
147
|
return [bx + Math.cos(rad) * label.distance, by + Math.sin(rad) * label.distance];
|
|
99
148
|
}
|
|
100
|
-
const {
|
|
101
|
-
const [bx, by] = anchorOf(aaLayout, anchor);
|
|
149
|
+
const { vec } = LABEL_DIRECTION_MAP[label.position];
|
|
102
150
|
return [bx + vec[0] * label.distance, by + vec[1] * label.distance];
|
|
103
151
|
};
|
|
152
|
+
/** 从 label 中心朝 border 方向,求 label 框(halfW×halfH)边界交点(pin 引线终点 = label 框近 node 边) */
|
|
153
|
+
var labelBoxEdgeToward = (center, border, halfW, halfH) => {
|
|
154
|
+
const dx = border[0] - center[0];
|
|
155
|
+
const dy = border[1] - center[1];
|
|
156
|
+
const len = Math.hypot(dx, dy);
|
|
157
|
+
if (len < 1e-9) return center;
|
|
158
|
+
const ux = dx / len;
|
|
159
|
+
const uy = dy / len;
|
|
160
|
+
const sx = Math.abs(ux) > 1e-9 ? halfW / Math.abs(ux) : Number.POSITIVE_INFINITY;
|
|
161
|
+
const sy = Math.abs(uy) > 1e-9 ? halfH / Math.abs(uy) : Number.POSITIVE_INFINITY;
|
|
162
|
+
const s = Math.min(sx, sy, len);
|
|
163
|
+
return [center[0] + ux * s, center[1] + uy * s];
|
|
164
|
+
};
|
|
104
165
|
/** 角度换算常量(弧度 → 度) */
|
|
105
166
|
var RAD_TO_DEG = 180 / Math.PI;
|
|
106
167
|
/**
|
|
@@ -162,32 +223,38 @@ var layoutNode = (node, measureText, nameStack, nodeDistance, scopeChain = [], l
|
|
|
162
223
|
const lineHeight = (node.lineHeight ?? baseFontSize * DEFAULT_LINE_HEIGHT_FACTOR) * sy;
|
|
163
224
|
const align = alignToTextAnchor(node.align ?? "center");
|
|
164
225
|
const rawLines = node.text === void 0 ? void 0 : typeof node.text === "string" ? [node.text] : node.text;
|
|
226
|
+
const maxTextWidth = node.maxTextWidth !== void 0 ? node.maxTextWidth * sx : void 0;
|
|
165
227
|
let textWidth = 0;
|
|
166
228
|
let textHeight = 0;
|
|
167
229
|
let lines;
|
|
168
230
|
if (rawLines) {
|
|
169
|
-
lines =
|
|
231
|
+
lines = [];
|
|
232
|
+
for (const spec of rawLines) {
|
|
170
233
|
const isObj = typeof spec !== "string";
|
|
171
234
|
const text = isObj ? spec.text : spec;
|
|
172
235
|
const lineFont = isObj ? spec.font : void 0;
|
|
173
|
-
const
|
|
236
|
+
const font = {
|
|
174
237
|
size: lineFont?.size ?? fontSize,
|
|
175
238
|
family: lineFont?.family ?? fontFamily,
|
|
176
239
|
weight: lineFont?.weight ?? fontWeight,
|
|
177
240
|
style: lineFont?.style ?? fontStyle
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
if (
|
|
183
|
-
|
|
184
|
-
if (
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
241
|
+
};
|
|
242
|
+
const physical = maxTextWidth !== void 0 ? wrapText(text, font, maxTextWidth, measureText) : [text];
|
|
243
|
+
for (const ptext of physical) {
|
|
244
|
+
const m = measureText(ptext, font);
|
|
245
|
+
if (m.width > textWidth) textWidth = m.width;
|
|
246
|
+
const out = { text: ptext };
|
|
247
|
+
if (isObj) {
|
|
248
|
+
if (spec.fill !== void 0) out.fill = spec.fill;
|
|
249
|
+
if (spec.opacity !== void 0) out.opacity = spec.opacity;
|
|
250
|
+
if (lineFont?.size !== void 0) out.fontSize = lineFont.size;
|
|
251
|
+
if (lineFont?.family !== void 0) out.fontFamily = lineFont.family;
|
|
252
|
+
if (lineFont?.weight !== void 0) out.fontWeight = lineFont.weight;
|
|
253
|
+
if (lineFont?.style !== void 0) out.fontStyle = lineFont.style;
|
|
254
|
+
}
|
|
255
|
+
lines.push(out);
|
|
188
256
|
}
|
|
189
|
-
|
|
190
|
-
});
|
|
257
|
+
}
|
|
191
258
|
textHeight = lines.length * lineHeight;
|
|
192
259
|
}
|
|
193
260
|
const minW = node.minimumWidth ?? node.minimumSize ?? 0;
|
|
@@ -200,18 +267,29 @@ var layoutNode = (node, measureText, nameStack, nodeDistance, scopeChain = [], l
|
|
|
200
267
|
if (!center) throw new Error(`Cannot resolve position for node ${node.id ?? "(unnamed)"}; polar.origin or at.of may reference an undefined node`);
|
|
201
268
|
const labels = (node.label === void 0 ? void 0 : Array.isArray(node.label) ? node.label : [node.label])?.map((lab) => {
|
|
202
269
|
const labFont = lab.font;
|
|
270
|
+
const labFontSize = (labFont?.size ?? labelDefault?.font?.size ?? baseFontSize) * fontScale;
|
|
271
|
+
const labFamily = labFont?.family ?? labelDefault?.font?.family ?? fontFamily;
|
|
272
|
+
const labWeight = labFont?.weight ?? labelDefault?.font?.weight ?? fontWeight;
|
|
273
|
+
const labStyle = labFont?.style ?? labelDefault?.font?.style ?? fontStyle;
|
|
203
274
|
return {
|
|
204
275
|
text: lab.text,
|
|
205
276
|
position: lab.position ?? "above",
|
|
206
277
|
distance: lab.distance ?? DEFAULT_LABEL_DISTANCE,
|
|
207
278
|
textColor: lab.textColor ?? labelDefault?.textColor ?? labelDefault?.color ?? node.textColor,
|
|
208
279
|
opacity: lab.opacity ?? labelDefault?.opacity,
|
|
209
|
-
fontSize:
|
|
210
|
-
fontFamily:
|
|
211
|
-
fontWeight:
|
|
212
|
-
fontStyle:
|
|
280
|
+
fontSize: labFontSize,
|
|
281
|
+
fontFamily: labFamily,
|
|
282
|
+
fontWeight: labWeight,
|
|
283
|
+
fontStyle: labStyle,
|
|
213
284
|
rotate: lab.rotate,
|
|
214
|
-
keepUpright: lab.keepUpright
|
|
285
|
+
keepUpright: lab.keepUpright,
|
|
286
|
+
measuredWidth: measureText(lab.text, {
|
|
287
|
+
size: labFontSize,
|
|
288
|
+
family: labFamily,
|
|
289
|
+
weight: labWeight,
|
|
290
|
+
style: labStyle
|
|
291
|
+
}).width,
|
|
292
|
+
pin: lab.pin
|
|
215
293
|
};
|
|
216
294
|
});
|
|
217
295
|
return {
|
|
@@ -248,9 +326,9 @@ var layoutNode = (node, measureText, nameStack, nodeDistance, scopeChain = [], l
|
|
|
248
326
|
labels
|
|
249
327
|
};
|
|
250
328
|
};
|
|
251
|
-
/** 从 NodeLayout 收敛 emit 所需的视觉样式子集(ShapeStyle,不含几何 /
|
|
252
|
-
var toShapeStyle = (layout) => ({
|
|
253
|
-
fill: layout.fill,
|
|
329
|
+
/** 从 NodeLayout 收敛 emit 所需的视觉样式子集(ShapeStyle,不含几何 / 文本);fill 经 resolveFill 转 PaintValue */
|
|
330
|
+
var toShapeStyle = (layout, resolveFill) => ({
|
|
331
|
+
fill: resolveFill(layout.fill),
|
|
254
332
|
fillOpacity: layout.fillOpacity,
|
|
255
333
|
stroke: layout.stroke,
|
|
256
334
|
strokeOpacity: layout.strokeOpacity,
|
|
@@ -264,12 +342,44 @@ var toShapeStyle = (layout) => ({
|
|
|
264
342
|
* @description shape 主体走 `shapeDef.emit`(收轴对齐 rect、可出多 primitive);text 始终走 TextPrim;
|
|
265
343
|
* 有旋转时外层 GroupPrim 用 `rotate(deg cx cy)` 统一包裹 shape + text(diamond 顶点 / text 都靠 group 旋转)
|
|
266
344
|
*/
|
|
267
|
-
|
|
345
|
+
/**
|
|
346
|
+
* 节点 label 的外接点(供顶层 bbox / viewBox 计算,让 label 不被裁——与 step.label 进 bbox 一致)
|
|
347
|
+
* @description 每个 label 取其文本框四角;label 中心走 labelCenter(轴对齐系),node 自身 rotate 时绕 node 中心旋转
|
|
348
|
+
* (与 emit 的 group rotate 同步)。pin 引线起点在 node 边界内、已被 node 四角覆盖,无需额外。
|
|
349
|
+
*/
|
|
350
|
+
var labelExtentPoints = (layout) => {
|
|
351
|
+
if (!layout.labels || layout.labels.length === 0) return [];
|
|
352
|
+
const cx = layout.rect.x;
|
|
353
|
+
const cy = layout.rect.y;
|
|
354
|
+
const rad = layout.rotateDeg * Math.PI / 180;
|
|
355
|
+
const cos = Math.cos(rad);
|
|
356
|
+
const sin = Math.sin(rad);
|
|
357
|
+
const pts = [];
|
|
358
|
+
for (const lab of layout.labels) {
|
|
359
|
+
const [lx, ly] = labelCenter(layout, lab);
|
|
360
|
+
const halfW = lab.measuredWidth / 2;
|
|
361
|
+
const halfH = lab.fontSize / 2;
|
|
362
|
+
const corners = [
|
|
363
|
+
[lx - halfW, ly - halfH],
|
|
364
|
+
[lx + halfW, ly - halfH],
|
|
365
|
+
[lx - halfW, ly + halfH],
|
|
366
|
+
[lx + halfW, ly + halfH]
|
|
367
|
+
];
|
|
368
|
+
for (const [px, py] of corners) if (layout.rotateDeg === 0) pts.push([px, py]);
|
|
369
|
+
else {
|
|
370
|
+
const dx = px - cx;
|
|
371
|
+
const dy = py - cy;
|
|
372
|
+
pts.push([cx + dx * cos - dy * sin, cy + dx * sin + dy * cos]);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
return pts;
|
|
376
|
+
};
|
|
377
|
+
var emitNodePrimitives = (layout, round, resolveFill) => {
|
|
268
378
|
const axisAlignedRect = {
|
|
269
379
|
...layout.rect,
|
|
270
380
|
rotate: 0
|
|
271
381
|
};
|
|
272
|
-
const inner = [...layout.shapeDef.emit(axisAlignedRect, toShapeStyle(layout), round)];
|
|
382
|
+
const inner = [...layout.shapeDef.emit(axisAlignedRect, toShapeStyle(layout, resolveFill), round)];
|
|
273
383
|
if (layout.lines) {
|
|
274
384
|
const halfBlockW = layout.textWidth / 2;
|
|
275
385
|
const xOffset = layout.align === "start" ? -halfBlockW : layout.align === "end" ? halfBlockW : 0;
|
|
@@ -296,6 +406,26 @@ var emitNodePrimitives = (layout, round) => {
|
|
|
296
406
|
const cy = layout.rect.y;
|
|
297
407
|
for (const lab of layout.labels) {
|
|
298
408
|
const [lx, ly] = labelCenter(layout, lab);
|
|
409
|
+
if (lab.pin) {
|
|
410
|
+
const style = typeof lab.pin === "object" ? lab.pin : void 0;
|
|
411
|
+
const [bx, by] = labelBorderPoint(layout, lab);
|
|
412
|
+
const pad = 2;
|
|
413
|
+
const [nx, ny] = labelBoxEdgeToward([lx, ly], [bx, by], lab.measuredWidth / 2 + pad, lab.fontSize / 2 + pad);
|
|
414
|
+
inner.push({
|
|
415
|
+
type: "path",
|
|
416
|
+
commands: [{
|
|
417
|
+
kind: "move",
|
|
418
|
+
to: [round(bx), round(by)]
|
|
419
|
+
}, {
|
|
420
|
+
kind: "line",
|
|
421
|
+
to: [round(nx), round(ny)]
|
|
422
|
+
}],
|
|
423
|
+
stroke: style?.stroke ?? lab.textColor ?? "currentColor",
|
|
424
|
+
strokeWidth: style?.strokeWidth ?? 1,
|
|
425
|
+
dashPattern: style?.dashPattern,
|
|
426
|
+
opacity: lab.opacity ?? layout.opacity
|
|
427
|
+
});
|
|
428
|
+
}
|
|
299
429
|
const textPrim = {
|
|
300
430
|
type: "text",
|
|
301
431
|
x: round(lx),
|
|
@@ -341,4 +471,4 @@ var emitNodePrimitives = (layout, round) => {
|
|
|
341
471
|
return [group];
|
|
342
472
|
};
|
|
343
473
|
//#endregion
|
|
344
|
-
export { anchorOf, angleBoundaryOf, boundaryPointOf, emitNodePrimitives, layoutNode };
|
|
474
|
+
export { anchorOf, angleBoundaryOf, boundaryPointOf, emitNodePrimitives, labelExtentPoints, layoutNode };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IRPaintSpec } from '../ir';
|
|
2
|
+
import { PaintValue, SceneResource } from '../primitive';
|
|
3
|
+
/** fill 解析器:纯色 string 原样返回;PaintSpec 去重 + 派稳定 id → `{ kind:'resourceRef', id }`;undefined 透传 */
|
|
4
|
+
export type PaintResolver = (fill: string | IRPaintSpec | undefined) => PaintValue | undefined;
|
|
5
|
+
/** paint 资源登记表:编译期收集 PaintSpec、去重派 id,最后产出 Scene.resources */
|
|
6
|
+
export type PaintRegistry = {
|
|
7
|
+
resolve: PaintResolver;
|
|
8
|
+
resources: () => Array<SceneResource>;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* 建一个 paint 登记表
|
|
12
|
+
* @description resolve 对相同 PaintSpec(结构化 JSON 深比较)合并为一个资源、派稳定 id(`paint-1` / `paint-2`…,首见序)。
|
|
13
|
+
* 同一份 IR 编译两次 → 同 id(快照稳定、SSR / CSR 一致)。SVG id 跨实例唯一性由 react adapter 加 useId 前缀解决。
|
|
14
|
+
*/
|
|
15
|
+
export declare const createPaintRegistry: () => PaintRegistry;
|
|
16
|
+
//# sourceMappingURL=paint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paint.d.ts","sourceRoot":"","sources":["../../../src/compile/paint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE9D,gGAAgG;AAChG,MAAM,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,KAAK,UAAU,GAAG,SAAS,CAAC;AAE/F,8DAA8D;AAC9D,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,aAAa,CAAC;IACvB,SAAS,EAAE,MAAM,KAAK,CAAC,aAAa,CAAC,CAAC;CACvC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,QAAO,aAkBtC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/compile/paint.ts
|
|
2
|
+
/**
|
|
3
|
+
* 建一个 paint 登记表
|
|
4
|
+
* @description resolve 对相同 PaintSpec(结构化 JSON 深比较)合并为一个资源、派稳定 id(`paint-1` / `paint-2`…,首见序)。
|
|
5
|
+
* 同一份 IR 编译两次 → 同 id(快照稳定、SSR / CSR 一致)。SVG id 跨实例唯一性由 react adapter 加 useId 前缀解决。
|
|
6
|
+
*/
|
|
7
|
+
var createPaintRegistry = () => {
|
|
8
|
+
const idByKey = /* @__PURE__ */ new Map();
|
|
9
|
+
const list = [];
|
|
10
|
+
let counter = 0;
|
|
11
|
+
const resolve = (fill) => {
|
|
12
|
+
if (fill === void 0) return void 0;
|
|
13
|
+
if (typeof fill === "string") return fill;
|
|
14
|
+
const key = JSON.stringify(fill);
|
|
15
|
+
let id = idByKey.get(key);
|
|
16
|
+
if (id === void 0) {
|
|
17
|
+
counter += 1;
|
|
18
|
+
id = `paint-${counter}`;
|
|
19
|
+
idByKey.set(key, id);
|
|
20
|
+
list.push({
|
|
21
|
+
kind: "paint",
|
|
22
|
+
id,
|
|
23
|
+
spec: fill
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
kind: "resourceRef",
|
|
28
|
+
id
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
resolve,
|
|
33
|
+
resources: () => list
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
//#endregion
|
|
37
|
+
export { createPaintRegistry };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PaintResolver } from '../paint';
|
|
1
2
|
import { IRPath, IRPosition } from '../../ir';
|
|
2
3
|
import { ScenePrimitive, Transform } from '../../primitive';
|
|
3
4
|
import { NameStack } from '../name-stack';
|
|
@@ -18,6 +19,8 @@ export type EmitPathWarnHook = {
|
|
|
18
19
|
* 投影回全局;顶层 path / 无 scope chain 时为 `[]`(恒等,等价 v0.1 行为)
|
|
19
20
|
*/
|
|
20
21
|
scopeChain?: ReadonlyArray<Transform>;
|
|
22
|
+
/** fill 解析器(PaintSpec → resourceRef + 登记资源);缺省时纯色透传、PaintSpec 退化为无填充 */
|
|
23
|
+
resolveFill?: PaintResolver;
|
|
21
24
|
};
|
|
22
25
|
/**
|
|
23
26
|
* IR Path → PathPrim
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/compile/path/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/compile/path/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAY9C,OAAO,KAAK,EACV,MAAM,EACN,UAAU,EAGX,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAEV,cAAc,EACd,SAAS,EACV,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,KAAK,YAAY,EAAoB,MAAM,iBAAiB,CAAC;AAkCtE,mCAAmC;AACnC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,iCAAiC;IACjC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;KACd,KAAK,IAAI,CAAC;IACX,yDAAyD;IACzD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,UAAU,CAAC,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;IACtC,wEAAwE;IACxE,WAAW,CAAC,EAAE,aAAa,CAAC;CAC7B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAC5B,MAAM,MAAM,EACZ,WAAW,SAAS,EACpB,OAAO,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,EAC5B,cAAa,YAA+B,EAC5C,WAAU,gBAAqB,KAC9B;IAAE,UAAU,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;IAAC,MAAM,EAAE,KAAK,CAAC,UAAU,CAAC,CAAA;CAAE,GAAG,IAqhBrE,CAAC"}
|
|
@@ -39,6 +39,7 @@ var emitPathPrimitive = (path, nameStack, round, measureText = fallbackMeasurer,
|
|
|
39
39
|
});
|
|
40
40
|
};
|
|
41
41
|
const scopeChain = warnHook.scopeChain ?? [];
|
|
42
|
+
const resolveFill = warnHook.resolveFill ?? ((f) => typeof f === "string" || f === void 0 ? f : void 0);
|
|
42
43
|
const steps = normalizeRelativeTargets(path.children, nameStack, scopeChain);
|
|
43
44
|
if (steps.length < 2) {
|
|
44
45
|
warn("PATH_TOO_SHORT", `Path requires at least 2 steps (got ${steps.length}); the entire path is skipped`, "children");
|
|
@@ -373,7 +374,7 @@ var emitPathPrimitive = (path, nameStack, round, measureText = fallbackMeasurer,
|
|
|
373
374
|
const baseProps = {
|
|
374
375
|
stroke: path.stroke ?? "currentColor",
|
|
375
376
|
strokeWidth,
|
|
376
|
-
fill: path.fill ?? "none",
|
|
377
|
+
fill: resolveFill(path.fill) ?? "none",
|
|
377
378
|
fillRule: path.fillRule,
|
|
378
379
|
dashPattern: path.dashPattern,
|
|
379
380
|
strokeLinecap: path.lineCap,
|
package/dist/es/index.d.ts
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
* @retikz/core 公开 API
|
|
3
3
|
* @description 任何 framework adapter(@retikz/react、@retikz/vue、@retikz/canvas、@retikz/ssr)只能 import 本文件导出内容,不准走子路径。本包零 React/零 DOM 依赖
|
|
4
4
|
*/
|
|
5
|
-
export { PositionSchema, PolarPositionSchema, AtPositionSchema, OffsetPositionSchema, AT_DIRECTIONS, TargetSchema, AnchorRefSchema, NodeTargetSchema, RelativeTargetSchema, RelativeAccumulateTargetSchema, MoveStepSchema, LineStepSchema, FoldStepSchema, CycleStepSchema, CurveStepSchema, CubicStepSchema, BendStepSchema, ArcStepSchema, CirclePathStepSchema, EllipsePathStepSchema, RectangleStepSchema, ControlPointSchema, StepLabelSchema, StepSchema, NodeSchema, NodeLabelSchema, CoordinateSchema, FontSchema, TextBlockSchema, LineSpecSchema, PathSchema, ArrowDetailSchema, ArrowEndDetailSchema, ScopeSchema, NodeDefaultSchema, PathDefaultSchema, LabelDefaultSchema, ArrowDefaultSchema, TransformSchema, ChildSchema, SceneSchema, CURRENT_IR_VERSION, } from './ir';
|
|
6
|
-
export type { IRPosition, IRAtPosition, IROffsetPosition, AtDirection, IRTarget, IRAnchorRef, IRNodeTarget, IRRelativeTarget, IRRelativeAccumulateTarget, IRMoveStep, IRLineStep, IRFoldStep, IRCycleStep, IRCurveStep, IRCubicStep, IRBendStep, IRArcStep, IRCirclePathStep, IREllipsePathStep, IRRectangleStep, IRControlPoint, IRStepLabel, IRStep, IRNode, IRNodeLabel, IRCoordinate, IRFont, IRLineSpec, IRTextBlock, IRPath, IRScope, IRNodeDefault, IRPathDefault, IRLabelDefault, IRArrowDefault, StyleChannel, IRTransform, IRTranslateTransform, IRPolarTranslateTransform, IRAtTranslateTransform, IROffsetTranslateTransform, IRRotateTransform, IRScaleTransform, IRChild, IR, ArrowShape, IRArrowDetail, IRArrowEndDetail, NodeShape, BuiltinShapeName, NodeTextAlign, } from './ir';
|
|
5
|
+
export { PositionSchema, PolarPositionSchema, AtPositionSchema, OffsetPositionSchema, AT_DIRECTIONS, TargetSchema, AnchorRefSchema, NodeTargetSchema, RelativeTargetSchema, RelativeAccumulateTargetSchema, MoveStepSchema, LineStepSchema, FoldStepSchema, CycleStepSchema, CurveStepSchema, CubicStepSchema, BendStepSchema, ArcStepSchema, CirclePathStepSchema, EllipsePathStepSchema, RectangleStepSchema, ControlPointSchema, StepLabelSchema, StepSchema, NodeSchema, NodeLabelSchema, CoordinateSchema, FontSchema, TextBlockSchema, LineSpecSchema, PathSchema, ArrowDetailSchema, ArrowEndDetailSchema, ScopeSchema, NodeDefaultSchema, PathDefaultSchema, LabelDefaultSchema, ArrowDefaultSchema, TransformSchema, ChildSchema, SceneSchema, CURRENT_IR_VERSION, PaintSpecSchema, GradientStopSchema, } from './ir';
|
|
6
|
+
export type { IRPosition, IRAtPosition, IROffsetPosition, AtDirection, IRTarget, IRAnchorRef, IRNodeTarget, IRRelativeTarget, IRRelativeAccumulateTarget, IRMoveStep, IRLineStep, IRFoldStep, IRCycleStep, IRCurveStep, IRCubicStep, IRBendStep, IRArcStep, IRCirclePathStep, IREllipsePathStep, IRRectangleStep, IRControlPoint, IRStepLabel, IRStep, IRNode, IRNodeLabel, IRCoordinate, IRFont, IRLineSpec, IRTextBlock, IRPath, IRScope, IRNodeDefault, IRPathDefault, IRLabelDefault, IRArrowDefault, StyleChannel, IRTransform, IRTranslateTransform, IRPolarTranslateTransform, IRAtTranslateTransform, IROffsetTranslateTransform, IRRotateTransform, IRScaleTransform, IRChild, IR, ArrowShape, IRArrowDetail, IRArrowEndDetail, NodeShape, BuiltinShapeName, NodeTextAlign, IRPaintSpec, IRGradientStop, } from './ir';
|
|
7
7
|
export { ARROW_SHAPES, DEFAULT_ARROW_SHAPE, HOLLOW_ARROW_SHAPES, ARROW_MARKER_DEFAULT_SIZE, ARROW_MARKER_HOLLOW_DEFAULT_LINE_WIDTH, NODE_SHAPES, NODE_TEXT_ALIGNS, } from './ir';
|
|
8
8
|
export type { ScenePrimitive, RectPrim, EllipsePrim, TextPrim, TextLine, PathPrim, PathCommand,
|
|
9
9
|
/** 7 个 named PathCommand 分支(便于 wrapper / Pick<>) */
|
|
10
10
|
MovePathCommand, LinePathCommand, QuadPathCommand, CubicPathCommand, ArcPathCommand, EllipseArcPathCommand, ClosePathCommand, ArrowEndSpec, GroupPrim, Transform,
|
|
11
11
|
/** 3 个 named Transform 分支 */
|
|
12
|
-
TranslateTransform, RotateTransform, ScaleTransform, Layout, Scene, } from './primitive';
|
|
12
|
+
TranslateTransform, RotateTransform, ScaleTransform, Layout, Scene, PaintValue, SceneResource, } from './primitive';
|
|
13
13
|
export type { FontSpec, TextMetrics, TextMeasurer, CompileOptions, CompileWarning, } from './compile';
|
|
14
14
|
export { computeLayout, fallbackMeasurer, compileToScene } from './compile';
|
|
15
15
|
export type { WayItem, WayDSL, WayCycle, WayVia, WayRelativeItem, WayLabel, WayLabelOp, } from './parsers';
|
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;;;GAGG;AAGH,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,EACb,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,8BAA8B,EAC9B,cAAc,EACd,cAAc,EACd,cAAc,EACd,eAAe,EACf,eAAe,EACf,eAAe,EACf,cAAc,EACd,aAAa,EACb,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,UAAU,EACV,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,eAAe,EACf,cAAc,EACd,UAAU,EACV,iBAAiB,EACjB,oBAAoB,EACpB,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EACf,WAAW,EACX,WAAW,EACX,kBAAkB,GACnB,MAAM,MAAM,CAAC;AACd,YAAY,EACV,UAAU,EACV,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,0BAA0B,EAC1B,UAAU,EACV,UAAU,EACV,UAAU,EACV,WAAW,EACX,WAAW,EACX,WAAW,EACX,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,WAAW,EACX,MAAM,EACN,MAAM,EACN,WAAW,EACX,YAAY,EACZ,MAAM,EACN,UAAU,EACV,WAAW,EACX,MAAM,EACN,OAAO,EACP,aAAa,EACb,aAAa,EACb,cAAc,EACd,cAAc,EACd,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,yBAAyB,EACzB,sBAAsB,EACtB,0BAA0B,EAC1B,iBAAiB,EACjB,gBAAgB,EAChB,OAAO,EACP,EAAE,EACF,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,SAAS,EACT,gBAAgB,EAChB,aAAa,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,EACb,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,8BA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
|
|
3
3
|
import { AT_DIRECTIONS, AtPositionSchema } from "./ir/position/at-position.js";
|
|
4
4
|
import { OffsetPositionSchema } from "./ir/position/offset-position.js";
|
|
5
5
|
import { FontSchema } from "./ir/font.js";
|
|
6
|
+
import { GradientStopSchema, PaintSpecSchema } from "./ir/paint.js";
|
|
6
7
|
import { LineSpecSchema, TextBlockSchema } from "./ir/text.js";
|
|
7
8
|
import { ARROW_MARKER_DEFAULT_SIZE, ARROW_MARKER_HOLLOW_DEFAULT_LINE_WIDTH, ARROW_SHAPES, ArrowDetailSchema, ArrowEndDetailSchema, DEFAULT_ARROW_SHAPE, HOLLOW_ARROW_SHAPES } from "./ir/path/arrow.js";
|
|
8
9
|
import { localToWorld, worldToLocal } from "./geometry/_transform.js";
|
|
@@ -27,4 +28,4 @@ import { parseTargetSugar } from "./parsers/parseTargetSugar.js";
|
|
|
27
28
|
import { DrawWay, parseWay } from "./parsers/parseWay.js";
|
|
28
29
|
import { polar } from "./geometry/polar.js";
|
|
29
30
|
import { point } from "./geometry/point.js";
|
|
30
|
-
export { ARROW_MARKER_DEFAULT_SIZE, ARROW_MARKER_HOLLOW_DEFAULT_LINE_WIDTH, ARROW_SHAPES, AT_DIRECTIONS, AnchorRefSchema, ArcStepSchema, ArrowDefaultSchema, ArrowDetailSchema, ArrowEndDetailSchema, AtPositionSchema, BUILTIN_SHAPES, BendStepSchema, CURRENT_IR_VERSION, ChildSchema, CirclePathStepSchema, ControlPointSchema, CoordinateSchema, CubicStepSchema, CurveStepSchema, CycleStepSchema, DEFAULT_ARROW_SHAPE, DrawWay, EllipsePathStepSchema, FoldStepSchema, FontSchema, HOLLOW_ARROW_SHAPES, LabelDefaultSchema, LineSpecSchema, LineStepSchema, MoveStepSchema, NODE_SHAPES, NODE_TEXT_ALIGNS, NodeDefaultSchema, NodeLabelSchema, NodeSchema, NodeTargetSchema, OffsetPositionSchema, PathDefaultSchema, PathSchema, PolarPositionSchema, PositionSchema, RECT_ANCHORS, RectangleStepSchema, RelativeAccumulateTargetSchema, RelativeTargetSchema, SceneSchema, ScopeSchema, StepLabelSchema, StepSchema, TargetSchema, TextBlockSchema, TransformSchema, circle, compileToScene, computeLayout, diamond, ellipse, fallbackMeasurer, localToWorld, parseNodeTarget, parseTargetSugar, parseWay, point, polar, rect, worldToLocal };
|
|
31
|
+
export { ARROW_MARKER_DEFAULT_SIZE, ARROW_MARKER_HOLLOW_DEFAULT_LINE_WIDTH, ARROW_SHAPES, AT_DIRECTIONS, AnchorRefSchema, ArcStepSchema, ArrowDefaultSchema, ArrowDetailSchema, ArrowEndDetailSchema, AtPositionSchema, BUILTIN_SHAPES, BendStepSchema, CURRENT_IR_VERSION, ChildSchema, CirclePathStepSchema, ControlPointSchema, CoordinateSchema, CubicStepSchema, CurveStepSchema, CycleStepSchema, DEFAULT_ARROW_SHAPE, DrawWay, EllipsePathStepSchema, FoldStepSchema, FontSchema, GradientStopSchema, HOLLOW_ARROW_SHAPES, LabelDefaultSchema, LineSpecSchema, LineStepSchema, MoveStepSchema, NODE_SHAPES, NODE_TEXT_ALIGNS, NodeDefaultSchema, NodeLabelSchema, NodeSchema, NodeTargetSchema, OffsetPositionSchema, PaintSpecSchema, PathDefaultSchema, PathSchema, PolarPositionSchema, PositionSchema, RECT_ANCHORS, RectangleStepSchema, RelativeAccumulateTargetSchema, RelativeTargetSchema, SceneSchema, ScopeSchema, StepLabelSchema, StepSchema, TargetSchema, TextBlockSchema, TransformSchema, circle, compileToScene, computeLayout, diamond, ellipse, fallbackMeasurer, localToWorld, parseNodeTarget, parseTargetSugar, parseWay, point, polar, rect, worldToLocal };
|
package/dist/es/ir/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ir/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ir/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
|