@yft-design/engine 0.0.15 → 0.0.17
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/core/triangulate.d.ts +16 -3
- package/dist/core/triangulate.js +100 -24
- package/dist/export/svgExport.js +1 -1
- package/dist/interact/cropSession.js +2 -1
- package/dist/interact/expandSession.js +2 -1
- package/dist/interact/hotkeyActions.js +2 -1
- package/dist/interact/pointer.js +11 -10
- package/dist/interact/tableCellEditing.js +2 -1
- package/dist/interact/warpSession.js +2 -1
- package/dist/model/alphaHit.js +8 -4
- package/dist/model/compatEvents.d.ts +30 -1
- package/dist/model/compatEvents.js +24 -1
- package/dist/model/compatObject.d.ts +1 -1
- package/dist/model/compatObject.js +11 -8
- package/dist/model/document.d.ts +12 -0
- package/dist/model/document.js +22 -4
- package/dist/model/scene.d.ts +8 -0
- package/dist/model/scene.js +62 -43
- package/dist/model/shapePath.js +10 -9
- package/dist/render/SceneRenderer.js +21 -1
- package/dist/render/clipMaskPainter.d.ts +72 -2
- package/dist/render/clipMaskPainter.js +144 -23
- package/dist/render/gpuFx.js +14 -5
- package/dist/render/lineDecorationSdf.js +4 -3
- package/dist/render/multiPage.js +2 -1
- package/dist/render/strokeBake.js +15 -14
- package/dist/render/strokeSdf.js +12 -11
- package/dist/render/warpText.js +5 -3
- package/package.json +2 -1
package/dist/model/document.js
CHANGED
|
@@ -17,6 +17,13 @@ import { EventBus } from '../core/events';
|
|
|
17
17
|
import { isHitTransparent } from './alphaHit';
|
|
18
18
|
import { buildScene, GroupNode, isReferenceLineNode, isStrokeLineNode, LINE_STROKE_HIT_TOLERANCE, PuzzleNode, TableNode, WORKSPACE_IDS } from './scene';
|
|
19
19
|
import RBush from 'rbush';
|
|
20
|
+
/** 历史事务锚点生成:会话内递增序号+时间戳——诊断/对账锚点用途(非安全域,
|
|
21
|
+
* 引擎零外部依赖故不引 nanoid) */
|
|
22
|
+
let historyTransactionSeq = 0;
|
|
23
|
+
const newHistoryTransactionId = () => {
|
|
24
|
+
historyTransactionSeq = (historyTransactionSeq + 1) % 0xffffffff;
|
|
25
|
+
return `tx-${Date.now().toString(36)}-${historyTransactionSeq.toString(36)}`;
|
|
26
|
+
};
|
|
20
27
|
export class EngineDocument {
|
|
21
28
|
events = new EventBus();
|
|
22
29
|
_nodes = [];
|
|
@@ -444,18 +451,29 @@ export class EngineDocument {
|
|
|
444
451
|
if (phase === 'modified') {
|
|
445
452
|
this.commitGeometry();
|
|
446
453
|
const before = detail?.before;
|
|
447
|
-
const firedDetail = before || detail?.action
|
|
454
|
+
const firedDetail = before || detail?.action || detail?.transactionId
|
|
448
455
|
? {
|
|
449
456
|
action: detail?.action,
|
|
450
|
-
before: before ? targets.map((t) => before.get(t)).filter((s) => !!s) : undefined
|
|
457
|
+
before: before ? targets.map((t) => before.get(t)).filter((s) => !!s) : undefined,
|
|
458
|
+
transactionId: detail?.transactionId
|
|
451
459
|
}
|
|
452
460
|
: undefined;
|
|
453
|
-
this.
|
|
461
|
+
this.fireObjectModified([...targets], firedDetail);
|
|
454
462
|
}
|
|
455
463
|
else {
|
|
456
464
|
this.events.fire(`object:${phase}`, targets[0]);
|
|
457
465
|
}
|
|
458
466
|
}
|
|
467
|
+
/**
|
|
468
|
+
* object:modified 的统一发射口(P3 历史契约,2026-10-16——主仓风险册 R12):
|
|
469
|
+
* detail 携带调用方 transactionId 则透传(同会话多事件共享一事务),缺省
|
|
470
|
+
* 生成——引擎内**所有** object:modified 必经此口(applyTransform/文本编辑
|
|
471
|
+
* 退出/直发手势收尾),保证事件恒带事务锚点。增量字段,旧订阅方零改动。
|
|
472
|
+
*/
|
|
473
|
+
fireObjectModified(targets, detail) {
|
|
474
|
+
const transactionId = detail?.transactionId ?? newHistoryTransactionId();
|
|
475
|
+
this.events.fire('object:modified', targets, { ...detail, transactionId });
|
|
476
|
+
}
|
|
459
477
|
// #endregion
|
|
460
478
|
// #region 文本编辑态
|
|
461
479
|
enterEditing(node, options = {}) {
|
|
@@ -513,7 +531,7 @@ export class EngineDocument {
|
|
|
513
531
|
const after = node.raw.text ?? '';
|
|
514
532
|
if (after !== this._editingTextSnapshot) {
|
|
515
533
|
this.events.fire('text:editing:committed', node, this._editingTextSnapshot, after);
|
|
516
|
-
this.
|
|
534
|
+
this.fireObjectModified([node], { before: this._editingBeforeObject ? [this._editingBeforeObject] : undefined });
|
|
517
535
|
}
|
|
518
536
|
else if (this._editingBitmapSnapshot) {
|
|
519
537
|
// 批次 314 五补:值等价退出(纯进入退出/键入后删回原文)——恢复位图声明
|
package/dist/model/scene.d.ts
CHANGED
|
@@ -469,8 +469,16 @@ export declare const isStrokeLineNode: (node: SceneNode) => boolean;
|
|
|
469
469
|
*/
|
|
470
470
|
export declare class PathNode extends ShapeNode {
|
|
471
471
|
private _pathGeo;
|
|
472
|
+
/** 填充多边形(洞合成)与三角网格:三层懒(批次 415)——建景只付
|
|
473
|
+
* parse+flatten+dims(dims/命中必需);洞合成与三角化是 PDF 长 path 的
|
|
474
|
+
* 秒级主项,懒到首渲染(shapeMesh 读点全在渲染/烘焙期)。失效键与
|
|
475
|
+
* _pathGeo 同源(path/fillRule),一次清三层 */
|
|
476
|
+
private _fillPolys;
|
|
477
|
+
private _pathMesh;
|
|
472
478
|
set(props: Partial<SerializedNode>): void;
|
|
473
479
|
private get pathGeometry();
|
|
480
|
+
/** 洞合成(桥接多边形集):纯函数重算可缓存,raw.fillRule 读位同旧实现 */
|
|
481
|
+
private get fillPolygons();
|
|
474
482
|
get shapeMesh(): ShapeMesh | null;
|
|
475
483
|
get dims(): {
|
|
476
484
|
x: number;
|
package/dist/model/scene.js
CHANGED
|
@@ -1017,29 +1017,15 @@ const buildPolygonMesh = (rawPoints) => {
|
|
|
1017
1017
|
return idx.length > 0 ? { verts, triangles: new Uint32Array(idx) } : null;
|
|
1018
1018
|
};
|
|
1019
1019
|
/**
|
|
1020
|
-
*
|
|
1021
|
-
*
|
|
1022
|
-
* → 逐多边形耳切 → 合并。顶点 − bbox 中心 = fabric pathOffset 语义
|
|
1023
|
-
* (_calcBoundsFromPath 精确极值中心)。
|
|
1020
|
+
* 桥接多边形集 → 中心系三角网格(ShapeMesh)。退化输入返回 null。
|
|
1021
|
+
* 批次 415 自 buildPathGeometry 拆出:顶点平铺 + 逐多边形耳切 + 偏移合并。
|
|
1024
1022
|
*/
|
|
1025
|
-
const
|
|
1026
|
-
const commands = parsePathData(rawPath);
|
|
1027
|
-
if (!commands)
|
|
1028
|
-
return { mesh: null, contours: [], dims: { x: 0, y: 0 } };
|
|
1029
|
-
const bounds = getBoundsOfPath(commands);
|
|
1030
|
-
const contours = flattenPathCommands(commands);
|
|
1031
|
-
if (!bounds)
|
|
1032
|
-
return { mesh: null, contours, dims: { x: 0, y: 0 } };
|
|
1033
|
-
const cx = (bounds.left + bounds.right) / 2;
|
|
1034
|
-
const cy = (bounds.top + bounds.bottom) / 2;
|
|
1035
|
-
// 轮廓平移到中心系(命中按 canvas fill 偶奇/非零口径在原始轮廓上算,中心系等价)
|
|
1036
|
-
const centered = contours.map((c) => ({ closed: c.closed, points: c.points.map((p) => ({ x: p.x - cx, y: p.y - cy })) }));
|
|
1037
|
-
const polys = contoursToFillPolygons(centered, fillRule);
|
|
1023
|
+
const buildFillMesh = (polys) => {
|
|
1038
1024
|
let vertCount = 0;
|
|
1039
1025
|
for (const poly of polys)
|
|
1040
1026
|
vertCount += poly.length;
|
|
1041
1027
|
if (vertCount < 3)
|
|
1042
|
-
return
|
|
1028
|
+
return null;
|
|
1043
1029
|
const verts = new Float32Array(vertCount * 2);
|
|
1044
1030
|
const tris = [];
|
|
1045
1031
|
let offset = 0;
|
|
@@ -1052,11 +1038,27 @@ const buildPathGeometry = (rawPath, fillRule) => {
|
|
|
1052
1038
|
tris.push(t + offset);
|
|
1053
1039
|
offset += poly.length;
|
|
1054
1040
|
}
|
|
1055
|
-
return {
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1041
|
+
return tris.length > 0 ? { verts, triangles: new Uint32Array(tris) } : null;
|
|
1042
|
+
};
|
|
1043
|
+
/**
|
|
1044
|
+
* 路径数据 → 建景期几何(P3-6a):parsePathData → flatten → 中心系轮廓。
|
|
1045
|
+
* 顶点 − bbox 中心 = fabric pathOffset 语义(_calcBoundsFromPath 精确极值中心)。
|
|
1046
|
+
* 填充多边形/网格的生成链(contoursToFillPolygons → 耳切)见 buildFillMesh——
|
|
1047
|
+
* 批次 415 起 lazy 到首渲染,建景不再为其付费。
|
|
1048
|
+
*/
|
|
1049
|
+
const buildPathGeometry = (rawPath) => {
|
|
1050
|
+
const commands = parsePathData(rawPath);
|
|
1051
|
+
if (!commands)
|
|
1052
|
+
return { contours: [], dims: { x: 0, y: 0 } };
|
|
1053
|
+
const bounds = getBoundsOfPath(commands);
|
|
1054
|
+
const contours = flattenPathCommands(commands);
|
|
1055
|
+
if (!bounds)
|
|
1056
|
+
return { contours, dims: { x: 0, y: 0 } };
|
|
1057
|
+
const cx = (bounds.left + bounds.right) / 2;
|
|
1058
|
+
const cy = (bounds.top + bounds.bottom) / 2;
|
|
1059
|
+
// 轮廓平移到中心系(命中按 canvas fill 偶奇/非零口径在原始轮廓上算,中心系等价)
|
|
1060
|
+
const centered = contours.map((c) => ({ closed: c.closed, points: c.points.map((p) => ({ x: p.x - cx, y: p.y - cy })) }));
|
|
1061
|
+
return { contours: centered, dims: { x: bounds.right - bounds.left, y: bounds.bottom - bounds.top } };
|
|
1060
1062
|
};
|
|
1061
1063
|
/**
|
|
1062
1064
|
* 填充形状节点(Phase 3 P3-1):ellipse/circle/polygon/polyline。
|
|
@@ -1085,14 +1087,14 @@ export class ShapeNode extends SceneNode {
|
|
|
1085
1087
|
if (this._mesh === undefined) {
|
|
1086
1088
|
const raw = this.raw;
|
|
1087
1089
|
const kind = this.shapeKind;
|
|
1088
|
-
if (kind ===
|
|
1090
|
+
if (kind === ElementTypes.ELLIPSE) {
|
|
1089
1091
|
this._mesh = buildEllipseMesh(raw.rx ?? 0, raw.ry ?? 0);
|
|
1090
1092
|
}
|
|
1091
|
-
else if (kind ===
|
|
1093
|
+
else if (kind === ElementTypes.CIRCLE) {
|
|
1092
1094
|
const r = raw.radius ?? 0;
|
|
1093
1095
|
this._mesh = buildEllipseMesh(r, r);
|
|
1094
1096
|
}
|
|
1095
|
-
else if (kind ===
|
|
1097
|
+
else if (kind === ElementTypes.TRIANGLE) {
|
|
1096
1098
|
this._mesh = buildPolygonMesh(trianglePoints(raw));
|
|
1097
1099
|
}
|
|
1098
1100
|
else {
|
|
@@ -1105,11 +1107,11 @@ export class ShapeNode extends SceneNode {
|
|
|
1105
1107
|
get dims() {
|
|
1106
1108
|
const raw = this.raw;
|
|
1107
1109
|
const kind = this.shapeKind;
|
|
1108
|
-
if (kind ===
|
|
1110
|
+
if (kind === ElementTypes.ELLIPSE)
|
|
1109
1111
|
return { x: 2 * (raw.rx ?? 0), y: 2 * (raw.ry ?? 0) };
|
|
1110
|
-
if (kind ===
|
|
1112
|
+
if (kind === ElementTypes.CIRCLE)
|
|
1111
1113
|
return { x: 2 * (raw.radius ?? 0), y: 2 * (raw.radius ?? 0) };
|
|
1112
|
-
if (kind ===
|
|
1114
|
+
if (kind === ElementTypes.TRIANGLE)
|
|
1113
1115
|
return { x: raw.width ?? 0, y: raw.height ?? 0 };
|
|
1114
1116
|
return polygonDims(raw.points);
|
|
1115
1117
|
}
|
|
@@ -1121,7 +1123,7 @@ export class ShapeNode extends SceneNode {
|
|
|
1121
1123
|
return hitStrokeVisible(this) && this.outlineStrokeHitAt(x, y, hitBand);
|
|
1122
1124
|
const local = this.localPoint(x, y);
|
|
1123
1125
|
const kind = this.shapeKind;
|
|
1124
|
-
if (kind ===
|
|
1126
|
+
if (kind === ElementTypes.ELLIPSE || kind === ElementTypes.CIRCLE) {
|
|
1125
1127
|
const rx = this.dims.x / 2;
|
|
1126
1128
|
const ry = this.dims.y / 2;
|
|
1127
1129
|
if (!(rx > 0) || !(ry > 0))
|
|
@@ -1131,13 +1133,13 @@ export class ShapeNode extends SceneNode {
|
|
|
1131
1133
|
return nx * nx + ny * ny <= 1;
|
|
1132
1134
|
}
|
|
1133
1135
|
const mesh = this.shapeMesh;
|
|
1134
|
-
if (kind ===
|
|
1136
|
+
if (kind === ElementTypes.POLYLINE || kind === ElementTypes.POLYGON) {
|
|
1135
1137
|
// 空填充 polyline/polygon(线段工具产物——2 点无网格)按描边命中带
|
|
1136
1138
|
// (fabric perPixelTargetFind 口径,半径与 LineNode.containsPoint 同源);
|
|
1137
1139
|
// 有填充仍走网格偶奇
|
|
1138
1140
|
if (mesh)
|
|
1139
1141
|
return pointInPolygon(mesh.verts, local.x, local.y);
|
|
1140
|
-
return polylineStrokeHit(this.raw.points, local, kind ===
|
|
1142
|
+
return polylineStrokeHit(this.raw.points, local, kind === ElementTypes.POLYGON, Math.max((Number(this.raw.strokeWidth) || 1) / 2, 3, hitBand));
|
|
1141
1143
|
}
|
|
1142
1144
|
if (!mesh)
|
|
1143
1145
|
return false;
|
|
@@ -1150,7 +1152,7 @@ export class ShapeNode extends SceneNode {
|
|
|
1150
1152
|
const local = this.localPoint(x, y);
|
|
1151
1153
|
const kind = this.shapeKind;
|
|
1152
1154
|
const r = strokeHitRadius(this, hitBand);
|
|
1153
|
-
if (kind ===
|
|
1155
|
+
if (kind === ElementTypes.ELLIPSE || kind === ElementTypes.CIRCLE) {
|
|
1154
1156
|
const rx = this.dims.x / 2;
|
|
1155
1157
|
const ry = this.dims.y / 2;
|
|
1156
1158
|
if (!(rx > 0) || !(ry > 0))
|
|
@@ -1163,9 +1165,9 @@ export class ShapeNode extends SceneNode {
|
|
|
1163
1165
|
const g = (local.x * local.x) / (rx * rx) + (local.y * local.y) / (ry * ry) - 1;
|
|
1164
1166
|
return Math.abs(g) / gl <= r;
|
|
1165
1167
|
}
|
|
1166
|
-
if (kind ===
|
|
1168
|
+
if (kind === ElementTypes.TRIANGLE)
|
|
1167
1169
|
return polylineStrokeHit(trianglePoints(this.raw), local, true, r);
|
|
1168
|
-
return polylineStrokeHit(this.raw.points, local, kind ===
|
|
1170
|
+
return polylineStrokeHit(this.raw.points, local, kind === ElementTypes.POLYGON, r);
|
|
1169
1171
|
}
|
|
1170
1172
|
}
|
|
1171
1173
|
/** fabric Triangle 的顶点合成(_render 逐式:本地系 (w/2,0)→(w,h)→(0,h);
|
|
@@ -1319,27 +1321,44 @@ const polylineStrokeHit = (rawPoints, local, closed, r) => {
|
|
|
1319
1321
|
*/
|
|
1320
1322
|
export class PathNode extends ShapeNode {
|
|
1321
1323
|
_pathGeo;
|
|
1324
|
+
/** 填充多边形(洞合成)与三角网格:三层懒(批次 415)——建景只付
|
|
1325
|
+
* parse+flatten+dims(dims/命中必需);洞合成与三角化是 PDF 长 path 的
|
|
1326
|
+
* 秒级主项,懒到首渲染(shapeMesh 读点全在渲染/烘焙期)。失效键与
|
|
1327
|
+
* _pathGeo 同源(path/fillRule),一次清三层 */
|
|
1328
|
+
_fillPolys;
|
|
1329
|
+
_pathMesh;
|
|
1322
1330
|
set(props) {
|
|
1323
1331
|
super.set(props);
|
|
1324
|
-
// 路径几何化(parse+flatten
|
|
1332
|
+
// 路径几何化(parse+flatten/洞合成/三角化)只依赖 path/fillRule(批次 221);
|
|
1325
1333
|
// 纯姿态写入(拖拽/缩放手势)保缓存——万级 stress 多选 50% path 的主卡顿源。
|
|
1326
1334
|
// 批次 337 收窄为按键存在性精确失效:app setCanvasObject 的选中链惰性规范化
|
|
1327
1335
|
// 键(setObjectEffects 每帧直写 effectFill/effectStroke/effectShadow、
|
|
1328
1336
|
// maskURL——TextNode 位图转正防线已同族豁免)不参与几何,但「非姿态键即
|
|
1329
1337
|
// 失效」的旧口径把它们全算进去了——1565 子路径级 PSD 网格 path 单次重建
|
|
1330
1338
|
// ~500ms,拖拽/抬手被逐帧重算(真机 LoAF onUp 481ms 主源)
|
|
1331
|
-
if ('path' in props || 'fillRule' in props)
|
|
1339
|
+
if ('path' in props || 'fillRule' in props) {
|
|
1332
1340
|
this._pathGeo = undefined;
|
|
1341
|
+
this._fillPolys = undefined;
|
|
1342
|
+
this._pathMesh = undefined;
|
|
1343
|
+
}
|
|
1333
1344
|
}
|
|
1334
1345
|
get pathGeometry() {
|
|
1335
|
-
if (this._pathGeo === undefined)
|
|
1346
|
+
if (this._pathGeo === undefined)
|
|
1347
|
+
this._pathGeo = buildPathGeometry(this.raw.path);
|
|
1348
|
+
return this._pathGeo;
|
|
1349
|
+
}
|
|
1350
|
+
/** 洞合成(桥接多边形集):纯函数重算可缓存,raw.fillRule 读位同旧实现 */
|
|
1351
|
+
get fillPolygons() {
|
|
1352
|
+
if (this._fillPolys === undefined) {
|
|
1336
1353
|
const rule = this.raw.fillRule === 'evenodd' ? 'evenodd' : 'nonzero';
|
|
1337
|
-
this.
|
|
1354
|
+
this._fillPolys = contoursToFillPolygons(this.pathGeometry.contours, rule);
|
|
1338
1355
|
}
|
|
1339
|
-
return this.
|
|
1356
|
+
return this._fillPolys;
|
|
1340
1357
|
}
|
|
1341
1358
|
get shapeMesh() {
|
|
1342
|
-
|
|
1359
|
+
if (this._pathMesh === undefined)
|
|
1360
|
+
this._pathMesh = buildFillMesh(this.fillPolygons);
|
|
1361
|
+
return this._pathMesh;
|
|
1343
1362
|
}
|
|
1344
1363
|
get dims() {
|
|
1345
1364
|
// 几何化缓存直取(批次 221):此前每次访问都 parsePathData+getBoundsOfPath——
|
|
@@ -1491,9 +1510,9 @@ export class LineNode extends SceneNode {
|
|
|
1491
1510
|
return true;
|
|
1492
1511
|
// 装饰命中扩展:类型键小写归一(批次46 勘注——raw 两形态并存)
|
|
1493
1512
|
const rawType = this.typeKey;
|
|
1494
|
-
if (rawType ===
|
|
1513
|
+
if (rawType === ElementTypes.ARROW)
|
|
1495
1514
|
return arrowHeadHit(this.raw, local, p);
|
|
1496
|
-
if (rawType ===
|
|
1515
|
+
if (rawType === ElementTypes.DIMENSION)
|
|
1497
1516
|
return dimensionDecorHit(this.raw, local, p, r);
|
|
1498
1517
|
return false;
|
|
1499
1518
|
}
|
package/dist/model/shapePath.js
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import { getBoundsOfPath, parsePathData } from '../core/pathData';
|
|
21
21
|
import { rectCornerRadii } from '../core/roundedRect';
|
|
22
|
+
import { ElementTypes, typeKeyOf } from './elementTypes';
|
|
22
23
|
const num = (value, fallback = 0) => (typeof value === 'number' && Number.isFinite(value) ? value : fallback);
|
|
23
24
|
/** scale 读位(缺省 1,零值兜 1 防除零/零尺寸) */
|
|
24
25
|
const scaleOf = (raw) => ({
|
|
@@ -71,15 +72,15 @@ export const buildEngineShapePath = (node) => {
|
|
|
71
72
|
if (node.isTextType)
|
|
72
73
|
return undefined;
|
|
73
74
|
const raw = node.raw;
|
|
74
|
-
const type =
|
|
75
|
+
const type = typeKeyOf(raw);
|
|
75
76
|
const { sx, sy } = scaleOf(raw);
|
|
76
|
-
if (type ===
|
|
77
|
+
if (type === ElementTypes.PATH) {
|
|
77
78
|
const path = typeof raw.path === 'string' ? raw.path : '';
|
|
78
79
|
if (!path.trim())
|
|
79
80
|
return undefined;
|
|
80
81
|
return { path, pathOffset: declaredOffset(raw) ?? pathBoundsCenter(path) ?? { x: 0, y: 0 } };
|
|
81
82
|
}
|
|
82
|
-
if (type ===
|
|
83
|
+
if (type === ElementTypes.RECT || type === ElementTypes.FABRICRECT) {
|
|
83
84
|
const w = node.dims.x * sx;
|
|
84
85
|
const h = node.dims.y * sy;
|
|
85
86
|
if (!(w > 0) || !(h > 0))
|
|
@@ -91,34 +92,34 @@ export const buildEngineShapePath = (node) => {
|
|
|
91
92
|
const path = rx > 0 || ry > 0 ? roundedRectPath(w, h, rx, ry) : `M 0 0 L ${w} 0 L ${w} ${h} L 0 ${h} Z`;
|
|
92
93
|
return { path, pathOffset: { x: w / 2, y: h / 2 } };
|
|
93
94
|
}
|
|
94
|
-
if (type ===
|
|
95
|
+
if (type === ElementTypes.CIRCLE) {
|
|
95
96
|
const r = num(raw.radius);
|
|
96
97
|
if (!(r > 0))
|
|
97
98
|
return undefined;
|
|
98
99
|
return { path: ellipsePath(r * sx, r * sy), pathOffset: { x: 0, y: 0 } };
|
|
99
100
|
}
|
|
100
|
-
if (type ===
|
|
101
|
+
if (type === ElementTypes.ELLIPSE) {
|
|
101
102
|
const rx = (num(raw.rx) || node.dims.x / 2) * sx;
|
|
102
103
|
const ry = (num(raw.ry) || node.dims.y / 2) * sy;
|
|
103
104
|
if (!(rx > 0) || !(ry > 0))
|
|
104
105
|
return undefined;
|
|
105
106
|
return { path: ellipsePath(rx, ry), pathOffset: { x: 0, y: 0 } };
|
|
106
107
|
}
|
|
107
|
-
if (type ===
|
|
108
|
+
if (type === ElementTypes.TRIANGLE) {
|
|
108
109
|
const w = node.dims.x * sx;
|
|
109
110
|
const h = node.dims.y * sy;
|
|
110
111
|
if (!(w > 0) || !(h > 0))
|
|
111
112
|
return undefined;
|
|
112
113
|
return { path: `M ${-w / 2} ${h / 2} L 0 ${-h / 2} L ${w / 2} ${h / 2} Z`, pathOffset: { x: 0, y: 0 } };
|
|
113
114
|
}
|
|
114
|
-
if (type ===
|
|
115
|
+
if (type === ElementTypes.POLYGON || type === ElementTypes.POLYLINE) {
|
|
115
116
|
const points = Array.isArray(raw.points) ? raw.points : [];
|
|
116
117
|
if (points.length === 0)
|
|
117
118
|
return { path: 'M 0 0', pathOffset: { x: 0, y: 0 } };
|
|
118
|
-
const path = points.map((p, i) => `${i === 0 ? 'M' : 'L'} ${p.x} ${p.y}`).join(' ') + (type ===
|
|
119
|
+
const path = points.map((p, i) => `${i === 0 ? 'M' : 'L'} ${p.x} ${p.y}`).join(' ') + (type === ElementTypes.POLYGON ? ' Z' : '');
|
|
119
120
|
return { path, pathOffset: declaredOffset(raw) ?? pointsBoundsCenter(points) ?? { x: 0, y: 0 } };
|
|
120
121
|
}
|
|
121
|
-
if (type ===
|
|
122
|
+
if (type === ElementTypes.LINE) {
|
|
122
123
|
const x1 = num(raw.x1);
|
|
123
124
|
const y1 = num(raw.y1);
|
|
124
125
|
const x2 = num(raw.x2);
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 场景渲染器(从 EngineCanvas 拆出,main-webgl2 重构;烘焙族再外拆)。
|
|
3
|
+
*
|
|
4
|
+
* 本文件是逐节点渲染分派核心(组递归/clipPath 隔离/文本/形状/线族/动画族/
|
|
5
|
+
* 图片族)与组隔离(FBO 合成)+ 拼图钳制状态。四族烘焙已外拆为独立画家
|
|
6
|
+
* (各自持 WeakMap 缓存与失效口径):ShadowPainter(原生阴影)/
|
|
7
|
+
* PsdEffectPainter(PS 图层样式)/ StrokePainter(描边)/ ClipMaskPainter
|
|
8
|
+
* (clipPath 剪影);双消费的 GPU 画家(GpuFxPainter/GpuImageFilterChain)
|
|
9
|
+
* 归 SharedGpuPainters 共享持有(防双实例重复占显存)。跨层读取(zoom/dpr/
|
|
10
|
+
* vpt/画布尺寸/编辑态)经 SceneRendererHost 注入;帧级状态(PSD 烘焙预算、
|
|
11
|
+
* 动画自续标记)挂在 frame 上,由 EngineCanvas.render 每帧 beginFrame 复位、
|
|
12
|
+
* 渲染尾部消费——不做参数穿透(renderSceneNode↔renderIsolatedGroup 互递归)。
|
|
13
|
+
*/
|
|
14
|
+
import { parseColor } from '../core/color';
|
|
1
15
|
import { renderViewportOf } from './renderViewport';
|
|
2
16
|
import { gradientSpaceMatrix } from '../core/gradient';
|
|
3
17
|
import { patternSpaceMatrix, repeatFlags } from '../core/pattern';
|
|
@@ -642,7 +656,13 @@ export class SceneRenderer {
|
|
|
642
656
|
if (!(x > 0) || !(y > 0))
|
|
643
657
|
return;
|
|
644
658
|
const opacity = node.renderOpacity;
|
|
645
|
-
|
|
659
|
+
// 批次 415 补四(用户点名):占位优先节点自带 fill——PDF 解析的图片对象
|
|
660
|
+
// 恒带 fill(图片区域终态由位图呈现,fill 仅装载期占位借色,图源就绪即被
|
|
661
|
+
// 位图替换);透明/缺省/病态形态(批次 341 毒化守卫→透明)回落中性灰。
|
|
662
|
+
// parseColor 的非串守卫使渐变/图案对象形态安全走回落
|
|
663
|
+
const fill = parseColor(node.raw.fill);
|
|
664
|
+
const base = fill[3] > 0 ? fill : IMAGE_PLACEHOLDER_COLOR;
|
|
665
|
+
this.host.batch.pushQuad(node.matrix, x, y, [base[0], base[1], base[2], base[3] * opacity], null, [0, 0, 1, 1], this.quadRadii(node), node);
|
|
646
666
|
}
|
|
647
667
|
/**
|
|
648
668
|
* quad 圆角解析(批次 98):rect 族走 rectCornerRadii(FabricRect 族 radius
|
|
@@ -2,12 +2,82 @@ import { type SceneNode, type SerializedNode } from '../model/scene';
|
|
|
2
2
|
import type { GroupMaskTexture } from './GLIsolate';
|
|
3
3
|
import type { SharedGpuPainters } from './sharedGpuPainters';
|
|
4
4
|
import type { SceneRendererHost } from './SceneRenderer';
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* 平移无关烘焙签名(批次 416):decl JSON + 投影线性分量(a-d)+ 画布尺寸。
|
|
7
|
+
* 投影全阵 tm = dpr×viewport×host×clip 的平移分量(e/f)不入签——纯滚动
|
|
8
|
+
* (vpt/宿主平移)下整屏剪影位图 = 旧位图平移,数学等价可复用。
|
|
9
|
+
*/
|
|
10
|
+
export declare const clipMaskBakeSig: (declJSON: string, tm: readonly number[], cw: number, ch: number) => string;
|
|
11
|
+
/**
|
|
12
|
+
* 纯平移差的蒙版复用补偿(批次 416):滚动帧命中平移无关签名时,maskInv
|
|
13
|
+
* 平移列(列主序数组位 6/7)加整数像素 uv 偏移——旧位图按 Δ 平移采样。
|
|
14
|
+
* 取整像素避免纹理插值软化 AA 边缘;残差恒 <1px(相对烘焙原点,不累积),
|
|
15
|
+
* 蒙版边缘本为 1px 级 AA 带不可感。Δ 为零返回原数组(引用恒等——帧内
|
|
16
|
+
* 零开销路径)。符号:采样位置 = 屏幕位 − Δ(M₁(px)=M₀(px−d))→ 平移列
|
|
17
|
+
* 减 Δ/尺寸(y 方向经 maskInv 自带翻转,推导同向)。
|
|
18
|
+
*/
|
|
19
|
+
export declare const clipMaskPanShiftInv: (base: readonly number[], dxRaw: number, dyRaw: number, cw: number, ch: number) => readonly number[];
|
|
20
|
+
/**
|
|
21
|
+
* 剪影形状投影 bbox(批次 416 勘注二提纯):dims 中心系四角(±w/2,±h/2)
|
|
22
|
+
* 经全链 tm(view×host×clip,中心系原点=矩阵原点)——与 aCoords+分解矩阵
|
|
23
|
+
* 口径等价且免重复乘 clip 自身矩阵的陷阱;画布物理像素域。
|
|
24
|
+
*/
|
|
25
|
+
export declare const clipMaskProjectedBBox: (dims: {
|
|
26
|
+
x: number;
|
|
27
|
+
y: number;
|
|
28
|
+
}, tm: readonly number[]) => {
|
|
29
|
+
minX: number;
|
|
30
|
+
minY: number;
|
|
31
|
+
maxX: number;
|
|
32
|
+
maxY: number;
|
|
33
|
+
} | null;
|
|
34
|
+
/**
|
|
35
|
+
* 剪影形状投影与画布的相交判定(批次 416 勘注):多页分段帧把所有页逐段
|
|
36
|
+
* 全渲——远离视口的页(如第 5 页)的组在懒建造首渲染时就走 mask(),形状
|
|
37
|
+
* 投影在整屏位图外 → 烘出全黑蒙版;平移无关签名使滚到位后也永不重烘 →
|
|
38
|
+
* 组内图片被全黑蒙版裁没(用户实测第 5 页图片消失)。画布外不烘(null=
|
|
39
|
+
* 不裁,画布外本就无帧内容),形状进画布(含部分相交)才首烘。
|
|
40
|
+
*/
|
|
41
|
+
export declare const clipMaskShapeOnCanvas: (dims: {
|
|
42
|
+
x: number;
|
|
43
|
+
y: number;
|
|
44
|
+
}, tm: readonly number[], cw: number, ch: number) => boolean;
|
|
45
|
+
/**
|
|
46
|
+
* 烘焙位图域(批次 416 勘注二)= 形状投影 bbox ∪ 画布 的包围盒——部分相交
|
|
47
|
+
* 首烘时形状画布外切片也须入图(勘注一残留缺陷:整屏位图只含画布内切片,
|
|
48
|
+
* 滚动后新进画布的形状部分在图上是黑=被裁,用户实测「图文只露出一点」)。
|
|
49
|
+
* 任何未来平移采样的 p−d 恒落画布域 ⊆ 并集 → 复用完备。位图域原点/尺寸
|
|
50
|
+
* 同时是 maskInv 组装与平移补偿的分母。
|
|
51
|
+
*/
|
|
52
|
+
export declare const clipMaskBakeDomain: (bb: {
|
|
53
|
+
minX: number;
|
|
54
|
+
minY: number;
|
|
55
|
+
maxX: number;
|
|
56
|
+
maxY: number;
|
|
57
|
+
}, cw: number, ch: number) => {
|
|
58
|
+
bx0: number;
|
|
59
|
+
by0: number;
|
|
60
|
+
bw: number;
|
|
61
|
+
bh: number;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* 烘焙位图的 vUv→位图 uv 映射(列主序 mat3,批次 416 勘注二全式化):
|
|
65
|
+
* 屏幕像素 px=vUv.x×cw / py=(1−vUv.y)×ch(y 翻转),位图坐标=(px−bx0)/bw。
|
|
66
|
+
* 全屏域(bx0=by0=0、bw=cw、bh=ch)退化为勘注前的 [1,0,0,0,-1,0,0,1,1]。
|
|
67
|
+
*/
|
|
68
|
+
export declare const clipMaskBakeInv: (dom: {
|
|
69
|
+
bx0: number;
|
|
70
|
+
by0: number;
|
|
71
|
+
bw: number;
|
|
72
|
+
bh: number;
|
|
73
|
+
}, cw: number, ch: number) => readonly number[];
|
|
6
74
|
export declare const clipDecl: (node: SceneNode) => SerializedNode | null;
|
|
7
75
|
export declare class ClipMaskPainter {
|
|
8
76
|
private readonly host;
|
|
9
77
|
private readonly gpu;
|
|
10
|
-
/** clipPath 剪影纹理缓存(P4-3:节点 → {sig, mask}
|
|
78
|
+
/** clipPath 剪影纹理缓存(P4-3:节点 → {sig, panX, panY, bw, bh, mask};
|
|
79
|
+
* sig 平移无关(批次 416 滚动复用),panX/panY 为烘焙时投影平移,
|
|
80
|
+
* bw/bh 为位图域尺寸(勘注二:平移补偿的分母) */
|
|
11
81
|
private clipBakes;
|
|
12
82
|
constructor(host: SceneRendererHost, gpu: SharedGpuPainters);
|
|
13
83
|
/** 剪影蒙版纹理与屏幕 uv 摆放(无合法声明/GPU 失败返回 null) */
|