@yft-design/engine 0.0.12 → 0.0.14
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 +87 -4
- package/dist/EngineCanvas.js +269 -15
- package/dist/core/events.d.ts +22 -0
- package/dist/core/events.js +28 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/interact/canvasInteractions.d.ts +18 -2
- package/dist/interact/canvasInteractions.js +52 -28
- package/dist/interact/dblClick.d.ts +18 -1
- package/dist/interact/dblClick.js +16 -2
- package/dist/interact/pageTransfer.d.ts +22 -0
- package/dist/interact/pageTransfer.js +56 -0
- package/dist/interact/pointer.d.ts +7 -1
- package/dist/interact/pointer.js +63 -7
- package/dist/interact/pointerTypes.d.ts +23 -0
- package/dist/interact/tableCellEditing.d.ts +4 -1
- package/dist/interact/tableCellEditing.js +17 -10
- package/dist/interact/tableInteraction.d.ts +4 -1
- package/dist/interact/tableInteraction.js +13 -6
- package/dist/interact/textEditing.d.ts +4 -1
- package/dist/interact/textEditing.js +19 -12
- package/dist/interact/wheelScroll.d.ts +21 -0
- package/dist/interact/wheelScroll.js +29 -1
- package/dist/render/SceneRenderer.js +2 -1
- package/dist/render/SourceManager.d.ts +7 -0
- package/dist/render/SourceManager.js +18 -0
- package/dist/render/clipMaskPainter.js +5 -3
- package/dist/render/fontInvalidationController.d.ts +4 -0
- package/dist/render/fontInvalidationController.js +6 -1
- package/dist/render/framePipeline.d.ts +3 -0
- package/dist/render/framePipeline.js +1 -1
- package/dist/render/multiPage.d.ts +190 -0
- package/dist/render/multiPage.js +403 -0
- package/dist/render/renderViewport.d.ts +7 -0
- package/dist/render/renderViewport.js +18 -0
- package/dist/render/strokePainter.js +3 -2
- package/dist/render/workspaceBackdrop.d.ts +25 -18
- package/dist/render/workspaceBackdrop.js +35 -46
- package/dist/render/workspaceGlow.d.ts +23 -12
- package/dist/render/workspaceGlow.js +42 -15
- package/package.json +2 -2
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 多页页注册表 + 分段帧组合(方案 D 批次 407 / P5-5 速排多页设计评审
|
|
3
|
+
* docs/2026-10-15_webgl2-p5-5-multidoc-design-review.md)。
|
|
4
|
+
*
|
|
5
|
+
* 形态:canvas 恒视口大小,N 页 = N 个 EngineDocument 按场景 Y 偏移竖排,
|
|
6
|
+
* 普通滚轮 = vpt 平移(与单页滚轮平移同一机制)。页坐标系采用 pageOrigin
|
|
7
|
+
* 装饰——每页保持模板原始页内坐标(各页 workSpace 在各自原点附近),
|
|
8
|
+
* 页偏移只存在于本注册表:渲染 = 逐页 vpt 换装(applyExportViewport 先例)、
|
|
9
|
+
* 命中/吸附 = 路由层减偏移、序列化 = doc.toObjects() 页内原坐标零换算
|
|
10
|
+
* (不写节点 raw,保存链零污染)。
|
|
11
|
+
*
|
|
12
|
+
* 单页等价门:页 0 即原单文档——count===1 时 EngineCanvas 走既有渲染路径
|
|
13
|
+
* 逐位不动(retainedFrame 保留式/渐进窗均不经本模块);多页态(count>1)
|
|
14
|
+
* 走 renderMultiPageFrame 分段帧:可见页预筛(页级 AABB——离屏页零遍历零
|
|
15
|
+
* draw call,滚动帧成本 = Σ可见页节点 ≈ 现状单页平移的 2-3 倍量级)+ 逐页
|
|
16
|
+
* begin(页间 flushAll——begin 会丢弃未出清挂起段,批次 221 延迟执行语义)
|
|
17
|
+
* + 多洞遮罩(workspaceBackdrop 多矩形)+ 活动页覆盖层。retainedFrame 在
|
|
18
|
+
* 多页态禁用(滚动即 vpt 变化本就全量帧,保留式收益面失效;页数增删经
|
|
19
|
+
* invalidate 防回退单页时重放陈旧快照)——分段快照是后续优化位(评审 §4.4)。
|
|
20
|
+
*
|
|
21
|
+
* D-1 范围边界(后续批次承接):懒解析 setPageRaw/ensurePageBuilt(D-2)、
|
|
22
|
+
* 指针路由接线与手势携 doc、setActivePage 会话收口(D-3)、事件总线聚合与
|
|
23
|
+
* TableNode.cellSelectionSink per-doc(D-4)、动画/源可见性门控(D-5)。
|
|
24
|
+
* 非活动页 loadPageObjects 不做该页旧动态源(视频/GIF sprite)的定向释放
|
|
25
|
+
* (SourceManager.releaseAnimatedSources 是整画布语义)——整景装载场景无
|
|
26
|
+
* 泄漏面,运行时换页图登记 D-5。
|
|
27
|
+
*/
|
|
28
|
+
import { EngineDocument } from '../model/document';
|
|
29
|
+
import { WORKSPACE_IDS, WORKSPACE_ID } from '../model/scene';
|
|
30
|
+
import { invert, multiply, sceneToClipMatrix, transformPoint } from '../core/mat2d';
|
|
31
|
+
import { renderSceneNodes } from './framePipeline';
|
|
32
|
+
import { buildHoverOverlay } from './selectionOverlay';
|
|
33
|
+
/**
|
|
34
|
+
* 页间视觉间隙(CSS 像素,屏幕恒定):2026-10-15 实测 canva.cn 桌面编辑器,
|
|
35
|
+
* 25% / 50% 的页面边缘间距均为 56px。布局用 gapScene = 间距 / viewportZoom,
|
|
36
|
+
* 页面缩放而间距不缩放;渲染与命中共用布局,页内序列化坐标保持原样。
|
|
37
|
+
*/
|
|
38
|
+
export const PAGE_GAP_CSS_PX = 56;
|
|
39
|
+
/** WorkSpaceDrawType 节点查找(workspaceBackdrop 批次 132 原位迁入——页矩形
|
|
40
|
+
* 与遮罩矩形共源;有效 = 存在 + visible + 宽高 > 0) */
|
|
41
|
+
export function findWorkspaceNode(doc) {
|
|
42
|
+
const workspace = doc.nodes.find((n) => String(n.raw.id ?? '') === WORKSPACE_ID);
|
|
43
|
+
if (!workspace || !workspace.visible)
|
|
44
|
+
return null;
|
|
45
|
+
if (!(workspace.bounds.width > 0) || !(workspace.bounds.height > 0))
|
|
46
|
+
return null;
|
|
47
|
+
return workspace;
|
|
48
|
+
}
|
|
49
|
+
export class MultiPageController {
|
|
50
|
+
entries = [{ doc: new EngineDocument(), origin: { x: 0, y: 0 }, workspaceNode: null, pendingRaw: null, placeholderRect: null }];
|
|
51
|
+
/** 视口 zoom(EC zoom 写点同步)——布局间隙屏恒折算基准(默认 1 = 单测/导出口径) */
|
|
52
|
+
viewportZoom = 1;
|
|
53
|
+
activeIndexValue = 0;
|
|
54
|
+
get pageCount() {
|
|
55
|
+
return this.entries.length;
|
|
56
|
+
}
|
|
57
|
+
get activeIndex() {
|
|
58
|
+
return this.activeIndexValue;
|
|
59
|
+
}
|
|
60
|
+
get activeDoc() {
|
|
61
|
+
return this.entries[this.activeIndexValue].doc;
|
|
62
|
+
}
|
|
63
|
+
pageAt(index) {
|
|
64
|
+
return this.entries[index] ?? null;
|
|
65
|
+
}
|
|
66
|
+
/** 激活页切换(D-1 仅索引——补帧/会话收口/滚动定位由宿主与 D-3/D-6 接线) */
|
|
67
|
+
setActiveIndex(index) {
|
|
68
|
+
if (index < 0 || index >= this.entries.length || index === this.activeIndexValue)
|
|
69
|
+
return false;
|
|
70
|
+
this.activeIndexValue = index;
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
/** 新建页(空文档)并重估布局;内容装载经宿主 loadPageObjects。返回实际落位索引 */
|
|
74
|
+
insert(index) {
|
|
75
|
+
const at = Math.max(0, Math.min(this.entries.length, index));
|
|
76
|
+
this.entries.splice(at, 0, { doc: new EngineDocument(), origin: { x: 0, y: 0 }, workspaceNode: null, pendingRaw: null, placeholderRect: null });
|
|
77
|
+
if (this.activeIndexValue >= at)
|
|
78
|
+
this.activeIndexValue++;
|
|
79
|
+
this.refreshAll();
|
|
80
|
+
return at;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 以活动 doc 为锚重建注册表(批次 412/413 主仓 syncEnginePages 的结构失配
|
|
84
|
+
* 修复面):首次启用/文档 Tab 换装时,引擎既有注册表(常为 [活动doc] 单页)
|
|
85
|
+
* 与 store 页集合的槽位错位——原「按索引逐页补差」会把非活动 store 页误判
|
|
86
|
+
* 到活动 doc 槽上(真机实证:setPageRaw 清空活动 doc + 新页从未插入)。
|
|
87
|
+
* 活动位置放活 doc,其余槽位全新空 doc(内容由调用方 setPageRaw 懒装载)。
|
|
88
|
+
*/
|
|
89
|
+
rebuildAroundActive(count, activeIndex) {
|
|
90
|
+
if (count < 1)
|
|
91
|
+
return;
|
|
92
|
+
const clamped = Math.max(0, Math.min(activeIndex, count - 1));
|
|
93
|
+
const entries = [];
|
|
94
|
+
for (let i = 0; i < count; i++) {
|
|
95
|
+
entries.push(i === clamped
|
|
96
|
+
? { doc: this.activeDoc, origin: { x: 0, y: 0 }, workspaceNode: null, pendingRaw: null, placeholderRect: null }
|
|
97
|
+
: { doc: new EngineDocument(), origin: { x: 0, y: 0 }, workspaceNode: null, pendingRaw: null, placeholderRect: null });
|
|
98
|
+
}
|
|
99
|
+
this.entries = entries;
|
|
100
|
+
this.activeIndexValue = clamped;
|
|
101
|
+
this.refreshAll();
|
|
102
|
+
}
|
|
103
|
+
/** 删除页(末页拒绝 false——页 0 是原单文档的等价面,不可删空) */
|
|
104
|
+
remove(index) {
|
|
105
|
+
if (this.entries.length <= 1 || index < 0 || index >= this.entries.length)
|
|
106
|
+
return false;
|
|
107
|
+
this.entries.splice(index, 1);
|
|
108
|
+
if (this.activeIndexValue >= this.entries.length)
|
|
109
|
+
this.activeIndexValue = this.entries.length - 1;
|
|
110
|
+
this.refreshAll();
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
/** 页内容重建后重捕获工作区引用(loadObjects/loadPageObjects 尾部调用) */
|
|
114
|
+
refresh(index) {
|
|
115
|
+
const entry = this.entries[index];
|
|
116
|
+
if (entry)
|
|
117
|
+
entry.workspaceNode = findWorkspaceNode(entry.doc);
|
|
118
|
+
}
|
|
119
|
+
/** 已建判定(懒解析面:pendingRaw 挂起即未建) */
|
|
120
|
+
isBuilt(index) {
|
|
121
|
+
return this.entries[index]?.pendingRaw == null;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* 懒解析挂起(D-2):存 raw 不建节点——布局用 raw 工作区直读的占位矩形。
|
|
125
|
+
* 对已建页调用 = 重新挂起(doc 清空回未建态)。
|
|
126
|
+
*/
|
|
127
|
+
setPageRaw(index, objects) {
|
|
128
|
+
const entry = this.entries[index];
|
|
129
|
+
if (!entry)
|
|
130
|
+
return false;
|
|
131
|
+
entry.pendingRaw = objects;
|
|
132
|
+
entry.placeholderRect = workspaceRectFromRaw(objects);
|
|
133
|
+
if (entry.doc.nodes.length > 0)
|
|
134
|
+
entry.doc.loadObjects([]);
|
|
135
|
+
entry.workspaceNode = null;
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
/** 建造完成记账(ensurePageBuilt 尾部调用——宿主已完成 doc.loadObjects + hydrate) */
|
|
139
|
+
markBuilt(index) {
|
|
140
|
+
const entry = this.entries[index];
|
|
141
|
+
if (!entry)
|
|
142
|
+
return;
|
|
143
|
+
entry.pendingRaw = null;
|
|
144
|
+
entry.placeholderRect = null;
|
|
145
|
+
this.refresh(index);
|
|
146
|
+
}
|
|
147
|
+
/** 全文档绝对包围盒(多页滚轮钳制域/宿主 fit 口径;空注册表 null) */
|
|
148
|
+
documentBounds() {
|
|
149
|
+
let l = Infinity;
|
|
150
|
+
let t = Infinity;
|
|
151
|
+
let r = -Infinity;
|
|
152
|
+
let b = -Infinity;
|
|
153
|
+
for (const row of this.layout()) {
|
|
154
|
+
const left = row.rect.left + row.entry.origin.x;
|
|
155
|
+
const top = row.rect.top + row.entry.origin.y;
|
|
156
|
+
l = Math.min(l, left);
|
|
157
|
+
t = Math.min(t, top);
|
|
158
|
+
r = Math.max(r, left + row.rect.width);
|
|
159
|
+
b = Math.max(b, top + row.rect.height);
|
|
160
|
+
}
|
|
161
|
+
if (l === Infinity)
|
|
162
|
+
return null;
|
|
163
|
+
return { left: l, top: t, width: r - l, height: b - t };
|
|
164
|
+
}
|
|
165
|
+
refreshAll() {
|
|
166
|
+
for (let i = 0; i < this.entries.length; i++)
|
|
167
|
+
this.refresh(i);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* 布局重算:每页矩形活读(已建 = workspaceNode.bounds 或节点包围盒退化;
|
|
171
|
+
* 未建 = pendingRaw 工作区占位直读)→ 竖排前缀和(页 i 工作区顶边落在
|
|
172
|
+
* Σ_{j<i}(h_j + gap)、水平中心对齐)。矩形无效(空页)不出行、贡献零
|
|
173
|
+
* 高度。逐帧调用(renderMultiPageFrame 头部/路由读位)——纯算术 O(页数),
|
|
174
|
+
* 节点扫描只在 refresh 期。
|
|
175
|
+
*/
|
|
176
|
+
layout() {
|
|
177
|
+
const out = [];
|
|
178
|
+
let maxWidth = 0;
|
|
179
|
+
for (let index = 0; index < this.entries.length; index++) {
|
|
180
|
+
const entry = this.entries[index];
|
|
181
|
+
const local = entry.workspaceNode ? { ...entry.workspaceNode.bounds } : entry.pendingRaw ? entry.placeholderRect : nodesBoundingBox(entry.doc);
|
|
182
|
+
if (!local)
|
|
183
|
+
continue;
|
|
184
|
+
maxWidth = Math.max(maxWidth, local.width);
|
|
185
|
+
out.push({ index, entry, rect: local });
|
|
186
|
+
}
|
|
187
|
+
let prefixY = 0;
|
|
188
|
+
for (const { entry, rect } of out) {
|
|
189
|
+
// -0 归一;各页围绕公共中轴伸缩,混合页宽也不会横向漂移。
|
|
190
|
+
entry.origin.x = (maxWidth - rect.width) / 2 - rect.left || 0;
|
|
191
|
+
entry.origin.y = prefixY - rect.top || 0;
|
|
192
|
+
prefixY += rect.height + PAGE_GAP_CSS_PX / (this.viewportZoom || 1);
|
|
193
|
+
}
|
|
194
|
+
return out;
|
|
195
|
+
}
|
|
196
|
+
/** 页绝对场景矩形(页内矩形 + 偏移;无效页 null)——debug/e2e/遮罩矩形共源 */
|
|
197
|
+
pageRectAt(index) {
|
|
198
|
+
const row = this.layout().find((r) => r.index === index);
|
|
199
|
+
if (!row)
|
|
200
|
+
return null;
|
|
201
|
+
return { left: row.rect.left + row.entry.origin.x, top: row.rect.top + row.entry.origin.y, width: row.rect.width, height: row.rect.height };
|
|
202
|
+
}
|
|
203
|
+
/** 指针路由(D-3 接线):画布场景点 → (页, 页内坐标);页间 gap 归属 null */
|
|
204
|
+
route(sceneX, sceneY) {
|
|
205
|
+
for (const row of this.layout()) {
|
|
206
|
+
const left = row.rect.left + row.entry.origin.x;
|
|
207
|
+
const top = row.rect.top + row.entry.origin.y;
|
|
208
|
+
if (sceneX >= left && sceneX <= left + row.rect.width && sceneY >= top && sceneY <= top + row.rect.height) {
|
|
209
|
+
return { index: row.index, doc: row.entry.doc, local: { x: sceneX - row.entry.origin.x, y: sceneY - row.entry.origin.y } };
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
/** 可见页(页 AABB 与视口场景矩形相交预筛;margin 外扩——遮罩发光带等
|
|
215
|
+
* 视口外沿视效的保留余量) */
|
|
216
|
+
visibleEntries(viewport, margin = 0) {
|
|
217
|
+
const out = [];
|
|
218
|
+
for (const row of this.layout()) {
|
|
219
|
+
const rect = { left: row.rect.left + row.entry.origin.x, top: row.rect.top + row.entry.origin.y, width: row.rect.width, height: row.rect.height };
|
|
220
|
+
if (rect.left - margin <= viewport.r && rect.left + rect.width + margin >= viewport.l && rect.top - margin <= viewport.b && rect.top + rect.height + margin >= viewport.t) {
|
|
221
|
+
out.push({ index: row.index, entry: row.entry, rect });
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return out;
|
|
225
|
+
}
|
|
226
|
+
/** 页偏移读取(布局新鲜度保证——内部先 layout;越界页回原点) */
|
|
227
|
+
originAt(index) {
|
|
228
|
+
this.layout();
|
|
229
|
+
const origin = this.entries[index]?.origin;
|
|
230
|
+
return origin ? { x: origin.x, y: origin.y } : { x: 0, y: 0 };
|
|
231
|
+
}
|
|
232
|
+
/** doc → 页索引(指针路由激活位;未命中 -1) */
|
|
233
|
+
indexOfDoc(doc) {
|
|
234
|
+
return this.entries.findIndex((e) => e.doc === doc);
|
|
235
|
+
}
|
|
236
|
+
/** 全部页 doc(字体迟到失效遍历面等) */
|
|
237
|
+
allDocs() {
|
|
238
|
+
return this.entries.map((e) => e.doc);
|
|
239
|
+
}
|
|
240
|
+
/** 页视口换装:vpt ∘ T(origin)——页内场景点经此矩阵即到屏幕(applyExportViewport 同机制) */
|
|
241
|
+
pageVpt(vpt, index) {
|
|
242
|
+
this.layout();
|
|
243
|
+
const entry = this.entries[index];
|
|
244
|
+
if (!entry)
|
|
245
|
+
return [...vpt];
|
|
246
|
+
return multiply(vpt, [1, 0, 0, 1, entry.origin.x, entry.origin.y]);
|
|
247
|
+
}
|
|
248
|
+
/** 画板中心缩放:指针所在页(空白处回退活动页)的中心屏幕位置保持不动,
|
|
249
|
+
* 其余页按固定屏幕间距重排;缩放本身不改变活动页,不写页内坐标。 */
|
|
250
|
+
zoomViewportAt(vpt, cssX, cssY, zoom) {
|
|
251
|
+
const sceneX = (cssX - vpt[4]) / vpt[0];
|
|
252
|
+
const sceneY = (cssY - vpt[5]) / vpt[3];
|
|
253
|
+
const index = this.route(sceneX, sceneY)?.index ?? this.activeIndex;
|
|
254
|
+
const before = this.pageRectAt(index);
|
|
255
|
+
const centerX = before ? before.left + before.width / 2 : sceneX;
|
|
256
|
+
const centerY = before ? before.top + before.height / 2 : sceneY;
|
|
257
|
+
const screen = transformPoint(vpt, centerX, centerY);
|
|
258
|
+
this.viewportZoom = zoom;
|
|
259
|
+
const after = this.pageRectAt(index);
|
|
260
|
+
return [zoom, 0, 0, zoom, screen.x - zoom * (after ? after.left + after.width / 2 : centerX), screen.y - zoom * (after ? after.top + after.height / 2 : centerY)];
|
|
261
|
+
}
|
|
262
|
+
/** 全页脏集出清(多页帧消费——不可见页脏集同样出清防累积) */
|
|
263
|
+
drainAll() {
|
|
264
|
+
for (const entry of this.entries)
|
|
265
|
+
entry.doc.drainRenderDirty();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/** 未建页占位矩形:raw 工作区直读(O(1) 不建节点);工作区缺席(自建空白页
|
|
269
|
+
* 等无 WorkSpaceDraw 数据)回退 raw 对象包围盒(批次 412 D-6 真机显影:无
|
|
270
|
+
* 工作区页占位 null → 多页流中不占位不可见,整流退化单页)。包围盒过滤
|
|
271
|
+
* 装饰族(WORKSPACE_IDS 非画板成员——参考线/裁切线 ±999999 会毁包围盒)
|
|
272
|
+
* 与参考线节点。全空页回退 750×500 缺省画板(占位可見,建造后按真内容排)。 */
|
|
273
|
+
function workspaceRectFromRaw(objects) {
|
|
274
|
+
for (const raw of objects) {
|
|
275
|
+
if (String(raw.id ?? '') !== WORKSPACE_ID)
|
|
276
|
+
continue;
|
|
277
|
+
const left = Number(raw.left ?? 0);
|
|
278
|
+
const top = Number(raw.top ?? 0);
|
|
279
|
+
const width = Number(raw.width ?? 0);
|
|
280
|
+
const height = Number(raw.height ?? 0);
|
|
281
|
+
if (Number.isFinite(left) && Number.isFinite(top) && width > 0 && height > 0)
|
|
282
|
+
return { left, top, width, height };
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
let l = Infinity;
|
|
286
|
+
let t = Infinity;
|
|
287
|
+
let r = -Infinity;
|
|
288
|
+
let b = -Infinity;
|
|
289
|
+
for (const raw of objects) {
|
|
290
|
+
const id = String(raw.id ?? '');
|
|
291
|
+
if (id !== WORKSPACE_ID && WORKSPACE_IDS.has(id))
|
|
292
|
+
continue;
|
|
293
|
+
if (String(raw.type ?? '').toLowerCase() === 'referenceline')
|
|
294
|
+
continue;
|
|
295
|
+
const left = Number(raw.left ?? 0);
|
|
296
|
+
const top = Number(raw.top ?? 0);
|
|
297
|
+
const width = Number(raw.width ?? 0);
|
|
298
|
+
const height = Number(raw.height ?? 0);
|
|
299
|
+
if (!Number.isFinite(left) || !Number.isFinite(top) || !(width > 0) || !(height > 0))
|
|
300
|
+
continue;
|
|
301
|
+
l = Math.min(l, left);
|
|
302
|
+
t = Math.min(t, top);
|
|
303
|
+
r = Math.max(r, left + width);
|
|
304
|
+
b = Math.max(b, top + height);
|
|
305
|
+
}
|
|
306
|
+
if (l === Infinity)
|
|
307
|
+
return { left: 0, top: 0, width: 750, height: 500 };
|
|
308
|
+
return { left: l, top: t, width: r - l, height: b - t };
|
|
309
|
+
}
|
|
310
|
+
/** 节点包围盒(工作区缺席的退化布局基准;空场景 null) */
|
|
311
|
+
function nodesBoundingBox(doc) {
|
|
312
|
+
let l = Infinity;
|
|
313
|
+
let t = Infinity;
|
|
314
|
+
let r = -Infinity;
|
|
315
|
+
let b = -Infinity;
|
|
316
|
+
for (const node of doc.nodes) {
|
|
317
|
+
const bb = node.bounds;
|
|
318
|
+
if (!Number.isFinite(bb.left) || !Number.isFinite(bb.top))
|
|
319
|
+
continue;
|
|
320
|
+
l = Math.min(l, bb.left);
|
|
321
|
+
t = Math.min(t, bb.top);
|
|
322
|
+
r = Math.max(r, bb.left + bb.width);
|
|
323
|
+
b = Math.max(b, bb.top + bb.height);
|
|
324
|
+
}
|
|
325
|
+
if (l === Infinity)
|
|
326
|
+
return null;
|
|
327
|
+
return { left: l, top: t, width: r - l, height: b - t };
|
|
328
|
+
}
|
|
329
|
+
/** 多页分段帧(EngineCanvas.render 的 count>1 分支体;单页路径不经此)。
|
|
330
|
+
* 相位序对齐单页帧:棋盘格(清屏后首笔,逐页)→ 逐页场景推入(页间
|
|
331
|
+
* flushAll + begin 换装)→ 全页脏集出清 → 多洞遮罩 → 活动页覆盖层
|
|
332
|
+
* (finishOverlay——OverlayTailHost 注入活动页 doc)。 */
|
|
333
|
+
export function renderMultiPageFrame(controller, host) {
|
|
334
|
+
controller.layout();
|
|
335
|
+
const inv = invert(host.vpt);
|
|
336
|
+
const tl = transformPoint(inv, 0, 0);
|
|
337
|
+
const br = transformPoint(inv, host.cssWidth, host.cssHeight);
|
|
338
|
+
const viewport = { l: Math.min(tl.x, br.x), t: Math.min(tl.y, br.y), r: Math.max(tl.x, br.x), b: Math.max(tl.y, br.y) };
|
|
339
|
+
// 发光带(8 CSS px)+ AA 余量;页间距已在布局层,无需再扩一整个间隙。
|
|
340
|
+
const margin = 16 / host.zoom;
|
|
341
|
+
const visible = controller.visibleEntries(viewport, margin);
|
|
342
|
+
// 懒解析触发(D-2):未建页进入可见窗口 → 宿主 kick ensurePageBuilt
|
|
343
|
+
// (宿主侧同步清 pendingRaw,后续帧不再重触发)
|
|
344
|
+
for (const page of visible) {
|
|
345
|
+
if (!controller.isBuilt(page.index))
|
|
346
|
+
host.onPageVisible(page.index);
|
|
347
|
+
}
|
|
348
|
+
// 布局间隙即屏恒灰隙(gapScene=PAGE_GAP_CSS_PX/zoom),遮罩用真页矩形
|
|
349
|
+
const rects = visible.map((p) => p.rect);
|
|
350
|
+
const canvasView = sceneToClipMatrix(host.vpt, host.cssWidth, host.cssHeight, host.dpr);
|
|
351
|
+
const viewportParams = { vpt: host.vpt, cssWidth: host.cssWidth, cssHeight: host.cssHeight, dpr: host.dpr };
|
|
352
|
+
host.workspaceBackdrop.drawChecker(host.gl, canvasView, viewportParams, rects);
|
|
353
|
+
const penScale = host.zoom * host.dpr;
|
|
354
|
+
const expand = host.expandUnderlay();
|
|
355
|
+
for (const page of visible) {
|
|
356
|
+
host.batchOrder.flushAll();
|
|
357
|
+
const pageViewport = controller.pageVpt(host.vpt, page.index);
|
|
358
|
+
const pageView = sceneToClipMatrix(pageViewport, host.cssWidth, host.cssHeight, host.dpr);
|
|
359
|
+
host.batch.begin(pageView, penScale);
|
|
360
|
+
host.meshBatch.begin(pageView);
|
|
361
|
+
host.batch.deferDraws = true;
|
|
362
|
+
host.meshBatch.deferDraws = true;
|
|
363
|
+
host.batchOrder.reset();
|
|
364
|
+
host.withPageViewport(pageViewport, () => renderSceneNodes(host.batch, host.renderer, page.entry.doc.nodes, expand, page.entry.doc.nodes.length));
|
|
365
|
+
}
|
|
366
|
+
host.batchOrder.flushAll();
|
|
367
|
+
controller.drainAll();
|
|
368
|
+
host.workspaceBackdrop.drawBackdrop(host.gl, canvasView, viewportParams, rects);
|
|
369
|
+
const activeView = sceneToClipMatrix(controller.pageVpt(host.vpt, controller.activeIndex), host.cssWidth, host.cssHeight, host.dpr);
|
|
370
|
+
host.batch.begin(activeView, penScale);
|
|
371
|
+
host.meshBatch.begin(activeView);
|
|
372
|
+
host.batch.deferDraws = true;
|
|
373
|
+
host.meshBatch.deferDraws = true;
|
|
374
|
+
host.batchOrder.reset();
|
|
375
|
+
host.finishOverlay();
|
|
376
|
+
// 非活动页 hover 边框(批次 409 D-3 补):hover 逐点路由把 hovered 状态落在
|
|
377
|
+
// 指针所在页 doc(不激活)——边框经该页视口补画(Canva 任意可见页 hover
|
|
378
|
+
// 可见语义);活动页 hover 已在 finishOverlay 的 buildFrameOverlay 内。收尾
|
|
379
|
+
// 出清序镜像 framePipeline pushOverlayAndContinue(flush 记录 → 统一执行)
|
|
380
|
+
for (const page of visible) {
|
|
381
|
+
if (page.index === controller.activeIndex)
|
|
382
|
+
continue;
|
|
383
|
+
const hovered = page.entry.doc.hovered;
|
|
384
|
+
if (!hovered)
|
|
385
|
+
continue;
|
|
386
|
+
const quads = buildHoverOverlay(hovered, host.zoom);
|
|
387
|
+
if (!quads.length)
|
|
388
|
+
continue;
|
|
389
|
+
const hoverView = sceneToClipMatrix(controller.pageVpt(host.vpt, page.index), host.cssWidth, host.cssHeight, host.dpr);
|
|
390
|
+
host.batch.begin(hoverView, penScale);
|
|
391
|
+
host.meshBatch.begin(hoverView);
|
|
392
|
+
host.batch.deferDraws = true;
|
|
393
|
+
host.meshBatch.deferDraws = true;
|
|
394
|
+
host.batchOrder.reset();
|
|
395
|
+
for (const q of quads) {
|
|
396
|
+
host.batch.pushQuad(q.matrix, q.dims.x, q.dims.y, q.color, q.texture ? host.textures.get(q.texture) : null);
|
|
397
|
+
}
|
|
398
|
+
host.batch.flush();
|
|
399
|
+
host.batch.deferDraws = false;
|
|
400
|
+
host.meshBatch.deferDraws = false;
|
|
401
|
+
host.batchOrder.executeDeferred();
|
|
402
|
+
}
|
|
403
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Mat } from '../core/mat2d';
|
|
2
|
+
interface ViewportHost {
|
|
3
|
+
readonly viewportTransform: Mat;
|
|
4
|
+
}
|
|
5
|
+
export declare function renderViewportOf(host: ViewportHost): Mat;
|
|
6
|
+
export declare function withRenderViewport(host: ViewportHost, viewport: Mat, render: () => void): void;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Drawing a visible page must not change the editor's active-page coordinate system. */
|
|
2
|
+
const renderingViewports = new WeakMap();
|
|
3
|
+
export function renderViewportOf(host) {
|
|
4
|
+
return renderingViewports.get(host) ?? host.viewportTransform;
|
|
5
|
+
}
|
|
6
|
+
export function withRenderViewport(host, viewport, render) {
|
|
7
|
+
const previous = renderingViewports.get(host);
|
|
8
|
+
renderingViewports.set(host, viewport);
|
|
9
|
+
try {
|
|
10
|
+
render();
|
|
11
|
+
}
|
|
12
|
+
finally {
|
|
13
|
+
if (previous)
|
|
14
|
+
renderingViewports.set(host, previous);
|
|
15
|
+
else
|
|
16
|
+
renderingViewports.delete(host);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -28,6 +28,7 @@ import { pickZoomBucket } from './GlyphAtlas';
|
|
|
28
28
|
import { SettleScheduler } from './settleScheduler';
|
|
29
29
|
import { bakeKMatches, bakeShouldHoldStale } from './bakeGate';
|
|
30
30
|
import { multiply } from '../core/mat2d';
|
|
31
|
+
import { renderViewportOf } from './renderViewport';
|
|
31
32
|
export class StrokePainter {
|
|
32
33
|
host;
|
|
33
34
|
frame;
|
|
@@ -111,7 +112,7 @@ export class StrokePainter {
|
|
|
111
112
|
// 允许复用更密/相近档缓存——跳过 snap 复核按缓存 lx/ly 原样铺放(场景
|
|
112
113
|
// 空间几何不变,仅栅格密度差);精确命中才做吸附翻转复核
|
|
113
114
|
const floor = this.host.bakeKReuseFloor ?? 0;
|
|
114
|
-
const snap = bake.k === k && bake.snapped ? strokeSnapOrigin(m, this.host.zoom, this.host.dpr, this.host
|
|
115
|
+
const snap = bake.k === k && bake.snapped ? strokeSnapOrigin(m, this.host.zoom, this.host.dpr, renderViewportOf(this.host), bake.sceneW, bake.sceneH) : null;
|
|
115
116
|
if (!bakeKMatches(bake.k, k, floor) || (snap && (snap.lx !== bake.lx || snap.ly !== bake.ly))) {
|
|
116
117
|
if (bakeShouldHoldStale(this.host, this.settle, this.frame, performance.now())) {
|
|
117
118
|
this.frame.bakeMore = true;
|
|
@@ -123,7 +124,7 @@ export class StrokePainter {
|
|
|
123
124
|
}
|
|
124
125
|
}
|
|
125
126
|
if (!bake) {
|
|
126
|
-
const result = bakeNodeStroke(node, { zoom: this.host.zoom, dpr: this.host.dpr, vpt: this.host
|
|
127
|
+
const result = bakeNodeStroke(node, { zoom: this.host.zoom, dpr: this.host.dpr, vpt: renderViewportOf(this.host) });
|
|
127
128
|
if (!result) {
|
|
128
129
|
this.strokeBakes.set(node, undefined);
|
|
129
130
|
return;
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 工作区画家接线(批次 132 自 EngineCanvas
|
|
2
|
+
* 工作区画家接线(批次 132 自 EngineCanvas 拆出——纯搬移;批次 407 方案 D
|
|
3
|
+
* 多页化:doc 构造期绑定改调用方传矩形数组,节点查找共源迁 render/multiPage
|
|
4
|
+
* 的 findWorkspaceNode)。
|
|
3
5
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* 两画家的装配:透明指示棋盘格(批次 89——清屏后首笔、全场景最底层,render
|
|
7
|
+
* 于 batch.begin 前调 drawChecker)与背景遮罩 + 外发光(批次 45——节点循环
|
|
8
|
+
* 后、选区/会话覆盖层前,fabric _renderAllWithWorkspaceOverlay 同相位,render
|
|
9
|
+
* 于 flush 后调 drawBackdrop)。多页:棋盘格逐页一画(页矩形互斥零 shader
|
|
10
|
+
* 改动);遮罩/发光一次多洞(矩形并集之外灰底——多页连画会互相盖掉对方页
|
|
11
|
+
* 内容,单洞 SDF 泛化见 workspaceGlow 头注)。矩形为绝对场景坐标(含页
|
|
12
|
+
* 偏移,MultiPageController 布局产物);单页态传 [唯一矩形] 与批次 132 行为
|
|
13
|
+
* 逐值一致。
|
|
14
|
+
* 仅交互渲染路径——SceneExporter 导出链不经此挂点,快照/缩略图/导出无遮罩
|
|
15
|
+
* 无发光;不写 raw 零序列化。
|
|
10
16
|
*/
|
|
11
|
-
import type { EngineDocument } from '../model/document';
|
|
12
17
|
import type { Mat } from '../core/mat2d';
|
|
13
18
|
/** 视口态快照(EngineCanvas.render 每帧组装传入) */
|
|
14
19
|
export interface WorkspaceViewportParams {
|
|
@@ -17,19 +22,21 @@ export interface WorkspaceViewportParams {
|
|
|
17
22
|
cssHeight: number;
|
|
18
23
|
dpr: number;
|
|
19
24
|
}
|
|
25
|
+
/** 工作区矩形(绝对场景坐标——多页态为各页矩形,单页态单元素) */
|
|
26
|
+
export interface WorkspaceRect {
|
|
27
|
+
left: number;
|
|
28
|
+
top: number;
|
|
29
|
+
width: number;
|
|
30
|
+
height: number;
|
|
31
|
+
}
|
|
20
32
|
export declare class WorkspaceBackdrop {
|
|
21
|
-
private readonly doc;
|
|
22
33
|
private readonly glow;
|
|
23
34
|
private readonly checker;
|
|
24
|
-
constructor(doc: EngineDocument);
|
|
25
35
|
/** P6-2 恢复链:program/VAO/缓冲随上下文销毁置空(两画家同批失效,重编译触发重绘) */
|
|
26
36
|
invalidate(): void;
|
|
27
|
-
/** 画板透明指示棋盘格(清屏后首笔;参数语义见 render/workspaceChecker.ts
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
* 线性扫,数千节点量级 µs 级,不值得缓存节点引用——loadObjects 重建节点
|
|
33
|
-
* 需失效跟踪,复杂度不成比例) */
|
|
34
|
-
private findWorkspaceNode;
|
|
37
|
+
/** 画板透明指示棋盘格(清屏后首笔;参数语义见 render/workspaceChecker.ts 头注)。
|
|
38
|
+
* 多页:逐页一画(棋盘格只画矩形内,页互斥零重叠) */
|
|
39
|
+
drawChecker(gl: WebGL2RenderingContext, view: Mat, viewport: WorkspaceViewportParams, rects: readonly WorkspaceRect[]): void;
|
|
40
|
+
/** 工作区背景遮罩 + 外发光(节点循环后;参数与多洞语义见 render/workspaceGlow.ts 头注) */
|
|
41
|
+
drawBackdrop(gl: WebGL2RenderingContext, view: Mat, viewport: WorkspaceViewportParams, rects: readonly WorkspaceRect[]): void;
|
|
35
42
|
}
|
|
@@ -1,71 +1,60 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 工作区画家接线(批次 132 自 EngineCanvas
|
|
2
|
+
* 工作区画家接线(批次 132 自 EngineCanvas 拆出——纯搬移;批次 407 方案 D
|
|
3
|
+
* 多页化:doc 构造期绑定改调用方传矩形数组,节点查找共源迁 render/multiPage
|
|
4
|
+
* 的 findWorkspaceNode)。
|
|
3
5
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* 两画家的装配:透明指示棋盘格(批次 89——清屏后首笔、全场景最底层,render
|
|
7
|
+
* 于 batch.begin 前调 drawChecker)与背景遮罩 + 外发光(批次 45——节点循环
|
|
8
|
+
* 后、选区/会话覆盖层前,fabric _renderAllWithWorkspaceOverlay 同相位,render
|
|
9
|
+
* 于 flush 后调 drawBackdrop)。多页:棋盘格逐页一画(页矩形互斥零 shader
|
|
10
|
+
* 改动);遮罩/发光一次多洞(矩形并集之外灰底——多页连画会互相盖掉对方页
|
|
11
|
+
* 内容,单洞 SDF 泛化见 workspaceGlow 头注)。矩形为绝对场景坐标(含页
|
|
12
|
+
* 偏移,MultiPageController 布局产物);单页态传 [唯一矩形] 与批次 132 行为
|
|
13
|
+
* 逐值一致。
|
|
14
|
+
* 仅交互渲染路径——SceneExporter 导出链不经此挂点,快照/缩略图/导出无遮罩
|
|
15
|
+
* 无发光;不写 raw 零序列化。
|
|
10
16
|
*/
|
|
11
|
-
import { WORKSPACE_ID } from '../model/scene';
|
|
12
17
|
import { WorkspaceCheckerPainter } from './workspaceChecker';
|
|
13
18
|
import { WorkspaceGlowPainter } from './workspaceGlow';
|
|
14
19
|
export class WorkspaceBackdrop {
|
|
15
|
-
doc;
|
|
16
20
|
glow = new WorkspaceGlowPainter();
|
|
17
21
|
checker = new WorkspaceCheckerPainter();
|
|
18
|
-
constructor(doc) {
|
|
19
|
-
this.doc = doc;
|
|
20
|
-
}
|
|
21
22
|
/** P6-2 恢复链:program/VAO/缓冲随上下文销毁置空(两画家同批失效,重编译触发重绘) */
|
|
22
23
|
invalidate() {
|
|
23
24
|
this.glow.invalidate();
|
|
24
25
|
this.checker.invalidate();
|
|
25
26
|
}
|
|
26
|
-
/** 画板透明指示棋盘格(清屏后首笔;参数语义见 render/workspaceChecker.ts
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
27
|
+
/** 画板透明指示棋盘格(清屏后首笔;参数语义见 render/workspaceChecker.ts 头注)。
|
|
28
|
+
* 多页:逐页一画(棋盘格只画矩形内,页互斥零重叠) */
|
|
29
|
+
drawChecker(gl, view, viewport, rects) {
|
|
30
|
+
const zoom = Math.hypot(viewport.vpt[0], viewport.vpt[1]);
|
|
31
|
+
for (const b of rects) {
|
|
32
|
+
if (!(b.width > 0) || !(b.height > 0))
|
|
33
|
+
continue;
|
|
34
|
+
this.checker.draw(gl, {
|
|
35
|
+
view,
|
|
36
|
+
vpt: viewport.vpt,
|
|
37
|
+
left: b.left,
|
|
38
|
+
top: b.top,
|
|
39
|
+
width: b.width,
|
|
40
|
+
height: b.height,
|
|
41
|
+
zoom,
|
|
42
|
+
dpr: viewport.dpr
|
|
43
|
+
});
|
|
44
|
+
}
|
|
41
45
|
}
|
|
42
|
-
/** 工作区背景遮罩 +
|
|
43
|
-
drawBackdrop(gl, view, viewport) {
|
|
44
|
-
|
|
45
|
-
if (!b)
|
|
46
|
+
/** 工作区背景遮罩 + 外发光(节点循环后;参数与多洞语义见 render/workspaceGlow.ts 头注) */
|
|
47
|
+
drawBackdrop(gl, view, viewport, rects) {
|
|
48
|
+
if (rects.length === 0)
|
|
46
49
|
return;
|
|
47
50
|
this.glow.draw(gl, {
|
|
48
51
|
view,
|
|
49
52
|
vpt: viewport.vpt,
|
|
50
53
|
cssWidth: viewport.cssWidth,
|
|
51
54
|
cssHeight: viewport.cssHeight,
|
|
52
|
-
|
|
53
|
-
top: b.top,
|
|
54
|
-
width: b.width,
|
|
55
|
-
height: b.height,
|
|
55
|
+
rects,
|
|
56
56
|
zoom: Math.hypot(viewport.vpt[0], viewport.vpt[1]),
|
|
57
57
|
dpr: viewport.dpr
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
|
-
/** WorkSpaceDrawType 节点查找(棋盘格/遮罩共用;per-frame find:字符串比对
|
|
61
|
-
* 线性扫,数千节点量级 µs 级,不值得缓存节点引用——loadObjects 重建节点
|
|
62
|
-
* 需失效跟踪,复杂度不成比例) */
|
|
63
|
-
findWorkspaceNode() {
|
|
64
|
-
const workspace = this.doc.nodes.find((n) => String(n.raw.id ?? '') === WORKSPACE_ID);
|
|
65
|
-
if (!workspace || !workspace.visible)
|
|
66
|
-
return null;
|
|
67
|
-
if (!(workspace.bounds.width > 0) || !(workspace.bounds.height > 0))
|
|
68
|
-
return null;
|
|
69
|
-
return workspace;
|
|
70
|
-
}
|
|
71
60
|
}
|