@yft-design/engine 0.0.13 → 0.0.15

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.
@@ -26,12 +26,17 @@
26
26
  * 泄漏面,运行时换页图登记 D-5。
27
27
  */
28
28
  import { EngineDocument } from '../model/document';
29
- import { WORKSPACE_ID } from '../model/scene';
29
+ import { WORKSPACE_IDS, WORKSPACE_ID } from '../model/scene';
30
30
  import { invert, multiply, sceneToClipMatrix, transformPoint } from '../core/mat2d';
31
31
  import { renderSceneNodes } from './framePipeline';
32
+ import { applyScissor, clearScissor, pageClipRect } from './screenClip';
32
33
  import { buildHoverOverlay } from './selectionOverlay';
33
- /** 页间距(场景单位——布局常量,产品口径调整随 D-6 裁量) */
34
- export const PAGE_GAP_SCENE = 60;
34
+ /**
35
+ * 页间视觉间隙(CSS 像素,屏幕恒定):2026-10-15 实测 canva.cn 桌面编辑器,
36
+ * 25% / 50% 的页面边缘间距均为 56px。布局用 gapScene = 间距 / viewportZoom,
37
+ * 页面缩放而间距不缩放;渲染与命中共用布局,页内序列化坐标保持原样。
38
+ */
39
+ export const PAGE_GAP_CSS_PX = 56;
35
40
  /** WorkSpaceDrawType 节点查找(workspaceBackdrop 批次 132 原位迁入——页矩形
36
41
  * 与遮罩矩形共源;有效 = 存在 + visible + 宽高 > 0) */
