@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
|
@@ -14,30 +14,126 @@ import { renderViewportOf } from './renderViewport';
|
|
|
14
14
|
import { isGpuClipMaskEnabled } from '../engineFlag';
|
|
15
15
|
import { buildRoundedRectMesh, rectCornerRadii } from '../core/roundedRect';
|
|
16
16
|
import { createNode, SHAPE_TYPES, ShapeNode } from '../model/scene';
|
|
17
|
+
import { ElementTypes, typeKeyOf } from '../model/elementTypes';
|
|
17
18
|
import { traceShapeStrokePath } from './strokeBake';
|
|
18
19
|
import { createTexture2D } from './textureUpload';
|
|
19
|
-
/** clipPath
|
|
20
|
-
const SHAPE_CLIP_TYPES = new Set([...SHAPE_TYPES
|
|
21
|
-
/**
|
|
20
|
+
/** clipPath 声明的合法类型(typeKey 归一,批次 98):SHAPE_TYPES ∪ rect 族 */
|
|
21
|
+
const SHAPE_CLIP_TYPES = new Set([...SHAPE_TYPES, ElementTypes.RECT, ElementTypes.FABRICRECT]);
|
|
22
|
+
/**
|
|
23
|
+
* 平移无关烘焙签名(批次 416):decl JSON + 投影线性分量(a-d)+ 画布尺寸。
|
|
24
|
+
* 投影全阵 tm = dpr×viewport×host×clip 的平移分量(e/f)不入签——纯滚动
|
|
25
|
+
* (vpt/宿主平移)下整屏剪影位图 = 旧位图平移,数学等价可复用。
|
|
26
|
+
*/
|
|
27
|
+
export const clipMaskBakeSig = (declJSON, tm, cw, ch) => [declJSON, tm[0], tm[1], tm[2], tm[3], cw, ch].join(';');
|
|
28
|
+
/**
|
|
29
|
+
* 纯平移差的蒙版复用补偿(批次 416):滚动帧命中平移无关签名时,maskInv
|
|
30
|
+
* 平移列(列主序数组位 6/7)加整数像素 uv 偏移——旧位图按 Δ 平移采样。
|
|
31
|
+
* 取整像素避免纹理插值软化 AA 边缘;残差恒 <1px(相对烘焙原点,不累积),
|
|
32
|
+
* 蒙版边缘本为 1px 级 AA 带不可感。Δ 为零返回原数组(引用恒等——帧内
|
|
33
|
+
* 零开销路径)。符号:采样位置 = 屏幕位 − Δ(M₁(px)=M₀(px−d))→ 平移列
|
|
34
|
+
* 减 Δ/尺寸(y 方向经 maskInv 自带翻转,推导同向)。
|
|
35
|
+
*/
|
|
36
|
+
export const clipMaskPanShiftInv = (base, dxRaw, dyRaw, cw, ch) => {
|
|
37
|
+
const dx = Math.round(dxRaw);
|
|
38
|
+
const dy = Math.round(dyRaw);
|
|
39
|
+
if (dx === 0 && dy === 0)
|
|
40
|
+
return base;
|
|
41
|
+
const inv = [...base];
|
|
42
|
+
inv[6] -= dx / cw;
|
|
43
|
+
inv[7] -= dy / ch;
|
|
44
|
+
return inv;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* 剪影形状投影 bbox(批次 416 勘注二提纯):dims 中心系四角(±w/2,±h/2)
|
|
48
|
+
* 经全链 tm(view×host×clip,中心系原点=矩阵原点)——与 aCoords+分解矩阵
|
|
49
|
+
* 口径等价且免重复乘 clip 自身矩阵的陷阱;画布物理像素域。
|
|
50
|
+
*/
|
|
51
|
+
export const clipMaskProjectedBBox = (dims, tm) => {
|
|
52
|
+
if (!(dims.x > 0) || !(dims.y > 0))
|
|
53
|
+
return null;
|
|
54
|
+
const hw = dims.x / 2;
|
|
55
|
+
const hh = dims.y / 2;
|
|
56
|
+
let minX = Infinity;
|
|
57
|
+
let minY = Infinity;
|
|
58
|
+
let maxX = -Infinity;
|
|
59
|
+
let maxY = -Infinity;
|
|
60
|
+
for (const [cx, cy] of [
|
|
61
|
+
[-hw, -hh],
|
|
62
|
+
[hw, -hh],
|
|
63
|
+
[hw, hh],
|
|
64
|
+
[-hw, hh]
|
|
65
|
+
]) {
|
|
66
|
+
const x = tm[0] * cx + tm[2] * cy + tm[4];
|
|
67
|
+
const y = tm[1] * cx + tm[3] * cy + tm[5];
|
|
68
|
+
if (minX > x)
|
|
69
|
+
minX = x;
|
|
70
|
+
if (minY > y)
|
|
71
|
+
minY = y;
|
|
72
|
+
if (maxX < x)
|
|
73
|
+
maxX = x;
|
|
74
|
+
if (maxY < y)
|
|
75
|
+
maxY = y;
|
|
76
|
+
}
|
|
77
|
+
return { minX, minY, maxX, maxY };
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* 剪影形状投影与画布的相交判定(批次 416 勘注):多页分段帧把所有页逐段
|
|
81
|
+
* 全渲——远离视口的页(如第 5 页)的组在懒建造首渲染时就走 mask(),形状
|
|
82
|
+
* 投影在整屏位图外 → 烘出全黑蒙版;平移无关签名使滚到位后也永不重烘 →
|
|
83
|
+
* 组内图片被全黑蒙版裁没(用户实测第 5 页图片消失)。画布外不烘(null=
|
|
84
|
+
* 不裁,画布外本就无帧内容),形状进画布(含部分相交)才首烘。
|
|
85
|
+
*/
|
|
86
|
+
export const clipMaskShapeOnCanvas = (dims, tm, cw, ch) => {
|
|
87
|
+
const bb = clipMaskProjectedBBox(dims, tm);
|
|
88
|
+
if (!bb)
|
|
89
|
+
return false;
|
|
90
|
+
return bb.maxX >= 0 && bb.minX <= cw && bb.maxY >= 0 && bb.minY <= ch;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* 烘焙位图域(批次 416 勘注二)= 形状投影 bbox ∪ 画布 的包围盒——部分相交
|
|
94
|
+
* 首烘时形状画布外切片也须入图(勘注一残留缺陷:整屏位图只含画布内切片,
|
|
95
|
+
* 滚动后新进画布的形状部分在图上是黑=被裁,用户实测「图文只露出一点」)。
|
|
96
|
+
* 任何未来平移采样的 p−d 恒落画布域 ⊆ 并集 → 复用完备。位图域原点/尺寸
|
|
97
|
+
* 同时是 maskInv 组装与平移补偿的分母。
|
|
98
|
+
*/
|
|
99
|
+
export const clipMaskBakeDomain = (bb, cw, ch) => {
|
|
100
|
+
const bx0 = Math.min(bb.minX, 0);
|
|
101
|
+
const by0 = Math.min(bb.minY, 0);
|
|
102
|
+
return { bx0, by0, bw: Math.max(bb.maxX, cw) - bx0, bh: Math.max(bb.maxY, ch) - by0 };
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* 烘焙位图的 vUv→位图 uv 映射(列主序 mat3,批次 416 勘注二全式化):
|
|
106
|
+
* 屏幕像素 px=vUv.x×cw / py=(1−vUv.y)×ch(y 翻转),位图坐标=(px−bx0)/bw。
|
|
107
|
+
* 全屏域(bx0=by0=0、bw=cw、bh=ch)退化为勘注前的 [1,0,0,0,-1,0,0,1,1]。
|
|
108
|
+
*/
|
|
109
|
+
export const clipMaskBakeInv = (dom, cw, ch) => [
|
|
110
|
+
cw / dom.bw,
|
|
111
|
+
0,
|
|
112
|
+
0,
|
|
113
|
+
0,
|
|
114
|
+
-ch / dom.bh,
|
|
115
|
+
0,
|
|
116
|
+
-dom.bx0 / dom.bw,
|
|
117
|
+
(ch - dom.by0) / dom.bh,
|
|
118
|
+
1
|
|
119
|
+
];
|
|
22
120
|
export const clipDecl = (node) => {
|
|
23
121
|
const cp = node.raw.clipPath;
|
|
24
122
|
if (!cp || typeof cp !== 'object' || Array.isArray(cp))
|
|
25
123
|
return null;
|
|
26
|
-
const type = cp.type;
|
|
27
|
-
if (typeof type !== 'string')
|
|
28
|
-
return null;
|
|
29
124
|
// 形状族 + rect(SOLID 族——traceShapeStrokePath 的 rect 分支同样覆盖;
|
|
30
|
-
// 曾漏 rect 致 rect
|
|
125
|
+
// 曾漏 rect 致 rect 裁剪静默失效)。typeKey 归一:clipPath 子节点 type 恒走
|
|
31
126
|
// toObject 注册名('Rect'/'FabricRect' 大写档与 trace 的归一口径一致,批次 98)
|
|
32
|
-
|
|
33
|
-
if (!SHAPE_CLIP_TYPES.has(lower))
|
|
127
|
+
if (!SHAPE_CLIP_TYPES.has(typeKeyOf(cp)))
|
|
34
128
|
return null;
|
|
35
129
|
return cp;
|
|
36
130
|
};
|
|
37
131
|
export class ClipMaskPainter {
|
|
38
132
|
host;
|
|
39
133
|
gpu;
|
|
40
|
-
/** clipPath 剪影纹理缓存(P4-3:节点 → {sig, mask}
|
|
134
|
+
/** clipPath 剪影纹理缓存(P4-3:节点 → {sig, panX, panY, bw, bh, mask};
|
|
135
|
+
* sig 平移无关(批次 416 滚动复用),panX/panY 为烘焙时投影平移,
|
|
136
|
+
* bw/bh 为位图域尺寸(勘注二:平移补偿的分母) */
|
|
41
137
|
clipBakes = new WeakMap();
|
|
42
138
|
constructor(host, gpu) {
|
|
43
139
|
this.host = host;
|
|
@@ -75,23 +171,41 @@ export class ClipMaskPainter {
|
|
|
75
171
|
}
|
|
76
172
|
return null;
|
|
77
173
|
}
|
|
78
|
-
|
|
174
|
+
// 批次 416:签名平移无关化——旧签 [decl, clipWorld, viewport, 尺寸] 含
|
|
175
|
+
// 平移分量,纯滚动(vpt/宿主 pan 变化)每帧失效:整屏 canvas 白填 +
|
|
176
|
+
// texImage2D 重传/可见组/帧是真机滚动卡顿主项(hook 实测 399 次/3s)。
|
|
177
|
+
// 命中签名时按平移差整数像素补偿 maskInv 复用位图(数学等价);宿主
|
|
178
|
+
// 旋转/缩放/视口缩放仍走线性分量变化 → 重烘
|
|
179
|
+
const declJSON = JSON.stringify({ ...decl, objects: undefined });
|
|
180
|
+
const view = multiply([this.host.dpr, 0, 0, this.host.dpr, 0, 0], viewport);
|
|
181
|
+
const tm = multiply(view, clipWorld);
|
|
182
|
+
// 画布外不烘(批次 416 勘注):分段帧全页渲染使远页组在画布外首烘——
|
|
183
|
+
// 全黑蒙版 + 平移复用永不重烘 = 图片被裁没;进画布才首烘
|
|
184
|
+
if (!clipMaskShapeOnCanvas(clipNode.dims, tm, cw, ch))
|
|
185
|
+
return null;
|
|
186
|
+
const sig = clipMaskBakeSig(declJSON, tm, cw, ch);
|
|
79
187
|
let bake = this.clipBakes.get(hostNode);
|
|
80
188
|
if (bake && bake.sig !== sig) {
|
|
81
189
|
this.host.gl.deleteTexture(bake.mask.tex);
|
|
82
190
|
bake = undefined;
|
|
83
191
|
}
|
|
84
192
|
if (!bake) {
|
|
193
|
+
// 位图域 = 形状 bbox ∪ 画布(勘注二):部分相交首烘把形状画布外切片
|
|
194
|
+
// 一并烘焙——纯平移复用完备(p−d ⊆ 画布域 ⊆ 位图域)
|
|
195
|
+
const bb = clipMaskProjectedBBox(clipNode.dims, tm);
|
|
196
|
+
if (!bb)
|
|
197
|
+
return null;
|
|
198
|
+
const dom = clipMaskBakeDomain(bb, cw, ch);
|
|
199
|
+
if (!(dom.bw > 0) || !(dom.bh > 0) || dom.bw > 8192 || dom.bh > 8192)
|
|
200
|
+
return null;
|
|
85
201
|
const canvas = document.createElement('canvas');
|
|
86
|
-
canvas.width =
|
|
87
|
-
canvas.height =
|
|
202
|
+
canvas.width = Math.ceil(dom.bw);
|
|
203
|
+
canvas.height = Math.ceil(dom.bh);
|
|
88
204
|
const ctx = canvas.getContext('2d');
|
|
89
205
|
if (!ctx)
|
|
90
206
|
return null;
|
|
91
|
-
// 场景矩阵 →
|
|
92
|
-
|
|
93
|
-
const tm = multiply(view, clipWorld);
|
|
94
|
-
ctx.setTransform(tm[0], tm[1], tm[2], tm[3], tm[4], tm[5]);
|
|
207
|
+
// 场景矩阵 → 位图像素(y 下)× dpr,平移分量平移到位图域原点
|
|
208
|
+
ctx.setTransform(tm[0], tm[1], tm[2], tm[3], tm[4] - dom.bx0, tm[5] - dom.by0);
|
|
95
209
|
ctx.fillStyle = '#ffffff';
|
|
96
210
|
if (!traceShapeStrokePath(ctx, clipNode))
|
|
97
211
|
return null;
|
|
@@ -101,20 +215,27 @@ export class ClipMaskPainter {
|
|
|
101
215
|
return null;
|
|
102
216
|
bake = {
|
|
103
217
|
sig,
|
|
218
|
+
panX: tm[4],
|
|
219
|
+
panY: tm[5],
|
|
220
|
+
bw: dom.bw,
|
|
221
|
+
bh: dom.bh,
|
|
104
222
|
mask: {
|
|
105
223
|
tex,
|
|
106
|
-
//
|
|
107
|
-
//
|
|
108
|
-
|
|
109
|
-
// → ma=uCovers=0——非反相宿主全灭、inverted 全显(不裁),批次 99 勘误
|
|
110
|
-
maskInv: [1, 0, 0, 0, -1, 0, 0, 1, 1],
|
|
224
|
+
// vUv → 位图域 uv(勘注二全式,含域原点缩放与 y 翻转;全屏域退化
|
|
225
|
+
// 为勘注前的 [1,0,0,0,-1,0,0,1,1])。列主序:平移常数落末列
|
|
226
|
+
maskInv: clipMaskBakeInv(dom, cw, ch),
|
|
111
227
|
coversHost: false,
|
|
112
228
|
invert: decl.inverted === true
|
|
113
229
|
}
|
|
114
230
|
};
|
|
115
231
|
this.clipBakes.set(hostNode, bake);
|
|
116
232
|
}
|
|
117
|
-
|
|
233
|
+
// 滚动复用(批次 416):纯平移差 → 整数像素 uv 补偿(取整在
|
|
234
|
+
// clipMaskPanShiftInv 内);Δ=0 恒等引用零开销
|
|
235
|
+
const inv = clipMaskPanShiftInv(bake.mask.maskInv, tm[4] - bake.panX, tm[5] - bake.panY, bake.bw, bake.bh);
|
|
236
|
+
if (inv === bake.mask.maskInv)
|
|
237
|
+
return bake.mask;
|
|
238
|
+
return { ...bake.mask, maskInv: inv };
|
|
118
239
|
}
|
|
119
240
|
/** 失效(context lost):烘焙整删——clipBakes 是几何蒙版剪影不含文本,字体迟到不动 */
|
|
120
241
|
invalidate() {
|
package/dist/render/gpuFx.js
CHANGED
|
@@ -483,12 +483,25 @@ export class GpuFxPainter {
|
|
|
483
483
|
}
|
|
484
484
|
if (!meshObj)
|
|
485
485
|
return null;
|
|
486
|
+
// ELEMENT_ARRAY_BUFFER 绑定属于 VAO 状态;首次上传网格前就隔离 VAO,
|
|
487
|
+
// 否则会覆盖调用方 QuadBatch 的 Uint16 索引绑定,后续图片退化为零面积三角形。
|
|
488
|
+
const vao = gl.createVertexArray();
|
|
489
|
+
if (!vao)
|
|
490
|
+
return null;
|
|
491
|
+
gl.bindVertexArray(vao);
|
|
486
492
|
let bufs = this.meshBufs.get(meshObj);
|
|
487
493
|
if (!bufs) {
|
|
488
494
|
const vbo = gl.createBuffer();
|
|
489
495
|
const ibo = gl.createBuffer();
|
|
490
|
-
if (!vbo || !ibo)
|
|
496
|
+
if (!vbo || !ibo) {
|
|
497
|
+
if (vbo)
|
|
498
|
+
gl.deleteBuffer(vbo);
|
|
499
|
+
if (ibo)
|
|
500
|
+
gl.deleteBuffer(ibo);
|
|
501
|
+
gl.bindVertexArray(null);
|
|
502
|
+
gl.deleteVertexArray(vao);
|
|
491
503
|
return null;
|
|
504
|
+
}
|
|
492
505
|
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
|
|
493
506
|
gl.bufferData(gl.ARRAY_BUFFER, meshObj.verts, gl.STATIC_DRAW);
|
|
494
507
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ibo);
|
|
@@ -496,10 +509,6 @@ export class GpuFxPainter {
|
|
|
496
509
|
bufs = { vbo, ibo, count: meshObj.triangles.length };
|
|
497
510
|
this.meshBufs.set(meshObj, bufs);
|
|
498
511
|
}
|
|
499
|
-
const vao = gl.createVertexArray();
|
|
500
|
-
if (!vao)
|
|
501
|
-
return null;
|
|
502
|
-
gl.bindVertexArray(vao);
|
|
503
512
|
gl.bindBuffer(gl.ARRAY_BUFFER, bufs.vbo);
|
|
504
513
|
const loc = gl.getAttribLocation(this.maskProg, 'aPos');
|
|
505
514
|
gl.enableVertexAttribArray(loc);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isStrokeSdfDashEnabled, isStrokeSdfLineDecorationEnabled } from '../engineFlag';
|
|
2
|
+
import { ElementTypes, typeKeyOf } from '../model/elementTypes';
|
|
2
3
|
import { segHash } from './segmentTable';
|
|
3
4
|
/** 描边码位段(与 strokeSdf.ts/shaders.ts 解码一致) */
|
|
4
5
|
const KIND_LINE = 2;
|
|
@@ -105,8 +106,8 @@ const readPoints = (raw) => {
|
|
|
105
106
|
* 烘焙的混血形态不做,383 原则)。几何源=raw.x1..y2(对象中心系)。
|
|
106
107
|
*/
|
|
107
108
|
export const lineDecorationPieces = (raw, decl, matrix, zoom, dpr) => {
|
|
108
|
-
const type =
|
|
109
|
-
if (type !==
|
|
109
|
+
const type = typeKeyOf(raw);
|
|
110
|
+
if (type !== ElementTypes.ARROW && type !== ElementTypes.DIMENSION)
|
|
110
111
|
return null;
|
|
111
112
|
if (!isStrokeSdfLineDecorationEnabled())
|
|
112
113
|
return null;
|
|
@@ -120,7 +121,7 @@ export const lineDecorationPieces = (raw, decl, matrix, zoom, dpr) => {
|
|
|
120
121
|
const strokeWidth = decl.width;
|
|
121
122
|
const cos = (p.x2 - p.x1) / Math.hypot(p.x2 - p.x1, p.y2 - p.y1);
|
|
122
123
|
const sin = (p.y2 - p.y1) / Math.hypot(p.x2 - p.x1, p.y2 - p.y1);
|
|
123
|
-
if (type ===
|
|
124
|
+
if (type === ElementTypes.ARROW) {
|
|
124
125
|
const arrowW = Number(raw.arrowWidth) || 15;
|
|
125
126
|
const arrowH = Number(raw.arrowHeight) || 22.5;
|
|
126
127
|
const arrowType = raw.arrowType === 'start' || raw.arrowType === 'both' ? raw.arrowType : 'end';
|
package/dist/render/multiPage.js
CHANGED
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
*/
|
|
28
28
|
import { EngineDocument } from '../model/document';
|
|
29
29
|
import { WORKSPACE_IDS, WORKSPACE_ID } from '../model/scene';
|
|
30
|
+
import { ElementTypes, typeKeyOf } from '../model/elementTypes';
|
|
30
31
|
import { invert, multiply, sceneToClipMatrix, transformPoint } from '../core/mat2d';
|
|
31
32
|
import { renderSceneNodes } from './framePipeline';
|
|
32
33
|
import { applyScissor, clearScissor, pageClipRect } from './screenClip';
|
|
@@ -291,7 +292,7 @@ function workspaceRectFromRaw(objects) {
|
|
|
291
292
|
const id = String(raw.id ?? '');
|
|
292
293
|
if (id !== WORKSPACE_ID && WORKSPACE_IDS.has(id))
|
|
293
294
|
continue;
|
|
294
|
-
if (
|
|
295
|
+
if (typeKeyOf(raw) === ElementTypes.REFERENCELINE)
|
|
295
296
|
continue;
|
|
296
297
|
const left = Number(raw.left ?? 0);
|
|
297
298
|
const top = Number(raw.top ?? 0);
|
|
@@ -28,6 +28,7 @@ import { parseStrokeDecl } from '../core/stroke';
|
|
|
28
28
|
import { getBoundsOfPath, parsePathData } from '../core/pathData';
|
|
29
29
|
import { multiply } from '../core/mat2d';
|
|
30
30
|
import { rectCornerRadii, traceRoundedRectPath } from '../core/roundedRect';
|
|
31
|
+
import { ElementTypes, typeKeyOf } from '../model/elementTypes';
|
|
31
32
|
/** 描边在对象线性变换下的包围盒半扩展(斜接尖峰可达 width×miterLimit/2) */
|
|
32
33
|
const strokeMargin = (decl, node) => {
|
|
33
34
|
const m = node.matrix;
|
|
@@ -75,9 +76,9 @@ export const strokeSnapOrigin = (m, zoom, dpr, vpt, sceneW, sceneH) => {
|
|
|
75
76
|
*/
|
|
76
77
|
export const traceShapeStrokePath = (ctx, node) => {
|
|
77
78
|
const raw = node.raw;
|
|
78
|
-
const type =
|
|
79
|
+
const type = typeKeyOf(raw);
|
|
79
80
|
ctx.beginPath();
|
|
80
|
-
if (type ===
|
|
81
|
+
if (type === ElementTypes.PATH) {
|
|
81
82
|
const commands = parsePathData(raw.path);
|
|
82
83
|
if (!commands)
|
|
83
84
|
return false;
|
|
@@ -107,7 +108,7 @@ export const traceShapeStrokePath = (ctx, node) => {
|
|
|
107
108
|
}
|
|
108
109
|
return true;
|
|
109
110
|
}
|
|
110
|
-
if (type ===
|
|
111
|
+
if (type === ElementTypes.POLYGON || type === ElementTypes.POLYLINE) {
|
|
111
112
|
const points = Array.isArray(raw.points) ? raw.points : [];
|
|
112
113
|
if (points.length < 2)
|
|
113
114
|
return false;
|
|
@@ -132,11 +133,11 @@ export const traceShapeStrokePath = (ctx, node) => {
|
|
|
132
133
|
ctx.moveTo(points[0].x - cx, points[0].y - cy);
|
|
133
134
|
for (let i = 0; i < points.length; i++)
|
|
134
135
|
ctx.lineTo(points[i].x - cx, points[i].y - cy);
|
|
135
|
-
if (
|
|
136
|
+
if (type === ElementTypes.POLYGON)
|
|
136
137
|
ctx.closePath();
|
|
137
138
|
return true;
|
|
138
139
|
}
|
|
139
|
-
if (type ===
|
|
140
|
+
if (type === ElementTypes.TRIANGLE) {
|
|
140
141
|
// fabric Triangle:points 不持久化,几何由 width/height 合成(本地系
|
|
141
142
|
// (w/2,0)→(w,h)→(0,h),scene.trianglePoints/svgExport 同源)——bbox 中心
|
|
142
143
|
// (w/2,h/2) 归一到中心原点(与填充网格 buildPolygonMesh 同口径)
|
|
@@ -150,15 +151,15 @@ export const traceShapeStrokePath = (ctx, node) => {
|
|
|
150
151
|
ctx.closePath();
|
|
151
152
|
return true;
|
|
152
153
|
}
|
|
153
|
-
if (type ===
|
|
154
|
-
const rx = (type ===
|
|
155
|
-
const ry = (type ===
|
|
154
|
+
if (type === ElementTypes.ELLIPSE || type === ElementTypes.CIRCLE) {
|
|
155
|
+
const rx = (type === ElementTypes.CIRCLE ? Number(raw.radius) : Number(raw.rx)) || 0;
|
|
156
|
+
const ry = (type === ElementTypes.CIRCLE ? Number(raw.radius) : Number(raw.ry)) || 0;
|
|
156
157
|
if (!(rx > 0) || !(ry > 0))
|
|
157
158
|
return false;
|
|
158
159
|
ctx.ellipse(0, 0, rx, ry, 0, 0, Math.PI * 2);
|
|
159
160
|
return true;
|
|
160
161
|
}
|
|
161
|
-
if (type ===
|
|
162
|
+
if (type === ElementTypes.LINE || type === ElementTypes.REFERENCELINE) {
|
|
162
163
|
// 线族:x1..y2 即中心相对坐标(calcLinePoints 恒等映射),开放路径
|
|
163
164
|
const x1 = Number(raw.x1);
|
|
164
165
|
const y1 = Number(raw.y1);
|
|
@@ -170,7 +171,7 @@ export const traceShapeStrokePath = (ctx, node) => {
|
|
|
170
171
|
ctx.lineTo(x2, y2);
|
|
171
172
|
return true;
|
|
172
173
|
}
|
|
173
|
-
if (type ===
|
|
174
|
+
if (type === ElementTypes.RECT || type === ElementTypes.FABRICRECT) {
|
|
174
175
|
const w = node.dims.x;
|
|
175
176
|
const h = node.dims.y;
|
|
176
177
|
if (!(w > 0) || !(h > 0))
|
|
@@ -197,8 +198,8 @@ export const bakeNodeStroke = (node, view) => {
|
|
|
197
198
|
const decl = parseStrokeDecl(node.raw);
|
|
198
199
|
if (!decl)
|
|
199
200
|
return null;
|
|
200
|
-
const type =
|
|
201
|
-
if (type ===
|
|
201
|
+
const type = typeKeyOf(node.raw);
|
|
202
|
+
if (type === ElementTypes.ARROW || type === ElementTypes.DIMENSION) {
|
|
202
203
|
// 线族装饰同主路径模型设备分辨率烘焙(zoom×dpr 光栅 + 窗口左上角设备像素
|
|
203
204
|
// 吸附)。首版维持 1× 的判据(2026-09-23「杆宽 ≥2px/文本不敏感」)失准:
|
|
204
205
|
// 箭头三角头两条斜边长,dpr 1.25~2 屏上 GL 双线性上采样把边缘抹成 3-4px
|
|
@@ -334,8 +335,8 @@ const bakeLineDecoration = (node, decl, view) => {
|
|
|
334
335
|
const raw = node.raw;
|
|
335
336
|
// 类型键小写归一(批次46 勘注:raw 两形态并存——store 装载小写 / fabric
|
|
336
337
|
// 构造器 toObject 大写,外层分支已归一,内层箭头/标注分派同口径)
|
|
337
|
-
const rawType =
|
|
338
|
-
const isArrow = rawType ===
|
|
338
|
+
const rawType = typeKeyOf(raw);
|
|
339
|
+
const isArrow = rawType === ElementTypes.ARROW;
|
|
339
340
|
const strokeWidth = Number(raw.strokeWidth) || 1;
|
|
340
341
|
const stroke = typeof raw.stroke === 'string' ? raw.stroke : isArrow ? '#000000' : '#000000';
|
|
341
342
|
const dash = Array.isArray(raw.strokeDashArray) ? raw.strokeDashArray : null;
|
package/dist/render/strokeSdf.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isStrokeSdfDashEnabled, isStrokeSdfPolygonEnabled } from '../engineFlag';
|
|
2
2
|
import { rectCornerRadii } from '../core/roundedRect';
|
|
3
|
+
import { ElementTypes, typeKeyOf } from '../model/elementTypes';
|
|
3
4
|
import { MAX_SEG_BATCH, segHash } from './segmentTable';
|
|
4
5
|
import { buildMiterOutline } from './strokeMiterOutline';
|
|
5
6
|
/** 描边码位段:kind(0-2) | cap(3-5) | penUniform(6)——与 strokeCoverage 解码一致 */
|
|
@@ -90,17 +91,17 @@ export const strokeSdfParams = (node, decl, zoom, dpr) => {
|
|
|
90
91
|
if (decl.alignment !== 'center')
|
|
91
92
|
return null;
|
|
92
93
|
const raw = node.raw;
|
|
93
|
-
const type =
|
|
94
|
+
const type = typeKeyOf(raw);
|
|
94
95
|
const dims = node.dims;
|
|
95
96
|
// rect/ellipse 须正尺寸;line 的 bbox 允许单轴为零(水平/垂直线最常见形态,
|
|
96
97
|
// margin 使 quad 两轴恒正)
|
|
97
|
-
if (type !==
|
|
98
|
+
if (type !== ElementTypes.LINE && (!(dims.x > 0) || !(dims.y > 0)))
|
|
98
99
|
return null;
|
|
99
|
-
const kindSel = type ===
|
|
100
|
+
const kindSel = type === ElementTypes.LINE
|
|
100
101
|
? STROKE_KIND_LINE
|
|
101
|
-
: type ===
|
|
102
|
+
: type === ElementTypes.ELLIPSE || type === ElementTypes.CIRCLE
|
|
102
103
|
? STROKE_KIND_ELLIPSE
|
|
103
|
-
: type ===
|
|
104
|
+
: type === ElementTypes.POLYGON || type === ElementTypes.POLYLINE || type === ElementTypes.TRIANGLE
|
|
104
105
|
? STROKE_KIND_SEGMENT
|
|
105
106
|
: STROKE_KIND_RECT;
|
|
106
107
|
const halfW = decl.width / 2;
|
|
@@ -112,7 +113,7 @@ export const strokeSdfParams = (node, decl, zoom, dpr) => {
|
|
|
112
113
|
let marginY = halfW;
|
|
113
114
|
/** kind=4 段表模式位(0=capsule/round、1=轮廓填充/miter);其余 kind 恒 0 */
|
|
114
115
|
let modeSlot = 0;
|
|
115
|
-
if (type ===
|
|
116
|
+
if (type === ElementTypes.RECT || type === ElementTypes.FABRICRECT) {
|
|
116
117
|
// 圆角与填充 quad 同源归一(rectCornerRadii:FabricRect 视觉 radius 反算/
|
|
117
118
|
// 单写 rx 提升 ry/钳半宽高)——角语义与批次 98 填充角天然同口径
|
|
118
119
|
const r = rectCornerRadii(raw, dims.x, dims.y);
|
|
@@ -129,7 +130,7 @@ export const strokeSdfParams = (node, decl, zoom, dpr) => {
|
|
|
129
130
|
return null;
|
|
130
131
|
shape = [rx, ry, dims.x / 2, dims.y / 2];
|
|
131
132
|
}
|
|
132
|
-
else if (type ===
|
|
133
|
+
else if (type === ElementTypes.LINE) {
|
|
133
134
|
const x1 = Number(raw.x1);
|
|
134
135
|
const y1 = Number(raw.y1);
|
|
135
136
|
const x2 = Number(raw.x2);
|
|
@@ -140,13 +141,13 @@ export const strokeSdfParams = (node, decl, zoom, dpr) => {
|
|
|
140
141
|
return null;
|
|
141
142
|
shape = [x1, y1, x2, y2];
|
|
142
143
|
}
|
|
143
|
-
else if (type ===
|
|
144
|
+
else if (type === ElementTypes.ELLIPSE || type === ElementTypes.CIRCLE) {
|
|
144
145
|
// 椭圆 dash:弧长无初等解析式(需椭圆积分近似)——回落(蓝图独立下刀)
|
|
145
146
|
if (dash)
|
|
146
147
|
return null;
|
|
147
148
|
shape = [0, 0, dims.x / 2, dims.y / 2];
|
|
148
149
|
}
|
|
149
|
-
else if (type ===
|
|
150
|
+
else if (type === ElementTypes.POLYGON || type === ElementTypes.POLYLINE || type === ElementTypes.TRIANGLE) {
|
|
150
151
|
// 方向三第二刀两放行面:round=capsule 并(批次 383)/ miter=双偏移轮廓
|
|
151
152
|
// winding 填充(批次 385);bevel 与超限顶点回落(枚举见文件头注)
|
|
152
153
|
if (!isStrokeSdfPolygonEnabled())
|
|
@@ -155,9 +156,9 @@ export const strokeSdfParams = (node, decl, zoom, dpr) => {
|
|
|
155
156
|
return null;
|
|
156
157
|
if (decl.uniform)
|
|
157
158
|
return null;
|
|
158
|
-
const closed = type !==
|
|
159
|
+
const closed = type !== ElementTypes.POLYLINE;
|
|
159
160
|
let src;
|
|
160
|
-
if (type ===
|
|
161
|
+
if (type === ElementTypes.TRIANGLE) {
|
|
161
162
|
// fabric Triangle:points 不持久化,几何由 w/h 合成(strokeBake/
|
|
162
163
|
// buildPolygonMesh(trianglePoints) 同源口径),直接给中心系三点
|
|
163
164
|
const w = dims.x;
|
package/dist/render/warpText.js
CHANGED
|
@@ -19,17 +19,19 @@
|
|
|
19
19
|
* 边界扫描 therefore 含特效墨(与 fabric 逐式一致——它也扫 super._render 产物)。
|
|
20
20
|
*/
|
|
21
21
|
import { drawParagraphPrefix, fontDeclaration, resolveStrokeDecl, charJitterY } from '../model/textLayout';
|
|
22
|
+
import { ElementTypes, typeKeyOf } from '../model/elementTypes';
|
|
22
23
|
import { bakePsdSolidFill, bakePsdStrokes, buildTextEffectSource } from './imageEffects';
|
|
23
24
|
import { drawVerticalGlyph, glyphStyleAt, verticalGlyphOps } from './verticalText';
|
|
24
25
|
export const warpTextKind = (raw) => {
|
|
25
26
|
const s = Number(raw.warpStrength) || 0;
|
|
26
27
|
if (!s)
|
|
27
28
|
return null;
|
|
28
|
-
|
|
29
|
+
const t = typeKeyOf(raw);
|
|
30
|
+
if (t === ElementTypes.ARCHTEXT)
|
|
29
31
|
return 'arch';
|
|
30
|
-
if (
|
|
32
|
+
if (t === ElementTypes.WAISTTEXT)
|
|
31
33
|
return 'waist';
|
|
32
|
-
if (
|
|
34
|
+
if (t === ElementTypes.FLAGTEXT)
|
|
33
35
|
return 'flag';
|
|
34
36
|
return null;
|
|
35
37
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yft-design/engine",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"description": "yft-design 的 WebGL2 画布引擎:接受 fabric toObject 格式 JSON,输出 GL 画布 / 位图(任意倍率 FBO 读回)/ SVG(纯数据序列化器)",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"warpvas": "^1.0.4"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
+
"@types/node": "^22.19.17",
|
|
36
37
|
"@types/rbush": "^4.0.0",
|
|
37
38
|
"jsdom": "^29.1.1",
|
|
38
39
|
"typescript": "^6.0.3",
|