@yft-design/engine 0.0.10 → 0.0.11
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/EngineCanvas.d.ts +6 -0
- package/dist/EngineCanvas.js +8 -0
- package/dist/debug/seed.d.ts +2 -1
- package/dist/debug/seed.js +8 -5
- package/dist/engineFlag.d.ts +12 -0
- package/dist/engineFlag.js +12 -0
- package/dist/export/svgExport.js +12 -9
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/interact/tableCellEditing.js +2 -1
- package/dist/model/scene.d.ts +1 -1
- package/dist/model/scene.js +4 -3
- package/dist/model/tableLayout.js +3 -2
- package/dist/model/textAlign.d.ts +37 -0
- package/dist/model/textAlign.js +36 -0
- package/dist/model/textLayout.d.ts +11 -4
- package/dist/model/textLayout.js +46 -26
- package/dist/render/QuadBatch.d.ts +14 -5
- package/dist/render/QuadBatch.js +66 -10
- package/dist/render/SceneRenderer.d.ts +10 -0
- package/dist/render/SceneRenderer.js +12 -0
- package/dist/render/TextRenderer.js +10 -4
- package/dist/render/imageEffects.d.ts +3 -1
- package/dist/render/imageEffects.js +30 -5
- package/dist/render/lineDecorationSdf.d.ts +63 -0
- package/dist/render/lineDecorationSdf.js +188 -0
- package/dist/render/scrollText.js +8 -3
- package/dist/render/segmentTable.d.ts +53 -0
- package/dist/render/segmentTable.js +117 -0
- package/dist/render/shaders.d.ts +4 -2
- package/dist/render/shaders.js +98 -7
- package/dist/render/strokeMiterOutline.d.ts +39 -0
- package/dist/render/strokeMiterOutline.js +224 -0
- package/dist/render/strokePainter.d.ts +11 -0
- package/dist/render/strokePainter.js +80 -7
- package/dist/render/strokeSdf.d.ts +34 -13
- package/dist/render/strokeSdf.js +177 -13
- package/package.json +1 -1
package/dist/render/strokeSdf.js
CHANGED
|
@@ -1,12 +1,66 @@
|
|
|
1
|
-
import { isStrokeSdfDashEnabled } from '../engineFlag';
|
|
1
|
+
import { isStrokeSdfDashEnabled, isStrokeSdfPolygonEnabled } from '../engineFlag';
|
|
2
2
|
import { rectCornerRadii } from '../core/roundedRect';
|
|
3
|
+
import { MAX_SEG_BATCH, segHash } from './segmentTable';
|
|
4
|
+
import { buildMiterOutline } from './strokeMiterOutline';
|
|
3
5
|
/** 描边码位段:kind(0-2) | cap(3-5) | penUniform(6)——与 strokeCoverage 解码一致 */
|
|
4
6
|
const STROKE_KIND_RECT = 1;
|
|
5
7
|
const STROKE_KIND_LINE = 2;
|
|
6
8
|
const STROKE_KIND_ELLIPSE = 3;
|
|
9
|
+
/** polygon 族段表(方向三第二刀):着色器 texelFetch 段循环 capsule 并(cap/uniform 位不使用) */
|
|
10
|
+
const STROKE_KIND_SEGMENT = 4;
|
|
7
11
|
const CAP_INDEX = { butt: 0, round: 1, square: 2 };
|
|
8
12
|
/** Chebyshev 盒角在 90° 恒 ≤ miterLimit×(w/2) 的安全下限(√2≈1.414) */
|
|
9
13
|
const MITER_SAFE_LIMIT = 1.5;
|
|
14
|
+
/**
|
|
15
|
+
* polygon 族段表打包(round 模式):中心线折线原样段集(端点不延长——capsule
|
|
16
|
+
* 并即 round join/cap 语义)。零长段跳过(fabric Polyline moveTo(p0)+lineTo(p0)
|
|
17
|
+
* 怪癖段;实线墨迹不受影响)。marginX/Y=端点圆盘(半径 halfW)超 points bbox
|
|
18
|
+
* 的逐轴余量。
|
|
19
|
+
*/
|
|
20
|
+
const packPolylineSegments = (pts, closed, halfW) => {
|
|
21
|
+
const total = closed ? pts.length : pts.length - 1;
|
|
22
|
+
if (total < 1)
|
|
23
|
+
return null;
|
|
24
|
+
const ax = [];
|
|
25
|
+
const ay = [];
|
|
26
|
+
const bx = [];
|
|
27
|
+
const by = [];
|
|
28
|
+
for (let i = 0; i < total; i++) {
|
|
29
|
+
const a = pts[i];
|
|
30
|
+
const b = pts[(i + 1) % pts.length];
|
|
31
|
+
const dx = b.x - a.x;
|
|
32
|
+
const dy = b.y - a.y;
|
|
33
|
+
if (dx * dx + dy * dy < 1e-18)
|
|
34
|
+
continue;
|
|
35
|
+
ax.push(a.x);
|
|
36
|
+
ay.push(a.y);
|
|
37
|
+
bx.push(b.x);
|
|
38
|
+
by.push(b.y);
|
|
39
|
+
}
|
|
40
|
+
const m = ax.length;
|
|
41
|
+
if (m < 1 || m > MAX_SEG_BATCH)
|
|
42
|
+
return null;
|
|
43
|
+
const data = new Float32Array(m * 4);
|
|
44
|
+
let absX = 0;
|
|
45
|
+
let absY = 0;
|
|
46
|
+
for (let i = 0; i < m; i++) {
|
|
47
|
+
data[i * 4] = ax[i];
|
|
48
|
+
data[i * 4 + 1] = ay[i];
|
|
49
|
+
data[i * 4 + 2] = bx[i];
|
|
50
|
+
data[i * 4 + 3] = by[i];
|
|
51
|
+
absX = Math.max(absX, Math.abs(ax[i]), Math.abs(bx[i]));
|
|
52
|
+
absY = Math.max(absY, Math.abs(ay[i]), Math.abs(by[i]));
|
|
53
|
+
}
|
|
54
|
+
let hx = 0;
|
|
55
|
+
let hy = 0;
|
|
56
|
+
for (const p of pts) {
|
|
57
|
+
hx = Math.max(hx, Math.abs(p.x));
|
|
58
|
+
hy = Math.max(hy, Math.abs(p.y));
|
|
59
|
+
}
|
|
60
|
+
if (!(hx > 0) || !(hy > 0))
|
|
61
|
+
return null;
|
|
62
|
+
return { segments: { data, count: m, hash: segHash(data) }, marginX: absX + halfW - hx, marginY: absY + halfW - hy };
|
|
63
|
+
};
|
|
10
64
|
/**
|
|
11
65
|
* eligibility 与打包:不合形态返回 null(调用方回落烘焙链)。
|
|
12
66
|
* zoom/dpr 与烘焙路径同源(host.zoom×host.dpr;导出期 applyExportViewport
|
|
@@ -22,7 +76,9 @@ export const strokeSdfParams = (node, decl, zoom, dpr) => {
|
|
|
22
76
|
return null;
|
|
23
77
|
if (decl.dashArray.length > 2)
|
|
24
78
|
return null;
|
|
25
|
-
|
|
79
|
+
// 帽:butt=硬窗/square=窗两侧延 halfW(canvas 逐 dash 半宽区间扩展精确形,
|
|
80
|
+
// 批次 386);round 帽=逐 dash 胶囊(门×带交集无圆角表达)回落
|
|
81
|
+
if (decl.lineCap !== 'butt' && decl.lineCap !== 'square')
|
|
26
82
|
return null;
|
|
27
83
|
if (decl.uniform)
|
|
28
84
|
return null;
|
|
@@ -40,10 +96,22 @@ export const strokeSdfParams = (node, decl, zoom, dpr) => {
|
|
|
40
96
|
// margin 使 quad 两轴恒正)
|
|
41
97
|
if (type !== 'line' && (!(dims.x > 0) || !(dims.y > 0)))
|
|
42
98
|
return null;
|
|
43
|
-
const
|
|
44
|
-
|
|
99
|
+
const kindSel = type === 'line'
|
|
100
|
+
? STROKE_KIND_LINE
|
|
101
|
+
: type === 'ellipse' || type === 'circle'
|
|
102
|
+
? STROKE_KIND_ELLIPSE
|
|
103
|
+
: type === 'polygon' || type === 'polyline' || type === 'triangle'
|
|
104
|
+
? STROKE_KIND_SEGMENT
|
|
105
|
+
: STROKE_KIND_RECT;
|
|
45
106
|
const halfW = decl.width / 2;
|
|
46
107
|
let shape;
|
|
108
|
+
let segments = null;
|
|
109
|
+
/** 墨迹超 bbox 的逐轴核心余量(rect/line/ellipse=halfW;polygon 族=端点圆盘
|
|
110
|
+
* (round)或轮廓顶点外沿(miter)) */
|
|
111
|
+
let marginX = halfW;
|
|
112
|
+
let marginY = halfW;
|
|
113
|
+
/** kind=4 段表模式位(0=capsule/round、1=轮廓填充/miter);其余 kind 恒 0 */
|
|
114
|
+
let modeSlot = 0;
|
|
47
115
|
if (type === 'rect' || type === 'fabricrect') {
|
|
48
116
|
// 圆角与填充 quad 同源归一(rectCornerRadii:FabricRect 视觉 radius 反算/
|
|
49
117
|
// 单写 rx 提升 ry/钳半宽高)——角语义与批次 98 填充角天然同口径
|
|
@@ -54,8 +122,10 @@ export const strokeSdfParams = (node, decl, zoom, dpr) => {
|
|
|
54
122
|
// miterLimit 过低(bevel 截断)不承接。圆角路径角区平滑,join 无语义不设门
|
|
55
123
|
if (rx < 1e-4 && ry < 1e-4 && (decl.lineJoin !== 'miter' || decl.miterLimit < MITER_SAFE_LIMIT))
|
|
56
124
|
return null;
|
|
57
|
-
//
|
|
58
|
-
|
|
125
|
+
// dash+圆角(批次 386):圆角 rx==ry 放行(角方块径向投影+直边段轴向投影,
|
|
126
|
+
// κ-bezier 角与理想圆弧弧长差 ~1e-4·r 亚像素);椭圆角(rx≠ry,非等比
|
|
127
|
+
// scale 的视觉 radius 产物)弧长=椭圆积分无闭式——回落(椭圆 dash 同族)
|
|
128
|
+
if (dash && Math.abs(rx - ry) >= 1e-4)
|
|
59
129
|
return null;
|
|
60
130
|
shape = [rx, ry, dims.x / 2, dims.y / 2];
|
|
61
131
|
}
|
|
@@ -76,22 +146,116 @@ export const strokeSdfParams = (node, decl, zoom, dpr) => {
|
|
|
76
146
|
return null;
|
|
77
147
|
shape = [0, 0, dims.x / 2, dims.y / 2];
|
|
78
148
|
}
|
|
149
|
+
else if (type === 'polygon' || type === 'polyline' || type === 'triangle') {
|
|
150
|
+
// 方向三第二刀两放行面:round=capsule 并(批次 383)/ miter=双偏移轮廓
|
|
151
|
+
// winding 填充(批次 385);bevel 与超限顶点回落(枚举见文件头注)
|
|
152
|
+
if (!isStrokeSdfPolygonEnabled())
|
|
153
|
+
return null;
|
|
154
|
+
if (dash)
|
|
155
|
+
return null;
|
|
156
|
+
if (decl.uniform)
|
|
157
|
+
return null;
|
|
158
|
+
const closed = type !== 'polyline';
|
|
159
|
+
let src;
|
|
160
|
+
if (type === 'triangle') {
|
|
161
|
+
// fabric Triangle:points 不持久化,几何由 w/h 合成(strokeBake/
|
|
162
|
+
// buildPolygonMesh(trianglePoints) 同源口径),直接给中心系三点
|
|
163
|
+
const w = dims.x;
|
|
164
|
+
const h = dims.y;
|
|
165
|
+
if (!(w > 0) || !(h > 0))
|
|
166
|
+
return null;
|
|
167
|
+
src = [
|
|
168
|
+
{ x: 0, y: -h / 2 },
|
|
169
|
+
{ x: w / 2, y: h / 2 },
|
|
170
|
+
{ x: -w / 2, y: h / 2 }
|
|
171
|
+
];
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
const points = Array.isArray(raw.points) ? raw.points : [];
|
|
175
|
+
if (points.length < (closed ? 3 : 2))
|
|
176
|
+
return null;
|
|
177
|
+
src = [];
|
|
178
|
+
for (const p of points) {
|
|
179
|
+
const x = Number(p?.x);
|
|
180
|
+
const y = Number(p?.y);
|
|
181
|
+
if (!Number.isFinite(x) || !Number.isFinite(y))
|
|
182
|
+
return null;
|
|
183
|
+
src.push({ x, y });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// points − points bbox 中心(buildPolygonMesh/strokeBake 同口径)= vLocal 中心系
|
|
187
|
+
let minX = Infinity;
|
|
188
|
+
let minY = Infinity;
|
|
189
|
+
let maxX = -Infinity;
|
|
190
|
+
let maxY = -Infinity;
|
|
191
|
+
for (const p of src) {
|
|
192
|
+
if (minX > p.x)
|
|
193
|
+
minX = p.x;
|
|
194
|
+
if (minY > p.y)
|
|
195
|
+
minY = p.y;
|
|
196
|
+
if (maxX < p.x)
|
|
197
|
+
maxX = p.x;
|
|
198
|
+
if (maxY < p.y)
|
|
199
|
+
maxY = p.y;
|
|
200
|
+
}
|
|
201
|
+
const cx = (minX + maxX) / 2;
|
|
202
|
+
const cy = (minY + maxY) / 2;
|
|
203
|
+
const centered = src.map((p) => ({ x: p.x - cx, y: p.y - cy }));
|
|
204
|
+
/** kind=4 的模式位(code cap 位段):0=capsule 并(round,既有行为零变化)
|
|
205
|
+
* / 1=双偏移轮廓 winding 填充(miter,批次 385) */
|
|
206
|
+
let segMode = 0;
|
|
207
|
+
if (decl.lineJoin === 'round') {
|
|
208
|
+
// 开放 polyline 端帽须 round(butt/square 平头/方帽无 capsule 表达)
|
|
209
|
+
if (!closed && decl.lineCap !== 'round')
|
|
210
|
+
return null;
|
|
211
|
+
const packed = packPolylineSegments(centered, closed, halfW);
|
|
212
|
+
if (!packed)
|
|
213
|
+
return null;
|
|
214
|
+
segments = packed.segments;
|
|
215
|
+
marginX = packed.marginX;
|
|
216
|
+
marginY = packed.marginY;
|
|
217
|
+
}
|
|
218
|
+
else if (decl.lineJoin === 'miter') {
|
|
219
|
+
// 缺省 join=miter(fabric 同缺省):开放 polyline 端帽须 butt(round/square
|
|
220
|
+
// 帽形无轮廓表达);闭合无帽。任一顶点超 miterLimit/回折尖刺/超段数在
|
|
221
|
+
// buildMiterOutline 内回落
|
|
222
|
+
if (!closed && decl.lineCap !== 'butt')
|
|
223
|
+
return null;
|
|
224
|
+
const packed = buildMiterOutline(centered, closed, halfW, decl.miterLimit);
|
|
225
|
+
if (!packed)
|
|
226
|
+
return null;
|
|
227
|
+
segments = packed.segments;
|
|
228
|
+
marginX = packed.marginX;
|
|
229
|
+
marginY = packed.marginY;
|
|
230
|
+
segMode = 1;
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
shape = [0, 0, 0, 0];
|
|
236
|
+
modeSlot = segMode;
|
|
237
|
+
}
|
|
79
238
|
else {
|
|
80
239
|
return null;
|
|
81
240
|
}
|
|
82
|
-
//
|
|
83
|
-
//
|
|
84
|
-
|
|
241
|
+
// kind=4 不消费帽语义——cap 位段复用为段表模式位(0=capsule/round,
|
|
242
|
+
// 1=轮廓填充/miter,与 shaders.ts strokeCoverage kind==4 分派一致)
|
|
243
|
+
const capSlot = kindSel === STROKE_KIND_SEGMENT ? modeSlot : CAP_INDEX[decl.lineCap] ?? 0;
|
|
244
|
+
const code = kindSel + (capSlot << 3) + (decl.uniform ? 64 : 0);
|
|
245
|
+
// margin:核心余量(本地)+ AA 余量(4 设备像素折算本地单位)。Chebyshev 方角/
|
|
246
|
+
// 方帽沿两轴各伸半宽、square 帽沿轴伸 hh——均被同一 margin 覆盖(minAxis 是
|
|
247
|
+
// 最劣方向);polygon 族 marginX/Y 已含端点圆盘
|
|
85
248
|
const m = node.matrix;
|
|
86
249
|
const k = Math.max(1e-6, zoom * dpr);
|
|
87
250
|
const axis0 = Math.hypot(m[0], m[1]);
|
|
88
251
|
const axis1 = Math.hypot(m[2], m[3]);
|
|
89
252
|
const minAxis = Math.max(Math.min(axis0, axis1), 1e-6);
|
|
90
253
|
const localPerDevicePx = 1 / (minAxis * k);
|
|
91
|
-
const
|
|
92
|
-
const
|
|
93
|
-
const
|
|
254
|
+
const mx = (decl.uniform ? halfW / minAxis : marginX) + 4 * localPerDevicePx;
|
|
255
|
+
const my = (decl.uniform ? halfW / minAxis : marginY) + 4 * localPerDevicePx;
|
|
256
|
+
const quadW = dims.x + 2 * mx;
|
|
257
|
+
const quadH = dims.y + 2 * my;
|
|
94
258
|
if (!Number.isFinite(quadW) || !Number.isFinite(quadH))
|
|
95
259
|
return null;
|
|
96
|
-
return { halfW, code: -code, shape, quadW, quadH, dash };
|
|
260
|
+
return { halfW, code: -code, shape, quadW, quadH, dash, segments };
|
|
97
261
|
};
|