@yft-design/engine 0.0.7 → 0.0.9

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.
@@ -31,6 +31,7 @@ import { type AnimationPlaybackInfo, type ScrollTextTrackInfo, type SinglePrevie
31
31
  import { type TableCellEditingHost } from './interact/tableCellEditing';
32
32
  import type { TableInteractionHost } from './interact/tableInteraction';
33
33
  import { type TextEditingHost } from './interact/textEditing';
34
+ import { RenderEpoch } from './render/renderEpoch';
34
35
  import { GradientRampCache } from './render/gradientRamp';
35
36
  import { GLTextureCache, type TextureCacheStats } from './render/GLTextureCache';
36
37
  import { BatchOrder } from './render/batchOrder';
@@ -76,6 +77,9 @@ export declare class EngineCanvas implements PointerHost, TextEditingHost, Sourc
76
77
  readonly textures: GLTextureCache;
77
78
  readonly gradientRamps: GradientRampCache;
78
79
  private readonly glyphAtlas;
80
+ /** 渲染产物统一失效纪元(批次 374 方向一):GlyphAtlas.reset/纹理淘汰经
81
+ * bump 汇入,保留式帧门链单点消费(RetainedFrameHost.renderEpoch) */
82
+ readonly renderEpoch: RenderEpoch;
79
83
  /** 源加载与图案/蒙版纹理(loadObjects 编排;渲染侧 SceneRenderer 读) */
80
84
  private readonly sources;
81
85
  /** 文本渲染管线(字形/背景/装饰/虚线/变形文本烘焙) */
@@ -33,6 +33,7 @@ import { TextEditingController } from './interact/textEditing';
33
33
  import { createGLContext } from './render/GLContext';
34
34
  import { FontInvalidationController } from './render/fontInvalidationController';
35
35
  import { GlyphAtlas } from './render/GlyphAtlas';
36
+ import { RenderEpoch } from './render/renderEpoch';
36
37
  import { GradientRampCache } from './render/gradientRamp';
37
38
  import { GLTextureCache } from './render/GLTextureCache';
38
39
  import { BatchOrder } from './render/batchOrder';
@@ -81,6 +82,9 @@ export class EngineCanvas {
81
82
  textures;
82
83
  gradientRamps;
83
84
  glyphAtlas;
85
+ /** 渲染产物统一失效纪元(批次 374 方向一):GlyphAtlas.reset/纹理淘汰经
86
+ * bump 汇入,保留式帧门链单点消费(RetainedFrameHost.renderEpoch) */
87
+ renderEpoch = new RenderEpoch();
84
88
  /** 源加载与图案/蒙版纹理(loadObjects 编排;渲染侧 SceneRenderer 读) */
85
89
  sources;
86
90
  /** 文本渲染管线(字形/背景/装饰/虚线/变形文本烘焙) */
@@ -168,12 +172,12 @@ export class EngineCanvas {
168
172
  this.batchOrder = new BatchOrder(this.batch, this.meshBatch);
169
173
  this.batch.order = this.batchOrder;
170
174
  this.meshBatch.order = this.batchOrder;
171
- this.textures = new GLTextureCache(handle.gl);
175
+ this.textures = new GLTextureCache(handle.gl, { epoch: this.renderEpoch });
172
176
  this.gradientRamps = new GradientRampCache(handle.gl);
173
177
  // 批次 42:provisional cell 被 loadingdone 丢弃后立即补帧(否则空转等下一次
174
178
  // 外部触发才重烘真字形);批次 46:帧界 settle(事件失联自愈路径)上报
175
179
  // family 集 → 宿主补齐排版/度量/烘焙失效(见 fontInvalidation 的 pendingSettle)
176
- this.glyphAtlas = new GlyphAtlas(handle.gl, () => this.requestRenderAll(), (families) => this.fontInvalidation.queueSettle(families));
180
+ this.glyphAtlas = new GlyphAtlas(handle.gl, () => this.requestRenderAll(), (families) => this.fontInvalidation.queueSettle(families), this.renderEpoch);
177
181
  this.dpr = options.dpr ?? (typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1);
178
182
  this.mobileControls = options.mobileControls ?? false;
179
183
  this.background = options.background ?? [0, 0, 0, 0];
@@ -866,6 +866,15 @@ export class TextNode extends SceneNode {
866
866
  * 字形/装饰线/背景高亮/光标/选区/阴影烘焙统一消费此口径。
867
867
  */
868
868
  get contentTopY() {
869
+ // 批次 370:位图态 dims=文档系位图 AABB(bitmapRect)——竖排/±90° 元素本地系
870
+ // 与文档系轴向互换(本地 Y=文档 X),而本值的消费面(编辑态字形/光标/选区/
871
+ // 划重点/剪影)全部工作在预旋本地系:块顶须锚排版内容高,位图盒高会把整块
872
+ // 沿本地 −Y(竖排=文档 +X)推出 (位图高−内容高)/2——「竖排 TextImage 进入
873
+ // 编辑向右偏移」报障根因。boxH 不进:位图态盒高是文档系值(存量解析形态),
874
+ // 且抬盒(width/height 属内容键)写入即转正脱离位图态——位图态无抬盒形态。
875
+ if (typeof this.raw.renderSrc === 'string') {
876
+ return -this.textLayout.height / 2;
877
+ }
869
878
  return -this.dims.y / 2;
870
879
  }
871
880
  /**
@@ -26,6 +26,7 @@
26
26
  *
27
27
  * context lost:invalidateAll() 清空(恢复事件里由渲染层重建)。
28
28
  */
29
+ import { RenderEpoch } from './renderEpoch';
29
30
  export type TextureSource = HTMLImageElement | HTMLCanvasElement | HTMLVideoElement;
30
31
  export interface GLTextureCacheOptions {
31
32
  /** 字节预算(估算口径),超出从最旧端淘汰;缺省 512 MiB */
@@ -35,6 +36,9 @@ export interface GLTextureCacheOptions {
35
36
  /** 插入压力淘汰的近帧宽限(帧数):lastFrame 距当前帧不足此值的条目跳过
36
37
  * 淘汰。缺省 30。1 = 仅本帧(旧行为)。 */
37
38
  evictGraceFrames?: number;
39
+ /** 统一失效纪元(批次 374 方向一):淘汰删句柄即 bump;EngineCanvas 注入
40
+ * 共享实例,缺省自建(直构单测=独立纪元) */
41
+ epoch?: RenderEpoch;
38
42
  }
39
43
  export interface TextureCacheStats {
40
44
  entries: number;
@@ -59,6 +63,8 @@ export declare class GLTextureCache {
59
63
  private evictions;
60
64
  private trackedBytes;
61
65
  private disposed;
66
+ /** 统一失效纪元(批次 374 方向一):淘汰即 bump,保留式门链经宿主共享实例消费 */
67
+ private readonly epoch;
62
68
  constructor(gl: WebGL2RenderingContext, options?: GLTextureCacheOptions);
63
69
  /** 帧界推进(EngineCanvas.render 顶部调用):此后的取用都算「本帧」。
64
70
  * 批次 321:不再做预算强制结算——帧界强逐在工作集超预算时构成
@@ -26,6 +26,7 @@
26
26
  *
27
27
  * context lost:invalidateAll() 清空(恢复事件里由渲染层重建)。
28
28
  */
29
+ import { RenderEpoch } from './renderEpoch';
29
30
  const DEFAULT_BUDGET_BYTES = 512 * 1024 * 1024;
30
31
  const DEFAULT_MAX_ENTRIES = 2048;
31
32
  const DEFAULT_EVICT_GRACE_FRAMES = 30;
@@ -44,11 +45,14 @@ export class GLTextureCache {
44
45
  evictions = 0;
45
46
  trackedBytes = 0;
46
47
  disposed = false;
48
+ /** 统一失效纪元(批次 374 方向一):淘汰即 bump,保留式门链经宿主共享实例消费 */
49
+ epoch;
47
50
  constructor(gl, options = {}) {
48
51
  this.gl = gl;
49
52
  this.budgetBytes = options.budgetBytes ?? DEFAULT_BUDGET_BYTES;
50
53
  this.maxEntries = options.maxEntries ?? DEFAULT_MAX_ENTRIES;
51
54
  this.evictGraceFrames = options.evictGraceFrames ?? DEFAULT_EVICT_GRACE_FRAMES;
55
+ this.epoch = options.epoch ?? new RenderEpoch();
52
56
  }
53
57
  /** 帧界推进(EngineCanvas.render 顶部调用):此后的取用都算「本帧」。
54
58
  * 批次 321:不再做预算强制结算——帧界强逐在工作集超预算时构成
@@ -156,6 +160,8 @@ export class GLTextureCache {
156
160
  this.cache.delete(source);
157
161
  this.trackedBytes -= entry.bytes;
158
162
  this.evictions += 1;
163
+ // 统一失效纪元(批次 374):被逐句柄可能已被保留式快照命令表引用
164
+ this.epoch.bump('texture-evict');
159
165
  return true;
160
166
  }
161
167
  return false;
@@ -19,6 +19,7 @@
19
19
  * 再做 pad+ankle mipmap 或 SDF。
20
20
  */
21
21
  import { type TextStrokeDecl, type TextStyleProps } from '../model/textLayout';
22
+ import { RenderEpoch } from './renderEpoch';
22
23
  export interface GlyphCell {
23
24
  /** 归属页索引(textureOf 反查) */
24
25
  pageIndex: number;
@@ -97,7 +98,10 @@ export declare class GlyphAtlas {
97
98
  * 全量失效,重复上报只会带来重复重排 */
98
99
  private readonly onProvisionalSettled?;
99
100
  private detachFontsListener;
100
- constructor(gl: WebGL2RenderingContext, onCellsInvalidated?: () => void, onProvisionalSettled?: (families: string[]) => void);
101
+ /** 统一失效纪元(批次 374 方向一):reset 删页纹理即 bump;EngineCanvas 注入
102
+ * 共享实例,缺省自建(直构单测=独立纪元) */
103
+ private readonly epoch;
104
+ constructor(gl: WebGL2RenderingContext, onCellsInvalidated?: () => void, onProvisionalSettled?: (families: string[]) => void, epoch?: RenderEpoch);
101
105
  /** document.fonts 的防御式取位(jsdom 旧版/非浏览器宿主可能缺) */
102
106
  private fontSet;
103
107
  /** 声明的 face 是否尚未就绪。两态都算 pending:
@@ -21,6 +21,7 @@
21
21
  import { fontDeclaration, GENERIC_FONTS } from '../model/textLayout';
22
22
  import { isRetainedDebugEnabled } from '../engineFlag';
23
23
  import { normalizeFamily } from './fontInvalidation';
24
+ import { RenderEpoch } from './renderEpoch';
24
25
  const PAGE_SIZE = 1024;
25
26
  const CELL_PAD = 2;
26
27
  /** miter 留白上限(px):防极端 miterLimit 让 cell 撑爆整页而让字形整体消失 */
@@ -93,10 +94,14 @@ export class GlyphAtlas {
93
94
  * 全量失效,重复上报只会带来重复重排 */
94
95
  onProvisionalSettled;
95
96
  detachFontsListener = null;
96
- constructor(gl, onCellsInvalidated, onProvisionalSettled) {
97
+ /** 统一失效纪元(批次 374 方向一):reset 删页纹理即 bump;EngineCanvas 注入
98
+ * 共享实例,缺省自建(直构单测=独立纪元) */
99
+ epoch;
100
+ constructor(gl, onCellsInvalidated, onProvisionalSettled, epoch = new RenderEpoch()) {
97
101
  this.gl = gl;
98
102
  this.onCellsInvalidated = onCellsInvalidated;
99
103
  this.onProvisionalSettled = onProvisionalSettled;
104
+ this.epoch = epoch;
100
105
  this.tmpCanvas = document.createElement('canvas');
101
106
  this.tmpCanvas.width = 8;
102
107
  this.tmpCanvas.height = 8;
@@ -225,6 +230,9 @@ export class GlyphAtlas {
225
230
  this.provisionalCells.clear();
226
231
  if (hadContent) {
227
232
  this._generation++;
233
+ // 统一失效纪元(批次 374):与 generation 同守卫块——reset 删全部页纹理,
234
+ // 快照命令表持有的活引用变死句柄,纪元 bump 进保留式门链
235
+ this.epoch.bump('atlas-reset');
228
236
  if (isRetainedDebugEnabled()) {
229
237
  console.warn('[retained] GlyphAtlas.reset → generation', this._generation, new Error('reset 调用栈取证').stack);
230
238
  }
@@ -7,6 +7,7 @@ import type { QuadBatch } from './QuadBatch';
7
7
  import type { MeshBatch } from './MeshBatch';
8
8
  import type { BatchOrder } from './batchOrder';
9
9
  import type { GLTextureCache } from './GLTextureCache';
10
+ import { SettleScheduler } from './settleScheduler';
10
11
  export interface SceneRendererHost {
11
12
  readonly gl: WebGL2RenderingContext;
12
13
  readonly batch: QuadBatch;
@@ -52,6 +53,10 @@ export declare class SceneRenderer {
52
53
  private readonly sources;
53
54
  private readonly text;
54
55
  readonly frame: FrameState;
56
+ /** 手势期帧预算调度底座(stale/settle 手势窗统一源,批次372 方向二第一刀):
57
+ * vpt 写点经 EngineCanvas→noteVptChange 汇入,三烘焙画家共享消费;后续
58
+ * 手势期排队任务策略(持截止时间/超预算让位)在此生长 */
59
+ readonly settle: SettleScheduler;
55
60
  /** 本帧是否全扁平(批次 223 重落保留式门):节点相位未触 FBO 隔离/混合路径
56
61
  * (renderIsolatedGroup/renderBlendedNode 置 false)——保留式快照只对
57
62
  * 扁平帧成立(隔离帧的命令重放缺少 FBO 边界语义)。场景相位前复位 */
@@ -82,7 +87,8 @@ export declare class SceneRenderer {
82
87
  /** 帧复位(EngineCanvas.render 开头,guard 之后调用):三态归零 + 本帧烘焙预算 */
83
88
  beginFrame(now: number): void;
84
89
  /** 视口变化通知(缩放/平移写点,2026-10-09 扩语义:描边/蒙版烘焙的栅格倍率
85
- * 与设备像素吸附都随 vpt 变化):stale 延迟重烘的手势窗口,语义见各画家 */
90
+ * 与设备像素吸附都随 vpt 变化):stale 延迟重烘的手势窗口——批次372 起
91
+ * 统一汇入 SettleScheduler(三画家消费同一窗口,语义见各画家头注) */
86
92
  noteVptChange(): void;
87
93
  /** 节点光栅蒙版纹理与屏幕 uv 摆放(组蒙版 + 形状族直挂蒙版——批次 178 泛化;
88
94
  * 无 mask/未加载返回 null。数学只依赖 raw.mask/dims/matrix,节点族无差) */
@@ -14,6 +14,7 @@ import { MaskBakeCache, maskSrcKey as maskClipSrcKey } from './maskRender';
14
14
  import { readTextureToCanvas } from './gpuImageFilters';
15
15
  import { ShadowPainter } from './shadowPainter';
16
16
  import { StrokePainter } from './strokePainter';
17
+ import { SettleScheduler } from './settleScheduler';
17
18
  import { ClipMaskPainter, clipDecl } from './clipMaskPainter';
18
19
  import { PsdEffectPainter, FX_BAKE_BUDGET_MS } from './psdEffectPainter';
19
20
  import { SharedGpuPainters } from './sharedGpuPainters';
@@ -25,6 +26,10 @@ export class SceneRenderer {
25
26
  sources;
26
27
  text;
27
28
  frame = { bakeDeadline: 0, bakeMore: false, animationActive: false };
29
+ /** 手势期帧预算调度底座(stale/settle 手势窗统一源,批次372 方向二第一刀):
30
+ * vpt 写点经 EngineCanvas→noteVptChange 汇入,三烘焙画家共享消费;后续
31
+ * 手势期排队任务策略(持截止时间/超预算让位)在此生长 */
32
+ settle;
28
33
  /** 本帧是否全扁平(批次 223 重落保留式门):节点相位未触 FBO 隔离/混合路径
29
34
  * (renderIsolatedGroup/renderBlendedNode 置 false)——保留式快照只对
30
35
  * 扁平帧成立(隔离帧的命令重放缺少 FBO 边界语义)。场景相位前复位 */
@@ -57,10 +62,13 @@ export class SceneRenderer {
57
62
  this.text = text;
58
63
  this.gpu = new SharedGpuPainters(host.gl);
59
64
  this.shadow = new ShadowPainter(host);
60
- this.stroke = new StrokePainter(host, this.frame);
65
+ // 手势窗/settle 统一底座(批次372 方向二第一刀):三画家共享同一实例——
66
+ // 单次 vpt 写点只排一个定时器、settle 只补一帧、跨画家窗口恒同步
67
+ this.settle = new SettleScheduler(() => this.host.requestRenderAll());
68
+ this.stroke = new StrokePainter(host, this.frame, this.settle);
61
69
  this.clip = new ClipMaskPainter(host, this.gpu);
62
- this.psd = new PsdEffectPainter(host, this.frame, this.gpu, () => this.puzzleBox);
63
- this.maskBake = new MaskBakeCache(host, this.frame);
70
+ this.psd = new PsdEffectPainter(host, this.frame, this.gpu, () => this.puzzleBox, this.settle);
71
+ this.maskBake = new MaskBakeCache(host, this.frame, this.settle);
64
72
  }
65
73
  /** 帧复位(EngineCanvas.render 开头,guard 之后调用):三态归零 + 本帧烘焙预算 */
66
74
  beginFrame(now) {
@@ -69,11 +77,10 @@ export class SceneRenderer {
69
77
  this.frame.bakeMore = false;
70
78
  }
71
79
  /** 视口变化通知(缩放/平移写点,2026-10-09 扩语义:描边/蒙版烘焙的栅格倍率
72
- * 与设备像素吸附都随 vpt 变化):stale 延迟重烘的手势窗口,语义见各画家 */
80
+ * 与设备像素吸附都随 vpt 变化):stale 延迟重烘的手势窗口——批次372 起
81
+ * 统一汇入 SettleScheduler(三画家消费同一窗口,语义见各画家头注) */
73
82
  noteVptChange() {
74
- this.psd.noteVptScaleChange();
75
- this.stroke.noteVptChange();
76
- this.maskBake.noteVptChange();
83
+ this.settle.noteInteraction();
77
84
  }
78
85
  /** 节点光栅蒙版纹理与屏幕 uv 摆放(组蒙版 + 形状族直挂蒙版——批次 178 泛化;
79
86
  * 无 mask/未加载返回 null。数学只依赖 raw.mask/dims/matrix,节点族无差) */
@@ -29,6 +29,7 @@
29
29
  * 烘焙,SceneExporter 按 bakeMore 多轮重渲兜底)。
30
30
  */
31
31
  import type { MaskNode } from '../model/scene';
32
+ import { SettleScheduler } from './settleScheduler';
32
33
  import type { FrameState, SceneRendererHost } from './SceneRenderer';
33
34
  /** base64 src 过大时取首尾特征作签名键(应用 maskSrcKey 同款;SceneRenderer 的
34
35
  * clipImage 滤镜读回缓存同源复用) */
@@ -71,15 +72,14 @@ export declare class MaskBakeCache {
71
72
  private readonly frame;
72
73
  /** 节点级烘焙缓存(WeakMap——节点删除后随 GC 回收;重烘前 deleteTexture 旧纹理) */
73
74
  private bakes;
74
- /** 最近一次视口写点时刻(stale 判定的手势窗口;-Infinity = 从未手势——
75
- * 0 会在钟起点被误判窗口内)与 settle 定时器 */
76
- private vptChangedAt;
77
- private settleTimer;
78
- constructor(host: SceneRendererHost, frame: FrameState);
75
+ /** 最近一次视口写点时刻(stale 判定的手势窗口)与 settle 定时器——统一
76
+ * 收敛至 SettleScheduler(批次372),见其头注 */
77
+ private readonly settle;
78
+ constructor(host: SceneRendererHost, frame: FrameState, settle?: SettleScheduler);
79
79
  /**
80
80
  * 视口变化通知(缩放/平移写点均调——蒙版烘焙只有 k=min(4,dpr×zoom×scaleBoost)
81
- * 随缩放变化,平移通知只顺延手势窗口,无害):记录时刻 + FX_SETTLE_MS settle
82
- * 定时器——持续手势期间零重烘焙(重烘+重传是重操作,卡手势不可接受),停止后
81
+ * 随缩放变化,平移通知只顺延手势窗口,无害):共享 SettleScheduler 记手势
82
+ * 窗口——持续手势期间零重烘焙(重烘+重传是重操作,卡手势不可接受),停止后
83
83
  * 由 settle 帧按每帧预算分帧补齐(frame.bakeDeadline/bakeMore)。与
84
84
  * StrokePainter.noteVptChange / PsdEffectPainter.noteVptScaleChange 同协议。
85
85
  */
@@ -29,7 +29,7 @@
29
29
  * 烘焙,SceneExporter 按 bakeMore 多轮重渲兜底)。
30
30
  */
31
31
  import { createTexture2D } from './textureUpload';
32
- import { FX_SETTLE_MS } from './psdEffectPainter';
32
+ import { SettleScheduler } from './settleScheduler';
33
33
  /** base64 src 过大时取首尾特征作签名键(应用 maskSrcKey 同款;SceneRenderer 的
34
34
  * clipImage 滤镜读回缓存同源复用) */
35
35
  export const maskSrcKey = (src) => {
@@ -157,29 +157,23 @@ export class MaskBakeCache {
157
157
  frame;
158
158
  /** 节点级烘焙缓存(WeakMap——节点删除后随 GC 回收;重烘前 deleteTexture 旧纹理) */
159
159
  bakes = new WeakMap();
160
- /** 最近一次视口写点时刻(stale 判定的手势窗口;-Infinity = 从未手势——
161
- * 0 会在钟起点被误判窗口内)与 settle 定时器 */
162
- vptChangedAt = -Infinity;
163
- settleTimer = null;
164
- constructor(host, frame) {
160
+ /** 最近一次视口写点时刻(stale 判定的手势窗口)与 settle 定时器——统一
161
+ * 收敛至 SettleScheduler(批次372),见其头注 */
162
+ settle;
163
+ constructor(host, frame, settle = new SettleScheduler(() => host.requestRenderAll())) {
165
164
  this.host = host;
166
165
  this.frame = frame;
166
+ this.settle = settle;
167
167
  }
168
168
  /**
169
169
  * 视口变化通知(缩放/平移写点均调——蒙版烘焙只有 k=min(4,dpr×zoom×scaleBoost)
170
- * 随缩放变化,平移通知只顺延手势窗口,无害):记录时刻 + FX_SETTLE_MS settle
171
- * 定时器——持续手势期间零重烘焙(重烘+重传是重操作,卡手势不可接受),停止后
170
+ * 随缩放变化,平移通知只顺延手势窗口,无害):共享 SettleScheduler 记手势
171
+ * 窗口——持续手势期间零重烘焙(重烘+重传是重操作,卡手势不可接受),停止后
172
172
  * 由 settle 帧按每帧预算分帧补齐(frame.bakeDeadline/bakeMore)。与
173
173
  * StrokePainter.noteVptChange / PsdEffectPainter.noteVptScaleChange 同协议。
174
174
  */
175
175
  noteVptChange() {
176
- this.vptChangedAt = performance.now();
177
- if (this.settleTimer !== null)
178
- clearTimeout(this.settleTimer);
179
- this.settleTimer = window.setTimeout(() => {
180
- this.settleTimer = null;
181
- this.host.requestRenderAll();
182
- }, FX_SETTLE_MS);
176
+ this.settle.noteInteraction();
183
177
  }
184
178
  /** 烘焙入口:sigBase+k 双命中直接复用;内容变化立即重烘;仅 k 变化走
185
179
  * stale 门(手势窗口/帧预算耗尽沿用旧烘焙,导出窗口恒新鲜) */
@@ -199,7 +193,7 @@ export class MaskBakeCache {
199
193
  // (逻辑尺寸不变,分辨率暂欠),settle 后补齐精确 k
200
194
  const now = performance.now();
201
195
  // 导出窗口(applyExportViewport 接管视口)不受手势门:k 换档立即新鲜烘焙
202
- const gesturing = !this.host.isExporting() && (now - this.vptChangedAt < FX_SETTLE_MS || this.settleTimer !== null);
196
+ const gesturing = !this.host.isExporting() && this.settle.isSettling(now);
203
197
  if (gesturing || now > this.frame.bakeDeadline) {
204
198
  this.frame.bakeMore = true;
205
199
  return cached;
@@ -1,10 +1,12 @@
1
1
  import { TextNode, type SceneNode } from '../model/scene';
2
2
  import { type PuzzleBox } from './puzzleClamp';
3
+ import { SettleScheduler } from './settleScheduler';
3
4
  import type { SharedGpuPainters } from './sharedGpuPainters';
4
5
  import type { FrameState, SceneRendererHost } from './SceneRenderer';
5
6
  /** PSD 烘焙分帧预算(每帧毫秒上限)与缩放 settle 窗口(beginFrame 侧共用) */
6
7
  export declare const FX_BAKE_BUDGET_MS = 6;
7
- export declare const FX_SETTLE_MS = 160;
8
+ /** settle 窗口常量随协议收敛迁至 SettleScheduler(批次372)——旧导入位保留转发 */
9
+ export { FX_SETTLE_MS } from './settleScheduler';
8
10
  export declare const bitmapFxNode: (node: TextNode) => TextNode;
9
11
  export declare class PsdEffectPainter {
10
12
  private readonly host;
@@ -16,13 +18,13 @@ export declare class PsdEffectPainter {
16
18
  * 矩阵/尺寸/源指纹(内容变化即失效重烘);bucket = 文本族缩放桶(仅它变化
17
19
  * 时走 stale 延迟重烘——跨桶烘焙是重操作,须避开缩放手势,见 noteVptScaleChange) */
18
20
  private psdBakes;
19
- /** 最近一次视口缩放变化时刻(stale 判定的手势窗口)与 settle 定时器 */
20
- private vptChangedAt;
21
- private fxSettleTimer;
22
- constructor(host: SceneRendererHost, frame: FrameState, gpu: SharedGpuPainters, getPuzzleBox: () => PuzzleBox | null);
21
+ /** 最近一次视口缩放变化时刻(stale 判定的手势窗口)与 settle 定时器——统一
22
+ * 收敛至 SettleScheduler(批次372),见其头注 */
23
+ private readonly settle;
24
+ constructor(host: SceneRendererHost, frame: FrameState, gpu: SharedGpuPainters, getPuzzleBox: () => PuzzleBox | null, settle?: SettleScheduler);
23
25
  /**
24
- * 视口缩放变化通知(文本特效 stale 重烘的手势窗口):记录时刻 + 160ms
25
- * settle 定时器——持续缩放期间零重烘焙(跨桶烘焙百毫秒级,卡手势不可接受),
26
+ * 视口缩放变化通知(文本特效 stale 重烘的手势窗口):共享 SettleScheduler
27
+ * 记手势窗口——持续缩放期间零重烘焙(跨桶烘焙百毫秒级,卡手势不可接受),
26
28
  * 停止后由 settle 帧按每帧预算分帧补齐(frame.bakeDeadline/bakeMore)。
27
29
  */
28
30
  noteVptScaleChange(): void;
@@ -24,9 +24,11 @@ import { pickZoomBucket } from './GlyphAtlas';
24
24
  import { bakePathEffectShadow, bakePsdShadow, bakePsdSolidFill, bakePsdStrokes, buildTextEffectSource, strokeSupersampleCap, imageFiltersSig } from './imageEffects';
25
25
  import { createTexture2D } from './textureUpload';
26
26
  import { clampQuadToPuzzleBox } from './puzzleClamp';
27
+ import { SettleScheduler } from './settleScheduler';
27
28
  /** PSD 烘焙分帧预算(每帧毫秒上限)与缩放 settle 窗口(beginFrame 侧共用) */
28
29
  export const FX_BAKE_BUDGET_MS = 6;
29
- export const FX_SETTLE_MS = 160;
30
+ /** settle 窗口常量随协议收敛迁至 SettleScheduler(批次372)——旧导入位保留转发 */
31
+ export { FX_SETTLE_MS } from './settleScheduler';
30
32
  /**
31
33
  * 位图态 fx 框架节点(批次 314 七补):PSD 效果的烘焙/铺放全链吃 node.matrix
32
34
  * (bake setTransform/签名/quad 铺放),位图态框架矩阵=渲染 quad 同款本地系
@@ -67,28 +69,23 @@ export class PsdEffectPainter {
67
69
  * 矩阵/尺寸/源指纹(内容变化即失效重烘);bucket = 文本族缩放桶(仅它变化
68
70
  * 时走 stale 延迟重烘——跨桶烘焙是重操作,须避开缩放手势,见 noteVptScaleChange) */
69
71
  psdBakes = new WeakMap();
70
- /** 最近一次视口缩放变化时刻(stale 判定的手势窗口)与 settle 定时器 */
71
- vptChangedAt = 0;
72
- fxSettleTimer = null;
73
- constructor(host, frame, gpu, getPuzzleBox) {
72
+ /** 最近一次视口缩放变化时刻(stale 判定的手势窗口)与 settle 定时器——统一
73
+ * 收敛至 SettleScheduler(批次372),见其头注 */
74
+ settle;
75
+ constructor(host, frame, gpu, getPuzzleBox, settle = new SettleScheduler(() => host.requestRenderAll())) {
74
76
  this.host = host;
75
77
  this.frame = frame;
76
78
  this.gpu = gpu;
77
79
  this.getPuzzleBox = getPuzzleBox;
80
+ this.settle = settle;
78
81
  }
79
82
  /**
80
- * 视口缩放变化通知(文本特效 stale 重烘的手势窗口):记录时刻 + 160ms
81
- * settle 定时器——持续缩放期间零重烘焙(跨桶烘焙百毫秒级,卡手势不可接受),
83
+ * 视口缩放变化通知(文本特效 stale 重烘的手势窗口):共享 SettleScheduler
84
+ * 记手势窗口——持续缩放期间零重烘焙(跨桶烘焙百毫秒级,卡手势不可接受),
82
85
  * 停止后由 settle 帧按每帧预算分帧补齐(frame.bakeDeadline/bakeMore)。
83
86
  */
84
87
  noteVptScaleChange() {
85
- this.vptChangedAt = performance.now();
86
- if (this.fxSettleTimer !== null)
87
- clearTimeout(this.fxSettleTimer);
88
- this.fxSettleTimer = window.setTimeout(() => {
89
- this.fxSettleTimer = null;
90
- this.host.requestRenderAll();
91
- }, FX_SETTLE_MS);
88
+ this.settle.noteInteraction();
92
89
  }
93
90
  render(node, phase) {
94
91
  // 路径族(P3-5c):只有 dropShadow[] 多层投影(PathCommon.renderShadow);
@@ -167,7 +164,7 @@ export class PsdEffectPainter {
167
164
  // (SceneExporter 按 bakeMore 多轮重渲兜底——2026-10-09 描边接入 stale
168
165
  // 协议时一并收口:此前缩放后 160ms 内导出会吃到手势期 stale 特效)
169
166
  const now = performance.now();
170
- const zooming = !this.host.isExporting() && (now - this.vptChangedAt < FX_SETTLE_MS || this.fxSettleTimer !== null);
167
+ const zooming = !this.host.isExporting() && this.settle.isSettling(now);
171
168
  if (zooming || now > this.frame.bakeDeadline) {
172
169
  this.frame.bakeMore = true;
173
170
  this.renderPsdBakeQuads(fxNode, bake, phase);
@@ -0,0 +1,28 @@
1
+ /**
2
+ * 渲染产物统一失效纪元(方向一第一刀,
3
+ * docs/2026-10-13_webgl2-render-jank-causes-and-watchlist.md §6.2)。
4
+ *
5
+ * 批次 223/225 的教训:纹理级失效(GlyphAtlas.reset 删全部页纹理、
6
+ * GLTextureCache 淘汰删句柄)不产生任何节点染脏——保留式快照持有死引用
7
+ * 重放即整层消失,自愈链对这类失效天然失明,只能靠失效源各自把计数
8
+ * 「接进门链」。此前是两个独立信号各自为政(atlas generation /
9
+ * evictionCount),批次 374 起收敛为单一单调纪元:
10
+ * - 失效源(reset/淘汰/未来的烘焙删除口)统一 `bump(reason)`;
11
+ * - 保留式帧门链快照只记一个 `artifactEpoch`,不等即回退全量帧——
12
+ * 新增失效源接一个 bump 就自动入门链,不可能再静默绕过(结构性收口);
13
+ * - `lastReason` 仅诊断(门链回退打点/快照收录日志)。
14
+ *
15
+ * 纪元只承载「产物级销毁」信号;节点级内容失效仍走 renderDirty 染脏
16
+ * (脏集重推语义不变)。EngineCanvas 持唯一实例注入 GlyphAtlas/
17
+ * GLTextureCache(缺省自建=独立纪元,直构单测等价旧口径)。
18
+ */
19
+ export declare class RenderEpoch {
20
+ private _value;
21
+ private _lastReason;
22
+ /** 单调纪元值(快照收录时记录比对) */
23
+ get value(): number;
24
+ /** 最近一次失效原因(仅诊断打点) */
25
+ get lastReason(): string;
26
+ /** 失效通知:任何「删了已被快照命令表引用的产物」的路径必须调用 */
27
+ bump(reason: string): void;
28
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * 渲染产物统一失效纪元(方向一第一刀,
3
+ * docs/2026-10-13_webgl2-render-jank-causes-and-watchlist.md §6.2)。
4
+ *
5
+ * 批次 223/225 的教训:纹理级失效(GlyphAtlas.reset 删全部页纹理、
6
+ * GLTextureCache 淘汰删句柄)不产生任何节点染脏——保留式快照持有死引用
7
+ * 重放即整层消失,自愈链对这类失效天然失明,只能靠失效源各自把计数
8
+ * 「接进门链」。此前是两个独立信号各自为政(atlas generation /
9
+ * evictionCount),批次 374 起收敛为单一单调纪元:
10
+ * - 失效源(reset/淘汰/未来的烘焙删除口)统一 `bump(reason)`;
11
+ * - 保留式帧门链快照只记一个 `artifactEpoch`,不等即回退全量帧——
12
+ * 新增失效源接一个 bump 就自动入门链,不可能再静默绕过(结构性收口);
13
+ * - `lastReason` 仅诊断(门链回退打点/快照收录日志)。
14
+ *
15
+ * 纪元只承载「产物级销毁」信号;节点级内容失效仍走 renderDirty 染脏
16
+ * (脏集重推语义不变)。EngineCanvas 持唯一实例注入 GlyphAtlas/
17
+ * GLTextureCache(缺省自建=独立纪元,直构单测等价旧口径)。
18
+ */
19
+ export class RenderEpoch {
20
+ _value = 0;
21
+ _lastReason = '';
22
+ /** 单调纪元值(快照收录时记录比对) */
23
+ get value() {
24
+ return this._value;
25
+ }
26
+ /** 最近一次失效原因(仅诊断打点) */
27
+ get lastReason() {
28
+ return this._lastReason;
29
+ }
30
+ /** 失效通知:任何「删了已被快照命令表引用的产物」的路径必须调用 */
31
+ bump(reason) {
32
+ this._value++;
33
+ this._lastReason = reason;
34
+ }
35
+ }
@@ -19,6 +19,7 @@
19
19
  import type { EngineDocument } from '../model/document';
20
20
  import type { Mat } from '../core/mat2d';
21
21
  import type { BatchOrder } from './batchOrder';
22
+ import type { RenderEpoch } from './renderEpoch';
22
23
  import type { GLTextureCache } from './GLTextureCache';
23
24
  import type { GlyphAtlas } from './GlyphAtlas';
24
25
  import type { MeshBatch } from './MeshBatch';
@@ -37,6 +38,9 @@ export interface RetainedFrameHost {
37
38
  readonly renderer: SceneRenderer;
38
39
  readonly textures: GLTextureCache;
39
40
  readonly glyphAtlas: GlyphAtlas;
41
+ /** 渲染产物统一失效纪元(批次 374 方向一):GlyphAtlas.reset/GLTextureCache
42
+ * 淘汰(及未来任何产物级删除口)经 bump 汇入,门链单点消费 */
43
+ readonly renderEpoch: RenderEpoch;
40
44
  readonly progressiveLoad: {
41
45
  readonly limit: number;
42
46
  };
@@ -60,12 +60,12 @@ export class RetainedFrameController {
60
60
  return this.gateFail('vpt');
61
61
  if (rf.dpr !== host.dpr || rf.sizeKey !== `${host.canvasEl.width}x${host.canvasEl.height}`)
62
62
  return this.gateFail('surface');
63
- if (rf.evictions !== host.textures.evictionCount)
64
- return this.gateFail('texture-evict');
65
- // 图集世代门(重落核心修复):reset 删全部页纹理零染脏——重放死句柄即
66
- // 文本整层消失;世代不等回退全量帧重栅格化
67
- if (rf.atlasGeneration !== host.glyphAtlas.generation)
68
- return this.gateFail('atlas-generation');
63
+ // 产物失效纪元门(批次 374 折叠图集世代+纹理淘汰两信号):纹理级失效
64
+ // (reset 删页纹理/淘汰删句柄)零节点染脏,快照命令表持有活引用——重放
65
+ // 死句柄 = 文本整层消失(模板 273 回归根因)。新增失效源经 renderEpoch
66
+ // .bump 汇入即自动入门链(方向一:结构性收口,不可能静默绕过)
67
+ if (rf.artifactEpoch !== host.renderEpoch.value)
68
+ return this.gateFail(`artifact-epoch(${host.renderEpoch.lastReason})`);
69
69
  const snap = rf.snap;
70
70
  const dirty = host.doc.renderDirty;
71
71
  for (const node of dirty) {
@@ -104,12 +104,12 @@ export class RetainedFrameController {
104
104
  if (host.batchOrder.hasNovelPaintReferences(snap))
105
105
  return this.gateFail('repush-commands');
106
106
  }
107
- // 批次 321 复检:重推期(renderSceneNode)新纹理插入可触发预算淘汰
108
- // (get miss → evictIfNeeded),被逐句柄若在快照命令表里(干净节点的
109
- // 纹理),重放即整帧消失。入口门读数在重推前——计数已变即整体回退
110
- // 全量帧(调用方全量重写覆盖本帧缓冲,无残留语义)
111
- if (rf.evictions !== host.textures.evictionCount)
112
- return this.gateFail('texture-evict-late');
107
+ // 批次 321 复检(批次 374 纪元化):重推期(renderSceneNode)新纹理插入
108
+ // 可触发预算淘汰(get miss → evictIfNeeded),被逐句柄若在快照命令表里
109
+ // (干净节点的纹理),重放即整帧消失。入口门读数在重推前——纪元已变即
110
+ // 整体回退全量帧(调用方全量重写覆盖本帧缓冲,无残留语义)
111
+ if (rf.artifactEpoch !== host.renderEpoch.value)
112
+ return this.gateFail(`artifact-epoch-late(${host.renderEpoch.lastReason})`);
113
113
  host.batch.restoreTotals(snap.quadTotal);
114
114
  host.meshBatch.restoreTotals(snap.meshTotal);
115
115
  host.batchOrder.discardRecorded();
@@ -141,8 +141,7 @@ export class RetainedFrameController {
141
141
  vptKey: host.vpt.join(','),
142
142
  dpr: host.dpr,
143
143
  sizeKey: `${host.canvasEl.width}x${host.canvasEl.height}`,
144
- evictions: host.textures.evictionCount,
145
- atlasGeneration: host.glyphAtlas.generation
144
+ artifactEpoch: host.renderEpoch.value
146
145
  }
147
146
  : null;
148
147
  if (snap && isRetainedDebugEnabled()) {
@@ -153,8 +152,8 @@ export class RetainedFrameController {
153
152
  meshSlots: snap.meshSlots.size,
154
153
  structureVersion: host.doc.structureVersion,
155
154
  atlasPages: atlas.pages,
156
- atlasGeneration: atlas.generation,
157
- evictions: host.textures.evictionCount
155
+ artifactEpoch: host.renderEpoch.value,
156
+ epochLastReason: host.renderEpoch.lastReason
158
157
  });
159
158
  }
160
159
  }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * 手势期帧预算调度器——烘焙族 stale/settle 手势窗的统一底座
3
+ * (docs/2026-10-13_webgl2-render-jank-causes-and-watchlist.md §6.3 方向二第一刀)。
4
+ *
5
+ * 此前三份同样的协议态各自为政(StrokePainter/PsdEffectPainter/MaskBakeCache
6
+ * 各持 vptChangedAt + settle 定时器)——本模块收敛为单一窗口源:
7
+ * - noteInteraction():视口写点(缩放/平移/吸附翻转)记录时刻 + 顺延 settle
8
+ * 定时器(FX_SETTLE_MS),停手后触发恰好一次补帧渲染(requestRenderAll);
9
+ * - isSettling():手势窗口判定(最近 FX_SETTLE_MS 内有交互或定时器在途),
10
+ * 画家消费位与 isExporting 门(导出窗口不受手势门)组合使用;
11
+ * - 画家构造参数可选注入(缺省自建——单测直构等价旧独立窗口;SceneRenderer
12
+ * 注入共享实例——单次 vpt 写点只排一个定时器/settle 只补一帧,跨画家窗口
13
+ * 恒同步)。lastInteractionAt 取 -Infinity 初始化(0 会在钟起点被误判窗口
14
+ * 内——PsdEffectPainter 旧 0 初始化的隐患随统一收口)。
15
+ *
16
+ * 后续手势期帧预算策略(排队任务持截止时间、超预算让位)在此底座上生长;
17
+ * 现有每帧烘焙预算(FrameState.bakeDeadline/bakeMore)语义不变。
18
+ */
19
+ /** 缩放/平移 settle 窗口(最后一次交互后多少毫秒视为停手) */
20
+ export declare const FX_SETTLE_MS = 160;
21
+ export declare class SettleScheduler {
22
+ private readonly requestRender;
23
+ /** 最近一次交互时刻(-Infinity = 从未交互) */
24
+ private lastInteractionAt;
25
+ private settleTimer;
26
+ constructor(requestRender: () => void);
27
+ /** 交互通知(视口写点):记录时刻 + 顺延 settle 定时器(持续手势期零补帧) */
28
+ noteInteraction(): void;
29
+ /** 手势窗口判定:最近 FX_SETTLE_MS 内有交互或 settle 定时器仍在途 */
30
+ isSettling(now?: number): boolean;
31
+ /** 丢弃未决 settle(定时器不再触发补帧,且彻底出窗——teardown 后消费方
32
+ * 的 isSettling 判定不再看到残留手势窗口) */
33
+ dispose(): void;
34
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * 手势期帧预算调度器——烘焙族 stale/settle 手势窗的统一底座
3
+ * (docs/2026-10-13_webgl2-render-jank-causes-and-watchlist.md §6.3 方向二第一刀)。
4
+ *
5
+ * 此前三份同样的协议态各自为政(StrokePainter/PsdEffectPainter/MaskBakeCache
6
+ * 各持 vptChangedAt + settle 定时器)——本模块收敛为单一窗口源:
7
+ * - noteInteraction():视口写点(缩放/平移/吸附翻转)记录时刻 + 顺延 settle
8
+ * 定时器(FX_SETTLE_MS),停手后触发恰好一次补帧渲染(requestRenderAll);
9
+ * - isSettling():手势窗口判定(最近 FX_SETTLE_MS 内有交互或定时器在途),
10
+ * 画家消费位与 isExporting 门(导出窗口不受手势门)组合使用;
11
+ * - 画家构造参数可选注入(缺省自建——单测直构等价旧独立窗口;SceneRenderer
12
+ * 注入共享实例——单次 vpt 写点只排一个定时器/settle 只补一帧,跨画家窗口
13
+ * 恒同步)。lastInteractionAt 取 -Infinity 初始化(0 会在钟起点被误判窗口
14
+ * 内——PsdEffectPainter 旧 0 初始化的隐患随统一收口)。
15
+ *
16
+ * 后续手势期帧预算策略(排队任务持截止时间、超预算让位)在此底座上生长;
17
+ * 现有每帧烘焙预算(FrameState.bakeDeadline/bakeMore)语义不变。
18
+ */
19
+ /** 缩放/平移 settle 窗口(最后一次交互后多少毫秒视为停手) */
20
+ export const FX_SETTLE_MS = 160;
21
+ export class SettleScheduler {
22
+ requestRender;
23
+ /** 最近一次交互时刻(-Infinity = 从未交互) */
24
+ lastInteractionAt = -Infinity;
25
+ settleTimer = null;
26
+ constructor(requestRender) {
27
+ this.requestRender = requestRender;
28
+ }
29
+ /** 交互通知(视口写点):记录时刻 + 顺延 settle 定时器(持续手势期零补帧) */
30
+ noteInteraction() {
31
+ this.lastInteractionAt = performance.now();
32
+ if (this.settleTimer !== null)
33
+ clearTimeout(this.settleTimer);
34
+ this.settleTimer = window.setTimeout(() => {
35
+ this.settleTimer = null;
36
+ this.requestRender();
37
+ }, FX_SETTLE_MS);
38
+ }
39
+ /** 手势窗口判定:最近 FX_SETTLE_MS 内有交互或 settle 定时器仍在途 */
40
+ isSettling(now = performance.now()) {
41
+ return now - this.lastInteractionAt < FX_SETTLE_MS || this.settleTimer !== null;
42
+ }
43
+ /** 丢弃未决 settle(定时器不再触发补帧,且彻底出窗——teardown 后消费方
44
+ * 的 isSettling 判定不再看到残留手势窗口) */
45
+ dispose() {
46
+ if (this.settleTimer !== null)
47
+ clearTimeout(this.settleTimer);
48
+ this.settleTimer = null;
49
+ this.lastInteractionAt = -Infinity;
50
+ }
51
+ }
@@ -1,22 +1,23 @@
1
1
  import type { SceneNode } from '../model/scene';
2
+ import { SettleScheduler } from './settleScheduler';
2
3
  import type { FrameState, SceneRendererHost } from './SceneRenderer';
3
4
  export declare class StrokePainter {
4
5
  private readonly host;
5
6
  private readonly frame;
7
+ /** 手势窗/settle 底座(SceneRenderer 注入共享实例;缺省自建=独立窗口) */
8
+ private readonly settle;
6
9
  /** 描边烘焙缓存(P3-2,场景空间):sigBase = 声明 + 矩阵 + 几何源(type/path/
7
10
  * points/rx)+ 尺寸(内容变化即失效立即重烘);k = 光栅 scale(zoom×dpr)——
8
11
  * 仅它或吸附 lx/ly 翻转变化时走 stale 延迟重烘(重烘+重传是重操作,须避开
9
12
  * 缩放/平移手势,见 noteVptChange)。lx/ly = 对齐后铺放左上角(snapped 时随
10
13
  * vpt 平移跨半像素界翻转同样延迟重烘,sceneW/H 供确定性重算) */
11
14
  private strokeBakes;
12
- /** 最近一次视口写点时刻(stale 判定的手势窗口;-Infinity = 从未手势——
13
- * 0 会在钟起点被误判窗口内)与 settle 定时器 */
14
- private vptChangedAt;
15
- private strokeSettleTimer;
16
- constructor(host: SceneRendererHost, frame: FrameState);
15
+ /** 最近一次视口写点时刻(stale 判定的手势窗口)与 settle 定时器——统一
16
+ * 收敛至 SettleScheduler(批次372),见其头注 */
17
+ constructor(host: SceneRendererHost, frame: FrameState, settle?: SettleScheduler);
17
18
  /**
18
19
  * 视口变化通知(缩放/平移写点均调——描边的光栅 scale 与设备像素吸附都随
19
- * vpt 变化):记录时刻 + FX_SETTLE_MS settle 定时器——持续手势期间零重烘焙
20
+ * vpt 变化):共享 SettleScheduler 记手势窗口——持续手势期间零重烘焙
20
21
  * (重烘+重传是重操作,卡手势不可接受),停止后由 settle 帧按每帧预算分帧
21
22
  * 补齐(frame.bakeDeadline/bakeMore)。与 PsdEffectPainter.noteVptScaleChange
22
23
  * 同协议(其注释含协议全貌)。
@@ -23,39 +23,34 @@ import { strokeKey } from '../core/stroke';
23
23
  import { strokeSdfParams } from './strokeSdf';
24
24
  import { bakeNodeStroke, strokeSnapOrigin } from './strokeBake';
25
25
  import { createTexture2D } from './textureUpload';
26
- import { FX_SETTLE_MS } from './psdEffectPainter';
26
+ import { SettleScheduler } from './settleScheduler';
27
27
  export class StrokePainter {
28
28
  host;
29
29
  frame;
30
+ /** 手势窗/settle 底座(SceneRenderer 注入共享实例;缺省自建=独立窗口) */
31
+ settle;
30
32
  /** 描边烘焙缓存(P3-2,场景空间):sigBase = 声明 + 矩阵 + 几何源(type/path/
31
33
  * points/rx)+ 尺寸(内容变化即失效立即重烘);k = 光栅 scale(zoom×dpr)——
32
34
  * 仅它或吸附 lx/ly 翻转变化时走 stale 延迟重烘(重烘+重传是重操作,须避开
33
35
  * 缩放/平移手势,见 noteVptChange)。lx/ly = 对齐后铺放左上角(snapped 时随
34
36
  * vpt 平移跨半像素界翻转同样延迟重烘,sceneW/H 供确定性重算) */
35
37
  strokeBakes = new WeakMap();
36
- /** 最近一次视口写点时刻(stale 判定的手势窗口;-Infinity = 从未手势——
37
- * 0 会在钟起点被误判窗口内)与 settle 定时器 */
38
- vptChangedAt = -Infinity;
39
- strokeSettleTimer = null;
40
- constructor(host, frame) {
38
+ /** 最近一次视口写点时刻(stale 判定的手势窗口)与 settle 定时器——统一
39
+ * 收敛至 SettleScheduler(批次372),见其头注 */
40
+ constructor(host, frame, settle = new SettleScheduler(() => host.requestRenderAll())) {
41
41
  this.host = host;
42
42
  this.frame = frame;
43
+ this.settle = settle;
43
44
  }
44
45
  /**
45
46
  * 视口变化通知(缩放/平移写点均调——描边的光栅 scale 与设备像素吸附都随
46
- * vpt 变化):记录时刻 + FX_SETTLE_MS settle 定时器——持续手势期间零重烘焙
47
+ * vpt 变化):共享 SettleScheduler 记手势窗口——持续手势期间零重烘焙
47
48
  * (重烘+重传是重操作,卡手势不可接受),停止后由 settle 帧按每帧预算分帧
48
49
  * 补齐(frame.bakeDeadline/bakeMore)。与 PsdEffectPainter.noteVptScaleChange
49
50
  * 同协议(其注释含协议全貌)。
50
51
  */
51
52
  noteVptChange() {
52
- this.vptChangedAt = performance.now();
53
- if (this.strokeSettleTimer !== null)
54
- clearTimeout(this.strokeSettleTimer);
55
- this.strokeSettleTimer = window.setTimeout(() => {
56
- this.strokeSettleTimer = null;
57
- this.host.requestRenderAll();
58
- }, FX_SETTLE_MS);
53
+ this.settle.noteInteraction();
59
54
  }
60
55
  render(node) {
61
56
  const decl = node.strokeDecl;
@@ -88,7 +83,7 @@ export class StrokePainter {
88
83
  if (bake.k !== k || (snap && (snap.lx !== bake.lx || snap.ly !== bake.ly))) {
89
84
  const now = performance.now();
90
85
  // 导出窗口(applyExportViewport 接管视口)不受手势门:k 换档立即新鲜烘焙
91
- const gesturing = !this.host.isExporting() && (now - this.vptChangedAt < FX_SETTLE_MS || this.strokeSettleTimer !== null);
86
+ const gesturing = !this.host.isExporting() && this.settle.isSettling(now);
92
87
  if (gesturing || now > this.frame.bakeDeadline) {
93
88
  this.frame.bakeMore = true;
94
89
  this.host.batch.pushQuad([1, 0, 0, 1, bake.lx + bake.w / 2, bake.ly + bake.h / 2], bake.w, bake.h, [1, 1, 1, node.renderOpacity], bake.tex);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yft-design/engine",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "yft-design 的 WebGL2 画布引擎:接受 fabric toObject 格式 JSON,输出 GL 画布 / 位图(任意倍率 FBO 读回)/ SVG(纯数据序列化器)",
5
5
  "repository": {
6
6
  "type": "git",