@yft-design/engine 0.0.14 → 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.
@@ -13,7 +13,7 @@
13
13
  import { objectCenter } from '../core/mat2d';
14
14
  import { AnimationPlayer, buildSequentialPlayback, buildSinglePreviewPlan, computeTotalDuration, evaluateSequentialAt, evaluateScrollTextOffset, evaluateSinglePreviewAt, getScrollTextDuration, readSerializedAnimates } from '../model/animation';
15
15
  import { WORKSPACE_ID } from '../model/scene';
16
- import { AnimatedNode, GroupNode, TextNode } from '../model/scene';
16
+ import { AnimatedNode, GroupNode, MaskNode, TextNode } from '../model/scene';
17
17
  import { scrollTrackInput } from '../render/scrollText';
18
18
  export class AnimationPlaybackController {
19
19
  host;
@@ -55,6 +55,8 @@ export class AnimationPlaybackController {
55
55
  for (const node of this.host.document.nodes) {
56
56
  if (node instanceof AnimatedNode)
57
57
  node.play();
58
+ else if (node instanceof MaskNode)
59
+ node.playClipMedia();
58
60
  }
59
61
  this.syncVideosToTime(this.player.time, true);
60
62
  this.applyScrollTextOffsets(this.player.time);
@@ -65,6 +67,8 @@ export class AnimationPlaybackController {
65
67
  for (const node of this.host.document.nodes) {
66
68
  if (node instanceof AnimatedNode)
67
69
  node.pause();
70
+ else if (node instanceof MaskNode)
71
+ node.pauseClipMedia();
68
72
  }
69
73
  this.host.requestRenderAll();
70
74
  }
@@ -80,6 +84,8 @@ export class AnimationPlaybackController {
80
84
  for (const node of this.host.document.nodes) {
81
85
  if (node instanceof AnimatedNode)
82
86
  node.stop();
87
+ else if (node instanceof MaskNode)
88
+ node.syncClipMediaToTime(0, false);
83
89
  }
84
90
  this.host.requestRenderAll();
85
91
  }
@@ -322,6 +328,12 @@ export class AnimationPlaybackController {
322
328
  for (const n of nodes) {
323
329
  if (n instanceof AnimatedNode)
324
330
  durations.push(n.mediaDuration);
331
+ else if (n instanceof MaskNode) {
332
+ // 蒙版动态 clip 视频(VideoPlay 预览时间轴):时长缺席则总时长 0,
333
+ // 播放立即 ended、进度条不可拖(用户报「视频蒙版预览不显示」的连坐面)
334
+ if (n.clipMediaDuration > 0)
335
+ durations.push(n.clipMediaDuration);
336
+ }
325
337
  else if (n instanceof GroupNode)
326
338
  collect(n.children);
327
339
  }
@@ -335,6 +347,8 @@ export class AnimationPlaybackController {
335
347
  for (const n of nodes) {
336
348
  if (n instanceof AnimatedNode)
337
349
  n.syncVideoToTime(time, playing);
350
+ else if (n instanceof MaskNode)
351
+ n.syncClipMediaToTime(time, playing);
338
352
  else if (n instanceof GroupNode)
339
353
  walk(n.children);
340
354
  }
@@ -102,6 +102,11 @@ export class TextEditingController {
102
102
  const s = Math.min(sel.start, sel.end);
103
103
  const e = Math.max(sel.start, sel.end);
104
104
  const nodeMatrix = node.matrix;
105
+ // 屏幕恒定宽/厚的世界量除数:节点矩阵 x 向线缩放(√(m0²+m1²),旋转载荷下
106
+ // 仍为纯缩放长度)。表格格内编辑 overlay 继承表级 scaleX/scaleY——不除尽
107
+ // 时表放大 N 倍光标屏幕宽随之 N 倍(「合并格输入光标非常粗」报障根因;
108
+ // 合并只是把用户带进格内编辑,普通格同粗)。k=0(退化矩阵)兜 1 防除零
109
+ const nodeScaleX = Math.hypot(nodeMatrix[0], nodeMatrix[1]) || 1;
105
110
  const quads = [];
106
111
  for (const line of layout.lines) {
107
112
  const ls = line.styleMap.flatStart;
@@ -128,8 +133,9 @@ export class TextEditingController {
128
133
  const coord = node.cursorCoord(s);
129
134
  if (coord) {
130
135
  // 屏幕 2px 恒定宽(px/zoom,selectionOverlay 同约定)——不可设世界尺寸
131
- // 下限:高倍 zoom 下 2/zoom<1 被钳位后屏幕宽 = zoom px,光标随缩放变粗
132
- const caretWidth = 2 / this.host.zoom;
136
+ // 下限:高倍 zoom 下 2/zoom<1 被钳位后屏幕宽 = zoom px,光标随缩放变粗。
137
+ // 再除节点矩阵缩放:quad 经 nodeMatrix 入屏,缩放不除尽则屏幕宽=2×scaleX
138
+ const caretWidth = 2 / this.host.zoom / nodeScaleX;
133
139
  quads.push({
134
140
  matrix: multiply(nodeMatrix, [1, 0, 0, 1, coord.x + caretWidth / 2, coord.y + coord.height / 2]),
135
141
  dims: { x: caretWidth, y: coord.height },
@@ -154,7 +160,7 @@ export class TextEditingController {
154
160
  const underlineY = baselineY + node.textStyle.fontSize * 0.14;
155
161
  quads.push({
156
162
  matrix: multiply(nodeMatrix, [1, 0, 0, 1, (x0 + x1) / 2, underlineY]),
157
- dims: { x: Math.max(0, x1 - x0), y: 1.5 / this.host.zoom },
163
+ dims: { x: Math.max(0, x1 - x0), y: 1.5 / this.host.zoom / nodeScaleX },
158
164
  color: CARET_COLOR
159
165
  });
160
166
  }
@@ -821,7 +821,8 @@ export declare class MaskNode extends SceneNode {
821
821
  private _clipImageEl;
822
822
  constructor(raw: SerializedNode);
823
823
  /** clipImage 源元素(加载完成挂载;dims 恒由序列化 width/height 决定,
824
- * 挂载不触几何失效——烘焙缓存签名含 src 自然失效) */
824
+ * 挂载不触几何失效——烘焙缓存签名含 src 自然失效;保留式帧染脏仍须显式
825
+ * 登记——装载期外(reloadMaskClipImage 运行时换图)快照重放不会重画本节点) */
825
826
  get clipImageEl(): HTMLImageElement | null;
826
827
  set clipImageEl(img: HTMLImageElement | null);
827
828
  /** clipImage 的序列化声明(无 src 的坏声明按无填充图处理) */
@@ -854,6 +855,17 @@ export declare class MaskNode extends SceneNode {
854
855
  /** 释放动态源(场景重建/dispose):视频暂停即可(元素由 SourceManager 建、
855
856
  * 场景重建即弃;不 pause 会后台占解码流);精灵图共享缓存不释放 */
856
857
  detachDynamicClip(): void;
858
+ /** clip 视频时长(秒;未挂载/非视频 0——时间轴总时长与 seek 钳制消费)。
859
+ * 元素未挂载时回落序列化 duration(装载链 fire-and-forget,play() 常早于
860
+ * attach——无回落则总时长 0、播放立即 ended,VideoPlay 预览时间轴瘫痪) */
861
+ get clipMediaDuration(): number;
862
+ /** clip 视频续播(playAnimations 编排;attach 时的自动播不经过时间轴) */
863
+ playClipMedia(): void;
864
+ /** clip 视频暂停(pauseAnimations 编排) */
865
+ pauseClipMedia(): void;
866
+ /** clip 视频对齐时间轴时刻(seekAnimations/播放对齐;镜像 syncVideoToTime:
867
+ * 先停再定位,playing 决定是否续播——loop 由元素自身 loop 属性承载) */
868
+ syncClipMediaToTime(time: number, playing: boolean): void;
857
869
  }
858
870
  /**
859
871
  * 拼图节点(P4-5b(2/2)):应用 FabricPuzzle 的引擎侧同构(GroupNode 子类)。
@@ -1572,8 +1572,11 @@ export class AnimatedNode extends SceneNode {
1572
1572
  this._anchorTime = performance.now();
1573
1573
  this._playing = sprite.framesLength > 1;
1574
1574
  this.blitFrame();
1575
- // dims 兜底从 0 变为帧尺寸,几何缓存随之失效(同 imageEl setter 语义)
1575
+ // dims 兜底从 0 变为帧尺寸,几何缓存随之失效(同 imageEl setter 语义);
1576
+ // 保留式帧染脏:装载链 fire-and-forget,attach 晚于首帧快照时不登记则
1577
+ // 重放永远跳过本节点(蒙版动态 clip 同款配方)
1576
1578
  this.invalidateGeometryCache();
1579
+ this._renderNotify?.();
1577
1580
  }
1578
1581
  /** 挂载视频元素(loadeddata 后由 EngineCanvas 调用):事件接线 + 自动播一遍 */
1579
1582
  attachVideo(el, onNewFrame) {
@@ -1598,6 +1601,8 @@ export class AnimatedNode extends SceneNode {
1598
1601
  }
1599
1602
  });
1600
1603
  this.invalidateGeometryCache();
1604
+ // 保留式帧染脏(同 attachSprite 批注:attach 晚于首帧快照的静态场景防冻结)
1605
+ this._renderNotify?.();
1601
1606
  el.play().catch(() => {
1602
1607
  /* 自动播放被策略拒绝(muted+playsInline 下罕见):定格首帧 */
1603
1608
  });
@@ -1715,7 +1720,11 @@ export class AnimatedNode extends SceneNode {
1715
1720
  get mediaDuration() {
1716
1721
  if (this.animatedKind === 'video') {
1717
1722
  const d = this._videoEl?.duration;
1718
- return d && Number.isFinite(d) ? d : 0;
1723
+ if (d && Number.isFinite(d))
1724
+ return d;
1725
+ // 序列化 duration 回落(挂载前 play() 同款口径,见 MaskNode.clipMediaDuration)
1726
+ const raw = Number(this.raw.duration);
1727
+ return Number.isFinite(raw) && raw > 0 ? raw : 0;
1719
1728
  }
1720
1729
  const sprite = this._sprite;
1721
1730
  if (!sprite)
@@ -2251,12 +2260,14 @@ export class MaskNode extends SceneNode {
2251
2260
  super(raw);
2252
2261
  }
2253
2262
  /** clipImage 源元素(加载完成挂载;dims 恒由序列化 width/height 决定,
2254
- * 挂载不触几何失效——烘焙缓存签名含 src 自然失效) */
2263
+ * 挂载不触几何失效——烘焙缓存签名含 src 自然失效;保留式帧染脏仍须显式
2264
+ * 登记——装载期外(reloadMaskClipImage 运行时换图)快照重放不会重画本节点) */
2255
2265
  get clipImageEl() {
2256
2266
  return this._clipImageEl;
2257
2267
  }
2258
2268
  set clipImageEl(img) {
2259
2269
  this._clipImageEl = img;
2270
+ this._renderNotify?.();
2260
2271
  }
2261
2272
  /** clipImage 的序列化声明(无 src 的坏声明按无填充图处理) */
2262
2273
  get clipImageRaw() {
@@ -2312,6 +2323,11 @@ export class MaskNode extends SceneNode {
2312
2323
  this._clipPlaying = sprite.framesLength > 1;
2313
2324
  this.clipDynamicVersion++;
2314
2325
  this.blitClipFrame();
2326
+ // 保留式帧染脏:装载链 fire-and-forget(SwiftShader 准死锁口径),attach 常
2327
+ // 晚于首帧快照——不登记则快照重放永远跳过本节点(VideoPlay 静态预览蒙版
2328
+ // 不显示的根因)。重推一次后:播放中 clipAnimating → animationActive 门
2329
+ // 自续全量帧;静止即定格新帧内容
2330
+ this._renderNotify?.();
2315
2331
  }
2316
2332
  /** 挂载视频元素:seeked/pause 补传帧版本 + 自动播(应用 renderDynamicElement
2317
2333
  * 的 videoElement.play 同语义;muted+playsInline 由 SourceManager 建) */
@@ -2320,12 +2336,16 @@ export class MaskNode extends SceneNode {
2320
2336
  this._clipOnNewFrame = onNewFrame ?? null;
2321
2337
  const markFrame = () => {
2322
2338
  this.clipDynamicVersion++;
2339
+ // play/pause/seeked 事件驱动的帧版本变化同样须染脏——静态期(快照有效、
2340
+ // 非播放中)事件到达时无登记则画面钉在旧帧
2341
+ this._renderNotify?.();
2323
2342
  this._clipOnNewFrame?.();
2324
2343
  };
2325
2344
  el.addEventListener('seeked', markFrame);
2326
2345
  el.addEventListener('pause', markFrame);
2327
2346
  el.addEventListener('play', markFrame);
2328
2347
  this.clipDynamicVersion++;
2348
+ this._renderNotify?.();
2329
2349
  el.play().catch(() => {
2330
2350
  /* 自动播放被策略拒绝(muted+playsInline 下罕见):定格首帧 */
2331
2351
  });
@@ -2390,6 +2410,55 @@ export class MaskNode extends SceneNode {
2390
2410
  this._clipVideoEl = null;
2391
2411
  this._clipSprite = null;
2392
2412
  this._clipFrameCanvas = null;
2413
+ this._renderNotify?.();
2414
+ }
2415
+ // ── 蒙版动态 clip 的播放编排面(VideoPlay 预览时间轴接入)──
2416
+ // 口径镜像 AnimatedNode.play/pause/syncVideoToTime/mediaDuration:仅视频
2417
+ //(GIF 帧机由渲染期 tick + animationActive 自续排驱动,编排器无需接管其
2418
+ // 播放态;时长计入同 AnimatedNode gif 的 sprite 口径)
2419
+ /** clip 视频时长(秒;未挂载/非视频 0——时间轴总时长与 seek 钳制消费)。
2420
+ * 元素未挂载时回落序列化 duration(装载链 fire-and-forget,play() 常早于
2421
+ * attach——无回落则总时长 0、播放立即 ended,VideoPlay 预览时间轴瘫痪) */
2422
+ get clipMediaDuration() {
2423
+ if (this.clipDynamicKind !== 'video')
2424
+ return 0;
2425
+ const d = this._clipVideoEl?.duration;
2426
+ if (d && Number.isFinite(d))
2427
+ return d;
2428
+ const raw = Number(this.clipImageRaw?.duration);
2429
+ return Number.isFinite(raw) && raw > 0 ? raw : 0;
2430
+ }
2431
+ /** clip 视频续播(playAnimations 编排;attach 时的自动播不经过时间轴) */
2432
+ playClipMedia() {
2433
+ if (this.clipDynamicKind !== 'video')
2434
+ return;
2435
+ this._clipVideoEl?.play().catch(() => undefined);
2436
+ }
2437
+ /** clip 视频暂停(pauseAnimations 编排) */
2438
+ pauseClipMedia() {
2439
+ if (this.clipDynamicKind !== 'video')
2440
+ return;
2441
+ this._clipVideoEl?.pause();
2442
+ }
2443
+ /** clip 视频对齐时间轴时刻(seekAnimations/播放对齐;镜像 syncVideoToTime:
2444
+ * 先停再定位,playing 决定是否续播——loop 由元素自身 loop 属性承载) */
2445
+ syncClipMediaToTime(time, playing) {
2446
+ if (this.clipDynamicKind !== 'video')
2447
+ return;
2448
+ const el = this._clipVideoEl;
2449
+ if (!el)
2450
+ return;
2451
+ el.pause();
2452
+ const duration = el.duration;
2453
+ const next = Number.isFinite(duration) && duration > 0 ? Math.min(Math.max(time, 0), duration) : Math.max(time, 0);
2454
+ try {
2455
+ el.currentTime = next;
2456
+ }
2457
+ catch {
2458
+ /* noop */
2459
+ }
2460
+ if (playing)
2461
+ el.play().catch(() => undefined);
2393
2462
  }
2394
2463
  }
2395
2464
  /**
@@ -20,6 +20,7 @@
20
20
  */
21
21
  import { effectiveShadow } from '../core/shadow';
22
22
  import { fillStyleForNode, traceShapeStrokePath } from './strokeBake';
23
+ import { suspendScissor } from './screenClip';
23
24
  /** 全屏三角(与 gpuShadow 相同的 trick,自持一份避免批次 1 回归面) */
24
25
  const VERT_TRI = `#version 300 es
25
26
  out vec2 vUv;
@@ -468,6 +469,11 @@ export class GpuFxPainter {
468
469
  this.maskMsaa = { fb, rb, samples, w, h };
469
470
  }
470
471
  const msaa = this.maskMsaa;
472
+ // MSAA 解析中转 RT:纯分配(无绘制),前移到绘制段之前——绘制段起豁
473
+ // 页剪裁后中间不再有 return 路径(免豁免泄漏,批次 414)
474
+ const resolveRt = this.ensureTarget(gl, 6, w, h);
475
+ if (!resolveRt)
476
+ return null;
471
477
  // 网格 VBO(rect 现构;形状族按 ShapeMesh 对象身份缓存——set() 重建即失效)
472
478
  let meshObj = mesh;
473
479
  if (!meshObj && rectDims) {
@@ -499,6 +505,9 @@ export class GpuFxPainter {
499
505
  gl.enableVertexAttribArray(loc);
500
506
  gl.vertexAttribPointer(loc, 2, gl.FLOAT, false, 0, 0);
501
507
  gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, bufs.ibo);
508
+ // 页剪裁豁免(批次 414):下方 MSAA 绘制/blit/pass 全在本内容尺寸坐标
509
+ // 系——多页帧 scissor 盒投到这里是随机区域(screenClip 头注)
510
+ const resumeScissor = suspendScissor(gl);
502
511
  gl.bindFramebuffer(gl.FRAMEBUFFER, msaa.fb);
503
512
  gl.viewport(0, 0, w, h);
504
513
  gl.clearColor(0, 0, 0, 0);
@@ -514,9 +523,6 @@ export class GpuFxPainter {
514
523
  // MSAA 解析必须 1:1 blit(缩放解析是 GL 非法操作——曾一步缩放 blit 静默
515
524
  // no-op 致蒙版全空):先 1:1 NEAREST 解析到 2× 中转纹理,再非 MSAA 缩放
516
525
  // blit(LINEAR 下采样)到 1× 蒙版纹理
517
- const resolveRt = this.ensureTarget(gl, 6, w, h);
518
- if (!resolveRt)
519
- return null;
520
526
  gl.bindFramebuffer(gl.READ_FRAMEBUFFER, msaa.fb);
521
527
  gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, resolveRt.fb);
522
528
  gl.blitFramebuffer(0, 0, w, h, 0, 0, w, h, gl.COLOR_BUFFER_BIT, gl.NEAREST);
@@ -534,6 +540,7 @@ export class GpuFxPainter {
534
540
  gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, null);
535
541
  gl.viewport(0, 0, viewportW, viewportH);
536
542
  this.restore(gl);
543
+ resumeScissor();
537
544
  return this.maskRt.tex;
538
545
  }
539
546
  /**
@@ -574,6 +581,9 @@ export class GpuFxPainter {
574
581
  const rt = this.slot(gl, node, options.sig, 'shadow', cw, ch);
575
582
  if (!rt)
576
583
  return null;
584
+ // 页剪裁豁免(批次 414):累积清空起全部 pass 在本内容尺寸坐标系
585
+ //(screenClip 头注;单页/导出态零直通)
586
+ const resumeScissor = suspendScissor(gl);
577
587
  // 清空累积
578
588
  gl.bindFramebuffer(gl.FRAMEBUFFER, accum.fb);
579
589
  gl.viewport(0, 0, cw, ch);
@@ -582,8 +592,14 @@ export class GpuFxPainter {
582
592
  for (const decl of decls) {
583
593
  const eff = pathMode ? { blur: decl.blur, offX: decl.offsetX, offY: decl.offsetY } : effectiveShadow(asDecl(decl), scaleX, scaleY);
584
594
  const blurred = this.blurChain(gl, srcTex, cw, ch, (eff.blur * rs) / 2, 0, 1, 2);
585
- if (!blurred)
595
+ // 出口状态归还(批次 414 一并收口:此处 return 曾泄 fb 绑定/viewport/
596
+ // blend/页剪裁——后续节点成片画错的同类面)
597
+ if (!blurred) {
598
+ gl.viewport(0, 0, options.viewportW, options.viewportH);
599
+ this.restore(gl);
600
+ resumeScissor();
586
601
  return null;
602
+ }
587
603
  // PS④(Normal):阴影层合成(canvas filter drop-shadow 的阴影部分)
588
604
  this.pass(gl, this.tintProg, accum, (p) => {
589
605
  gl.activeTexture(gl.TEXTURE0);
@@ -614,6 +630,7 @@ export class GpuFxPainter {
614
630
  });
615
631
  gl.viewport(0, 0, options.viewportW, options.viewportH);
616
632
  this.restore(gl);
633
+ resumeScissor();
617
634
  return { tex: rt.tex, w: cw, h: ch };
618
635
  }
619
636
  /**
@@ -630,6 +647,8 @@ export class GpuFxPainter {
630
647
  if (!rt)
631
648
  return null;
632
649
  const s = sourceTex;
650
+ // 页剪裁豁免(批次 414):pass 在本内容尺寸坐标系(screenClip 头注)
651
+ const resumeScissor = suspendScissor(gl);
633
652
  this.pass(gl, this.fillProg, rt, (p) => {
634
653
  gl.activeTexture(gl.TEXTURE0);
635
654
  gl.bindTexture(gl.TEXTURE_2D, s);
@@ -638,6 +657,7 @@ export class GpuFxPainter {
638
657
  });
639
658
  gl.viewport(0, 0, viewportW, viewportH);
640
659
  this.restore(gl);
660
+ resumeScissor();
641
661
  return rt.tex;
642
662
  }
643
663
  }
@@ -27,6 +27,7 @@
27
27
  */
28
28
  import { imageFiltersKey } from '../core/imageFilters';
29
29
  import { buildPasses, VERTEX_SOURCE } from './gpuFilterPasses';
30
+ import { suspendScissor } from './screenClip';
30
31
  /** 图片滤镜 GPU 链:程序缓存 + FBO ping-pong + 按节点签名缓存输出纹理 */
31
32
  export class GpuImageFilterChain {
32
33
  gl;
@@ -109,6 +110,10 @@ export class GpuImageFilterChain {
109
110
  if (!texA || !texB || !fboA || !fboB)
110
111
  return null;
111
112
  const quad = this.ensureQuad();
113
+ // 页剪裁豁免(批次 414):下方 pass 循环在本内容尺寸坐标系画进 FBO——
114
+ // 多页帧 scissor 盒投到这里是随机区域;此处起豁、恢复段复位(其间无
115
+ // early return,screenClip 头注)
116
+ const resumeScissor = suspendScissor(gl);
112
117
  let input = sourceTex;
113
118
  let outTex = texA;
114
119
  let outFbo = fboA;
@@ -145,6 +150,7 @@ export class GpuImageFilterChain {
145
150
  }
146
151
  const finalTex = input;
147
152
  // ---- 状态恢复 ----
153
+ resumeScissor();
148
154
  gl.bindVertexArray(prevVao);
149
155
  gl.bindFramebuffer(gl.FRAMEBUFFER, prevFbo);
150
156
  gl.viewport(prevViewport[0], prevViewport[1], prevViewport[2], prevViewport[3]);
@@ -23,6 +23,7 @@ import { effectiveShadow, shadowMargin } from '../core/shadow';
23
23
  import { AnimatedNode } from '../model/scene';
24
24
  import { drawSilhouette, linearExtent } from './shadowBake';
25
25
  import { createTexture2D } from './textureUpload';
26
+ import { suspendScissor } from './screenClip';
26
27
  /** 全屏三角(box/final 两 pass 的几何,vUv 在可见屏幕区恰好插值 0..1) */
27
28
  const VERT_TRI = `#version 300 es
28
29
  out vec2 vUv;
@@ -251,6 +252,9 @@ export class GpuShadowBaker {
251
252
  if (!(w > 0) || !(h > 0) || w > 8192 || h > 8192)
252
253
  return null;
253
254
  const sig = bakeSig(node, decl, w, h);
255
+ // 页剪裁豁免(批次 414):pass 全在本内容尺寸坐标系——多页帧的 scissor
256
+ // 盒投到这里是随机区域,进出豁免(screenClip 头注;单页/导出态零直通)
257
+ const resumeScissor = suspendScissor(gl);
254
258
  try {
255
259
  let entry = this.targets.get(node);
256
260
  if (entry && entry.sig !== sig) {
@@ -317,6 +321,7 @@ export class GpuShadowBaker {
317
321
  // 恢复 blend(QuadBatch 只在构造时开启一次——曾泄漏 disabled 状态)
318
322
  gl.enable(gl.BLEND);
319
323
  gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
324
+ resumeScissor();
320
325
  }
321
326
  }
322
327
  }
@@ -185,6 +185,7 @@ export declare class MultiPageController {
185
185
  }
186
186
  /** 多页分段帧(EngineCanvas.render 的 count>1 分支体;单页路径不经此)。
187
187
  * 相位序对齐单页帧:棋盘格(清屏后首笔,逐页)→ 逐页场景推入(页间
188
- * flushAll + begin 换装)→ 全页脏集出清 → 多洞遮罩 → 活动页覆盖层
189
- * (finishOverlay——OverlayTailHost 注入活动页 doc)。 */
188
+ * flushAll + begin 换装 + 页剪裁 scissor——内容不出页,批次 414)→ 全页
189
+ * 脏集出清 → 多洞遮罩 → 活动页覆盖层(finishOverlay——OverlayTailHost
190
+ * 注入活动页 doc)。 */
190
191
  export declare function renderMultiPageFrame(controller: MultiPageController, host: MultiPageFrameHost): void;
@@ -29,6 +29,7 @@ import { EngineDocument } from '../model/document';
29
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
34
  /**
34
35
  * 页间视觉间隙(CSS 像素,屏幕恒定):2026-10-15 实测 canva.cn 桌面编辑器,
@@ -328,8 +329,9 @@ function nodesBoundingBox(doc) {
328
329
  }
329
330
  /** 多页分段帧(EngineCanvas.render 的 count>1 分支体;单页路径不经此)。
330
331
  * 相位序对齐单页帧:棋盘格(清屏后首笔,逐页)→ 逐页场景推入(页间
331
- * flushAll + begin 换装)→ 全页脏集出清 → 多洞遮罩 → 活动页覆盖层
332
- * (finishOverlay——OverlayTailHost 注入活动页 doc)。 */
332
+ * flushAll + begin 换装 + 页剪裁 scissor——内容不出页,批次 414)→ 全页
333
+ * 脏集出清 → 多洞遮罩 → 活动页覆盖层(finishOverlay——OverlayTailHost
334
+ * 注入活动页 doc)。 */
333
335
  export function renderMultiPageFrame(controller, host) {
334
336
  controller.layout();
335
337
  const inv = invert(host.vpt);
@@ -352,18 +354,32 @@ export function renderMultiPageFrame(controller, host) {
352
354
  host.workspaceBackdrop.drawChecker(host.gl, canvasView, viewportParams, rects);
353
355
  const penScale = host.zoom * host.dpr;
354
356
  const expand = host.expandUnderlay();
355
- 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
+ }
356
376
  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
377
  }
366
- host.batchOrder.flushAll();
378
+ finally {
379
+ // 遮罩(全视口灰底+发光)/覆盖层(选框/hover/编辑光标)不裁——单页态
380
+ // 「内容被盖、选框可见」语义的多页推广;finally 保证中途异常不泄全局态
381
+ clearScissor(host.gl);
382
+ }
367
383
  controller.drainAll();
368
384
  host.workspaceBackdrop.drawBackdrop(host.gl, canvasView, viewportParams, rects);
369
385
  const activeView = sceneToClipMatrix(controller.pageVpt(host.vpt, controller.activeIndex), host.cssWidth, host.cssHeight, host.dpr);
@@ -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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yft-design/engine",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "description": "yft-design 的 WebGL2 画布引擎:接受 fabric toObject 格式 JSON,输出 GL 画布 / 位图(任意倍率 FBO 读回)/ SVG(纯数据序列化器)",
5
5
  "repository": {
6
6
  "type": "git",