37
42
  export function findWorkspaceNode(doc) {
@@ -44,6 +49,8 @@ export function findWorkspaceNode(doc) {
44
49
  }
45
50
  export class MultiPageController {
46
51
  entries = [{ doc: new EngineDocument(), origin: { x: 0, y: 0 }, workspaceNode: null, pendingRaw: null, placeholderRect: null }];
52
+ /** 视口 zoom(EC zoom 写点同步)——布局间隙屏恒折算基准(默认 1 = 单测/导出口径) */
53
+ viewportZoom = 1;
47
54
  activeIndexValue = 0;
48
55
  get pageCount() {
49
56
  return this.entries.length;
@@ -73,6 +80,27 @@ export class MultiPageController {
73
80
  this.refreshAll();
74
81
  return at;
75
82
  }
83
+ /**
84
+ * 以活动 doc 为锚重建注册表(批次 412/413 主仓 syncEnginePages 的结构失配
85
+ * 修复面):首次启用/文档 Tab 换装时,引擎既有注册表(常为 [活动doc] 单页)
86
+ * 与 store 页集合的槽位错位——原「按索引逐页补差」会把非活动 store 页误判
87
+ * 到活动 doc 槽上(真机实证:setPageRaw 清空活动 doc + 新页从未插入)。
88
+ * 活动位置放活 doc,其余槽位全新空 doc(内容由调用方 setPageRaw 懒装载)。
89
+ */
90
+ rebuildAroundActive(count, activeIndex) {
91
+ if (count < 1)
92
+ return;
93
+ const clamped = Math.max(0, Math.min(activeIndex, count - 1));
94
+ const entries = [];
95
+ for (let i = 0; i < count; i++) {
96
+ entries.push(i === clamped
97
+ ? { doc: this.activeDoc, origin: { x: 0, y: 0 }, workspaceNode: null, pendingRaw: null, placeholderRect: null }
98
+ : { doc: new EngineDocument(), origin: { x: 0, y: 0 }, workspaceNode: null, pendingRaw: null, placeholderRect: null });
99
+ }
100
+ this.entries = entries;
101
+ this.activeIndexValue = clamped;
102
+ this.refreshAll();
103
+ }
76
104
  /** 删除页(末页拒绝 false——页 0 是原单文档的等价面,不可删空) */
77
105
  remove(index) {
78
106
  if (this.entries.length <= 1 || index < 0 || index >= this.entries.length)
@@ -142,24 +170,28 @@ export class MultiPageController {
142
170
  /**
143
171
  * 布局重算:每页矩形活读(已建 = workspaceNode.bounds 或节点包围盒退化;
144
172
  * 未建 = pendingRaw 工作区占位直读)→ 竖排前缀和(页 i 工作区顶边落在
145
- * Σ_{j<i}(h_j + gap)、左缘归零对齐)。矩形无效(空页)不出行、贡献零
173
+ * Σ_{j<i}(h_j + gap)、水平中心对齐)。矩形无效(空页)不出行、贡献零
146
174
  * 高度。逐帧调用(renderMultiPageFrame 头部/路由读位)——纯算术 O(页数),
147
175
  * 节点扫描只在 refresh 期。
148
176
  */
149
177
  layout() {
150
178
  const out = [];
151
- let prefixY = 0;
179
+ let maxWidth = 0;
152
180
  for (let index = 0; index < this.entries.length; index++) {
153
181
  const entry = this.entries[index];
154
182
  const local = entry.workspaceNode ? { ...entry.workspaceNode.bounds } : entry.pendingRaw ? entry.placeholderRect : nodesBoundingBox(entry.doc);
155
183
  if (!local)
156
184
  continue;
157
- // -0 归一(workspace left/top 为 0 时取负产生 -0,深比较/序列化口径脏值)
158
- entry.origin.x = -local.left || 0;
159
- entry.origin.y = prefixY - local.top || 0;
160
- prefixY += local.height + PAGE_GAP_SCENE;
185
+ maxWidth = Math.max(maxWidth, local.width);
161
186
  out.push({ index, entry, rect: local });
162
187
  }
188
+ let prefixY = 0;
189
+ for (const { entry, rect } of out) {
190
+ // -0 归一;各页围绕公共中轴伸缩,混合页宽也不会横向漂移。
191
+ entry.origin.x = (maxWidth - rect.width) / 2 - rect.left || 0;
192
+ entry.origin.y = prefixY - rect.top || 0;
193
+ prefixY += rect.height + PAGE_GAP_CSS_PX / (this.viewportZoom || 1);
194
+ }
163
195
  return out;
164
196
  }
165
197
  /** 页绝对场景矩形(页内矩形 + 偏移;无效页 null)——debug/e2e/遮罩矩形共源 */
@@ -208,18 +240,37 @@ export class MultiPageController {
208
240
  }
209
241
  /** 页视口换装:vpt ∘ T(origin)——页内场景点经此矩阵即到屏幕(applyExportViewport 同机制) */
210
242
  pageVpt(vpt, index) {
243
+ this.layout();
211
244
  const entry = this.entries[index];
212
245
  if (!entry)
213
246
  return [...vpt];
214
247
  return multiply(vpt, [1, 0, 0, 1, entry.origin.x, entry.origin.y]);
215
248
  }
249
+ /** 画板中心缩放:指针所在页(空白处回退活动页)的中心屏幕位置保持不动,
250
+ * 其余页按固定屏幕间距重排;缩放本身不改变活动页,不写页内坐标。 */
251
+ zoomViewportAt(vpt, cssX, cssY, zoom) {
252
+ const sceneX = (cssX - vpt[4]) / vpt[0];
253
+ const sceneY = (cssY - vpt[5]) / vpt[3];
254
+ const index = this.route(sceneX, sceneY)?.index ?? this.activeIndex;
255
+ const before = this.pageRectAt(index);
256
+ const centerX = before ? before.left + before.width / 2 : sceneX;
257
+ const centerY = before ? before.top + before.height / 2 : sceneY;
258
+ const screen = transformPoint(vpt, centerX, centerY);
259
+ this.viewportZoom = zoom;
260
+ const after = this.pageRectAt(index);
261
+ 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)];
262
+ }
216
263
  /** 全页脏集出清(多页帧消费——不可见页脏集同样出清防累积) */
217
264
  drainAll() {
218
265
  for (const entry of this.entries)
219
266
  entry.doc.drainRenderDirty();
220
267
  }
221
268
  }
222
- /** 未建页占位矩形:raw 工作区直读(O(1) 不建节点;缺席/无效 null) */
269
+ /** 未建页占位矩形:raw 工作区直读(O(1) 不建节点);工作区缺席(自建空白页
270
+ * 等无 WorkSpaceDraw 数据)回退 raw 对象包围盒(批次 412 D-6 真机显影:无
271
+ * 工作区页占位 null → 多页流中不占位不可见,整流退化单页)。包围盒过滤
272
+ * 装饰族(WORKSPACE_IDS 非画板成员——参考线/裁切线 ±999999 会毁包围盒)
273
+ * 与参考线节点。全空页回退 750×500 缺省画板(占位可見,建造后按真内容排)。 */
223
274
  function workspaceRectFromRaw(objects) {
224
275
  for (const raw of objects) {
225
276
  if (String(raw.id ?? '') !== WORKSPACE_ID)
@@ -232,7 +283,30 @@ function workspaceRectFromRaw(objects) {
232
283
  return { left, top, width, height };
233
284
  return null;
234
285
  }
235
- return null;
286
+ let l = Infinity;
287
+ let t = Infinity;
288
+ let r = -Infinity;
289
+ let b = -Infinity;
290
+ for (const raw of objects) {
291
+ const id = String(raw.id ?? '');
292
+ if (id !== WORKSPACE_ID && WORKSPACE_IDS.has(id))
293
+ continue;
294
+ if (String(raw.type ?? '').toLowerCase() === 'referenceline')
295
+ continue;
296
+ const left = Number(raw.left ?? 0);
297
+ const top = Number(raw.top ?? 0);
298
+ const width = Number(raw.width ?? 0);
299
+ const height = Number(raw.height ?? 0);
300
+ if (!Number.isFinite(left) || !Number.isFinite(top) || !(width > 0) || !(height > 0))
301
+ continue;
302
+ l = Math.min(l, left);
303
+ t = Math.min(t, top);
304
+ r = Math.max(r, left + width);
305
+ b = Math.max(b, top + height);
306
+ }
307
+ if (l === Infinity)
308
+ return { left: 0, top: 0, width: 750, height: 500 };
309
+ return { left: l, top: t, width: r - l, height: b - t };
236
310
  }
237
311
  /** 节点包围盒(工作区缺席的退化布局基准;空场景 null) */
238
312
  function nodesBoundingBox(doc) {
@@ -255,15 +329,16 @@ function nodesBoundingBox(doc) {
255
329
  }
256
330
  /** 多页分段帧(EngineCanvas.render 的 count>1 分支体;单页路径不经此)。
257
331
  * 相位序对齐单页帧:棋盘格(清屏后首笔,逐页)→ 逐页场景推入(页间
258
- * flushAll + begin 换装)→ 全页脏集出清 → 多洞遮罩 → 活动页覆盖层
259
- * (finishOverlay——OverlayTailHost 注入活动页 doc)。 */
332
+ * flushAll + begin 换装 + 页剪裁 scissor——内容不出页,批次 414)→ 全页
333
+ * 脏集出清 → 多洞遮罩 → 活动页覆盖层(finishOverlay——OverlayTailHost
334
+ * 注入活动页 doc)。 */
260
335
  export function renderMultiPageFrame(controller, host) {
261
336
  controller.layout();
262
337
  const inv = invert(host.vpt);
263
338
  const tl = transformPoint(inv, 0, 0);
264
339
  const br = transformPoint(inv, host.cssWidth, host.cssHeight);
265
340
  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) };
266
- // 遮罩发光带(8 CSS px)+ AA 余量:视口缘的近邻页仍需遮罩/发光矩形
341
+ // 发光带(8 CSS px)+ AA 余量;页间距已在布局层,无需再扩一整个间隙。
267
342
  const margin = 16 / host.zoom;
268
343
  const visible = controller.visibleEntries(viewport, margin);
269
344
  // 懒解析触发(D-2):未建页进入可见窗口 → 宿主 kick ensurePageBuilt
@@ -272,23 +347,39 @@ export function renderMultiPageFrame(controller, host) {
272
347
  if (!controller.isBuilt(page.index))
273
348
  host.onPageVisible(page.index);
274
349
  }
350
+ // 布局间隙即屏恒灰隙(gapScene=PAGE_GAP_CSS_PX/zoom),遮罩用真页矩形
275
351
  const rects = visible.map((p) => p.rect);
276
352
  const canvasView = sceneToClipMatrix(host.vpt, host.cssWidth, host.cssHeight, host.dpr);
277
353
  const viewportParams = { vpt: host.vpt, cssWidth: host.cssWidth, cssHeight: host.cssHeight, dpr: host.dpr };
278
354
  host.workspaceBackdrop.drawChecker(host.gl, canvasView, viewportParams, rects);
279
355
  const penScale = host.zoom * host.dpr;
280
356
  const expand = host.expandUnderlay();
281
- for (const page of visible) {
357
+ try {
358
+ for (const page of visible) {
359
+ // 前页延迟命令先出清——彼时 scissor 仍是前页盒(本页盒换装前把前页
360
+ // 命令画完,内容不出页的时序关键:push 期烘焙豁免与隔离边界 flush
361
+ // 也都发生在当前页盒之下)
362
+ host.batchOrder.flushAll();
363
+ // 页剪裁:本页全部绘制(含越界几何/屏幕尺寸隔离混合合成)钳在本页
364
+ // 矩形内——邻页矩形是多洞遮罩的洞,遮罩救不了越界内容(screenClip
365
+ // 头注);零尺寸盒 = 预筛 margin 余量下的视口外沿页,合法全弃置
366
+ applyScissor(host.gl, pageClipRect(page.rect, host.vpt, host.cssWidth, host.cssHeight, host.dpr));
367
+ const pageViewport = controller.pageVpt(host.vpt, page.index);
368
+ const pageView = sceneToClipMatrix(pageViewport, host.cssWidth, host.cssHeight, host.dpr);
369
+ host.batch.begin(pageView, penScale);
370
+ host.meshBatch.begin(pageView);
371
+ host.batch.deferDraws = true;
372
+ host.meshBatch.deferDraws = true;
373
+ host.batchOrder.reset();
374
+ host.withPageViewport(pageViewport, () => renderSceneNodes(host.batch, host.renderer, page.entry.doc.nodes, expand, page.entry.doc.nodes.length));
375
+ }
282
376
  host.batchOrder.flushAll();
283
- const pageView = sceneToClipMatrix(controller.pageVpt(host.vpt, page.index), host.cssWidth, host.cssHeight, host.dpr);
284
- host.batch.begin(pageView, penScale);
285
- host.meshBatch.begin(pageView);
286
- host.batch.deferDraws = true;
287
- host.meshBatch.deferDraws = true;
288
- host.batchOrder.reset();
289
- renderSceneNodes(host.batch, host.renderer, page.entry.doc.nodes, expand, page.entry.doc.nodes.length);
290
377
  }
291
- host.batchOrder.flushAll();
378
+ finally {
379
+ // 遮罩(全视口灰底+发光)/覆盖层(选框/hover/编辑光标)不裁——单页态
380
+ // 「内容被盖、选框可见」语义的多页推广;finally 保证中途异常不泄全局态
381
+ clearScissor(host.gl);
382
+ }
292
383
  controller.drainAll();
293
384
  host.workspaceBackdrop.drawBackdrop(host.gl, canvasView, viewportParams, rects);
294
385
  const activeView = sceneToClipMatrix(controller.pageVpt(host.vpt, controller.activeIndex), host.cssWidth, host.cssHeight, host.dpr);
@@ -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
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * 屏幕域页剪裁(方案 D 多页「内容不出页」,批次 414)。
3
+ *
4
+ * 多页分段帧逐页换装视口但不裁几何——节点越出本页工作区矩形的部分会画进
5
+ * 页间 gap 与邻页矩形;gap 段随后被不透明多洞灰遮罩盖住(不可见),而邻页
6
+ * 矩形是遮罩的洞,越界内容就此漏显在他人画板里(「元素跨两页显示」病灶——
7
+ * 跨页拖入置顶已定归属语义,渲染面须执行同一语义:元素只在归属页可见)。
8
+ * 单页态既有语义本就是「工作区外内容被遮罩盖住、只留覆盖层选框」——本模块
9
+ * 把它推广到多页:页段渲染期开 GL scissor,把本页全部绘制(含越界几何与
10
+ * 隔离/混合全屏合成)钳在本页矩形的帧缓冲像素内;遮罩/覆盖层相位关回。
11
+ *
12
+ * 坐标口径:编辑器 vpt 无旋转,页矩形(绝对场景系)经 vpt 映射为轴对齐
13
+ * CSS 矩形,再 ×dpr、y 翻转(GL 原点左下)得帧缓冲 scissor 盒;外向取整
14
+ * (floor/ceil)保边沿内容像素,与视口求交,空交集 = 零尺寸盒(全弃置,
15
+ * 预筛 margin 余量下的视口外沿页)。
16
+ *
17
+ * 烘焙豁免(suspendScissor):scissor 是上下文级状态,作用于一切帧缓冲的
18
+ * draw/clear/blit/像素拷贝。GPU 烘焙族(GpuShadowBaker/GpuFxPainter 三入口/
19
+ * GpuImageFilterChain)在自身内容坐标系的内容尺寸 FBO 里跑 pass——页矩形投
20
+ * 到那边是随机区域,不豁免即剪坏烘焙纹理。屏幕尺寸 FBO(GLIsolate 组隔离/
21
+ * GLBlend 混合)与页同屏同系:不豁免恰是把组内容一并钳在页内(组越页同裁)
22
+ * ——故不在豁免之列。CPU 烘焙(2D canvas → texImage 上传)不受 scissor 影响
23
+ * 天然豁免(maskRender/strokePainter/shadowPainter CPU 支/psdEffectPainter/
24
+ * GlyphAtlas 全族)。
25
+ */
26
+ import { type Mat } from '../core/mat2d';
27
+ /** 帧缓冲像素矩形(GL scissor 盒;w/h=0 = 空交集全弃置) */
28
+ export interface FbClipRect {
29
+ x: number;
30
+ y: number;
31
+ w: number;
32
+ h: number;
33
+ }
34
+ /** 场景矩形 → 帧缓冲 scissor 盒(vpt 无旋转假设下两角即轴对齐;空交集零尺寸) */
35
+ export declare function pageClipRect(sceneRect: {
36
+ left: number;
37
+ top: number;
38
+ width: number;
39
+ height: number;
40
+ }, vpt: Mat, cssWidth: number, cssHeight: number, dpr: number): FbClipRect;
41
+ /** 开启并设置页剪裁(零尺寸盒合法——本页绘制全弃置) */
42
+ export declare function applyScissor(gl: WebGL2RenderingContext, rect: FbClipRect): void;
43
+ /** 关闭页剪裁(帧尾 finally/遮罩与覆盖层相位前) */
44
+ export declare function clearScissor(gl: WebGL2RenderingContext): void;
45
+ /** 烘焙豁免:记录并关闭 scissor,返回恢复函数(幂等;出口/finally 调用)。
46
+ * 未开启时零成本直通(单页态/导出链恒不开启)。 */
47
+ export declare function suspendScissor(gl: WebGL2RenderingContext): () => void;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * 屏幕域页剪裁(方案 D 多页「内容不出页」,批次 414)。
3
+ *
4
+ * 多页分段帧逐页换装视口但不裁几何——节点越出本页工作区矩形的部分会画进
5
+ * 页间 gap 与邻页矩形;gap 段随后被不透明多洞灰遮罩盖住(不可见),而邻页
6
+ * 矩形是遮罩的洞,越界内容就此漏显在他人画板里(「元素跨两页显示」病灶——
7
+ * 跨页拖入置顶已定归属语义,渲染面须执行同一语义:元素只在归属页可见)。
8
+ * 单页态既有语义本就是「工作区外内容被遮罩盖住、只留覆盖层选框」——本模块
9
+ * 把它推广到多页:页段渲染期开 GL scissor,把本页全部绘制(含越界几何与
10
+ * 隔离/混合全屏合成)钳在本页矩形的帧缓冲像素内;遮罩/覆盖层相位关回。
11
+ *
12
+ * 坐标口径:编辑器 vpt 无旋转,页矩形(绝对场景系)经 vpt 映射为轴对齐
13
+ * CSS 矩形,再 ×dpr、y 翻转(GL 原点左下)得帧缓冲 scissor 盒;外向取整
14
+ * (floor/ceil)保边沿内容像素,与视口求交,空交集 = 零尺寸盒(全弃置,
15
+ * 预筛 margin 余量下的视口外沿页)。
16
+ *
17
+ * 烘焙豁免(suspendScissor):scissor 是上下文级状态,作用于一切帧缓冲的
18
+ * draw/clear/blit/像素拷贝。GPU 烘焙族(GpuShadowBaker/GpuFxPainter 三入口/
19
+ * GpuImageFilterChain)在自身内容坐标系的内容尺寸 FBO 里跑 pass——页矩形投
20
+ * 到那边是随机区域,不豁免即剪坏烘焙纹理。屏幕尺寸 FBO(GLIsolate 组隔离/
21
+ * GLBlend 混合)与页同屏同系:不豁免恰是把组内容一并钳在页内(组越页同裁)
22
+ * ——故不在豁免之列。CPU 烘焙(2D canvas → texImage 上传)不受 scissor 影响
23
+ * 天然豁免(maskRender/strokePainter/shadowPainter CPU 支/psdEffectPainter/
24
+ * GlyphAtlas 全族)。
25
+ */
26
+ import { transformPoint } from '../core/mat2d';
27
+ /** 场景矩形 → 帧缓冲 scissor 盒(vpt 无旋转假设下两角即轴对齐;空交集零尺寸) */
28
+ export function pageClipRect(sceneRect, vpt, cssWidth, cssHeight, dpr) {
29
+ const p1 = transformPoint(vpt, sceneRect.left, sceneRect.top);
30
+ const p2 = transformPoint(vpt, sceneRect.left + sceneRect.width, sceneRect.top + sceneRect.height);
31
+ const x0 = Math.floor(Math.min(p1.x, p2.x) * dpr);
32
+ const x1 = Math.ceil(Math.max(p1.x, p2.x) * dpr);
33
+ const yTop = Math.min(p1.y, p2.y);
34
+ const yBottom = Math.max(p1.y, p2.y);
35
+ // y 翻转:CSS 顶左原点 → GL 底左原点(帧缓冲底边 = cssHeight − 矩形下沿)
36
+ const y0 = Math.floor((cssHeight - yBottom) * dpr);
37
+ const y1 = Math.ceil((cssHeight - yTop) * dpr);
38
+ const cx0 = Math.max(0, x0);
39
+ const cy0 = Math.max(0, y0);
40
+ const cx1 = Math.min(Math.ceil(cssWidth * dpr), x1);
41
+ const cy1 = Math.min(Math.ceil(cssHeight * dpr), y1);
42
+ return { x: cx0, y: cy0, w: Math.max(0, cx1 - cx0), h: Math.max(0, cy1 - cy0) };
43
+ }
44
+ /** 开启并设置页剪裁(零尺寸盒合法——本页绘制全弃置) */
45
+ export function applyScissor(gl, rect) {
46
+ gl.enable(gl.SCISSOR_TEST);
47
+ gl.scissor(rect.x, rect.y, rect.w, rect.h);
48
+ }
49
+ /** 关闭页剪裁(帧尾 finally/遮罩与覆盖层相位前) */
50
+ export function clearScissor(gl) {
51
+ gl.disable(gl.SCISSOR_TEST);
52
+ }
53
+ /** 烘焙豁免:记录并关闭 scissor,返回恢复函数(幂等;出口/finally 调用)。
54
+ * 未开启时零成本直通(单页态/导出链恒不开启)。 */
55
+ export function suspendScissor(gl) {
56
+ const wasEnabled = gl.isEnabled(gl.SCISSOR_TEST);
57
+ if (wasEnabled)
58
+ gl.disable(gl.SCISSOR_TEST);
59
+ let resumed = false;
60
+ return () => {
61
+ if (resumed)
62
+ return;
63
+ resumed = true;
64
+ if (wasEnabled)
65
+ gl.enable(gl.SCISSOR_TEST);
66
+ };
67
+ }
@@ -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.viewportTransform, bake.sceneW, bake.sceneH) : null;
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.viewportTransform });
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;
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@yft-design/engine",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
4
4
  "description": "yft-design 的 WebGL2 画布引擎:接受 fabric toObject 格式 JSON,输出 GL 画布 / 位图(任意倍率 FBO 读回)/ SVG(纯数据序列化器)",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/more-strive/yft-design-engine.git"
8
8
  },
9
- "license": "UNLICENSED",
9
+ "license": "MIT",
10
10
  "main": "./dist/index.js",
11
11
  "types": "./dist/index.d.ts",
12
12
  "exports": {