@yft-design/engine 0.0.16 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1696,7 +1696,7 @@ export class SvgExporter {
1696
1696
  // 圆族 dims 兜底(model/scene ShapeNode.dims 同式):circle=2·radius、
1697
1697
  // ellipse=2·rx/ry——fabric 序列化原生带 radius/rx/ry,width/height 可缺席
1698
1698
  // (2026-10-08 报障:radius-only Circle 记 dims-missing:Circle 整页回退)
1699
- if (type.toLowerCase() === 'circle') {
1699
+ if (type === ElementTypes.CIRCLE) {
1700
1700
  const r = 2 * num(raw, 'radius', NaN);
1701
1701
  if (!Number.isFinite(width))
1702
1702
  width = r;
@@ -31,6 +31,7 @@ import { AnimatedNode, MaskNode } from '../model/scene';
31
31
  import { maskCropLiveState, maskCropWriteProps } from '../model/maskCropEdit';
32
32
  import { applyCropCorner, applyCropEdge, applyCropRatioCorner, applyCropRatioPreset, applyScaleEquallyCrop, CROP_HANDLE_OFFSETS, fullImageCornerLocal, liveStateFromRaw, liveStateToRawProps, moveCropImage } from '../model/cropEdit';
33
33
  import { isCornerHandle } from '../model/handles';
34
+ import { CompatHistoryActions } from '../model/compatEvents';
34
35
  import { lineQuad } from '../render/selectionOverlay';
35
36
  /** 手柄命中半径(屏幕 px;fabric 口径 cornerSize 13 方形域的圆近似)。
36
37
  * 圆手柄贴视觉直径放大(16px)取 14——同心(crop=0)时让位角括号
@@ -276,7 +277,7 @@ export class CropSessionController {
276
277
  this.detachKey?.();
277
278
  this.detachKey = null;
278
279
  // 应用 fireCropImageEvent:每退必发(无变化也发——应用历史层按 action 分流)
279
- this.host.document.applyTransform([node], () => ({}), 'modified', { action: 'crop' });
280
+ this.host.document.applyTransform([node], () => ({}), 'modified', { action: CompatHistoryActions.crop });
280
281
  this.host.requestRenderAll();
281
282
  }
282
283
  /** pointer 点框外通道(应用 canvasMouseDown 的退出分支,同 exit) */
@@ -14,6 +14,7 @@ import { clampExpandImageCenter, expandPixelOffsets, expandRectOf, EXPAND_HANDLE
14
14
  import { AnimatedNode, MaskNode } from '../model/scene';
15
15
  import { objectOriginFromCenter, transformPoint } from '../core/mat2d';
16
16
  import { lineQuad } from '../render/selectionOverlay';
17
+ import { CompatHistoryActions } from '../model/compatEvents';
17
18
  import { parseColor } from '../core/color';
18
19
  const rad = (deg) => (deg * Math.PI) / 180;
19
20
  const HANDLE_HIT_PX = 12;
@@ -124,7 +125,7 @@ export class ExpandSessionController {
124
125
  expandBottomOffset: offsets.bottom
125
126
  });
126
127
  }
127
- this.host.document.applyTransform([node], () => ({}), 'modified', { action: 'crop' });
128
+ this.host.document.applyTransform([node], () => ({}), 'modified', { action: CompatHistoryActions.crop });
128
129
  this.host.requestRenderAll();
129
130
  }
130
131
  exitByOutsideClick() {
@@ -5,6 +5,7 @@
5
5
  * 薄委托(公开 API 面不变)。
6
6
  */
7
7
  import { isReferenceLineNode, WORKSPACE_IDS } from '../model/scene';
8
+ import { CompatHistoryActions } from '../model/compatEvents';
8
9
  /** Ctrl+A:全选可见对象(排除 workspace 族——应用 selectAllElement 同口径;
9
10
  * 原只滤 DrawType,Clip/Safe/Line 等装饰层会漏进全选;参考线排除(批次 72)
10
11
  * ——引导 chrome 非内容,fabric 落定线 selectable:false 同不进全选) */
@@ -35,7 +36,7 @@ export function nudgeSelectionAction(doc, dx, dy, requestRenderAll) {
35
36
  doc.setProps(node, { left: (node.raw.left ?? 0) + dx, top: (node.raw.top ?? 0) + dy }, { deferIndexRebuild: true });
36
37
  }
37
38
  doc.commitGeometry();
38
- doc.events.fire('object:modified', targets, { action: 'drag', before });
39
+ doc.fireObjectModified(targets, { action: CompatHistoryActions.drag, before });
39
40
  requestRenderAll();
40
41
  return targets.length;
41
42
  }
@@ -26,6 +26,7 @@
26
26
  * 手势同步维护,选框刚性跟随而非按成员 AABB 重新拟合。
27
27
  */
28
28
  import { createNode, createReferenceLineRaw, GroupNode, isReferenceLineNode, PuzzleNode, TableNode } from '../model/scene';
29
+ import { CompatHistoryActions } from '../model/compatEvents';
29
30
  import { RULER_SIZE } from '../render/ruler';
30
31
  import { buildSelectionRange, getBorderCursor, selectionBounds } from '../model/tableEdit';
31
32
  import { CORNER_ROTATE_CURSOR_OFFSET, CORNER_ROTATE_ZONE_PX, cornerOffsetToRadius, getActiveChildHandles, getAdaptiveSelectionHandles, getCornerRotateZones, HANDLE_HIT_PX, isImageRadiusHandleNode, isRadiusHandleNode, isUserLockedNode, MOVE_CONTROL_HIT_PX, moveControlPosition, moveControlTarget, radiusHandleTarget, rectCornerMaxRadius, rotateControlSpecByAngle, selectionQuadCoords } from '../render/selectionOverlay';
@@ -1535,12 +1536,12 @@ export class PointerController {
1535
1536
  // 全部将被触碰的节点
1536
1537
  const touched = refitGroupShells(g.childMove.shells);
1537
1538
  const targets = [...new Set([g.childMove.child, ...touched])];
1538
- doc.applyTransform(targets, () => ({}), 'modified', { action: 'drag', before: g.historyBefore });
1539
+ doc.applyTransform(targets, () => ({}), 'modified', { action: CompatHistoryActions.drag, before: g.historyBefore });
1539
1540
  }
1540
1541
  else {
1541
1542
  const nodes = [...g.snapshot.keys()];
1542
1543
  if (!this.host.transferDraggedNodes?.(nodes, g.historyBefore, cssX, cssY)) {
1543
- doc.applyTransform(nodes, () => ({}), 'modified', { action: 'drag', before: g.historyBefore });
1544
+ doc.applyTransform(nodes, () => ({}), 'modified', { action: CompatHistoryActions.drag, before: g.historyBefore });
1544
1545
  }
1545
1546
  }
1546
1547
  }
@@ -1567,10 +1568,10 @@ export class PointerController {
1567
1568
  const band = this.host.rulerVisible ? rulerBandAt(cssX, cssY) : null;
1568
1569
  if (band === g.axis || (g.creating && !this.performed)) {
1569
1570
  doc.remove(g.node);
1570
- doc.events.fire('object:modified', [g.node], { action: 'drag', before: g.historyBefore ? [g.historyBefore.get(g.node)].filter((s) => !!s) : undefined });
1571
+ doc.fireObjectModified([g.node], { action: CompatHistoryActions.drag, before: g.historyBefore ? [g.historyBefore.get(g.node)].filter((s) => !!s) : undefined });
1571
1572
  }
1572
1573
  else if (this.performed) {
1573
- doc.applyTransform([g.node], () => ({ selectable: false }), 'modified', { action: 'drag', before: g.historyBefore });
1574
+ doc.applyTransform([g.node], () => ({ selectable: false }), 'modified', { action: CompatHistoryActions.drag, before: g.historyBefore });
1574
1575
  }
1575
1576
  }
1576
1577
  else if (g.type === 'scale' || g.type === 'rotate') {
@@ -1591,11 +1592,11 @@ export class PointerController {
1591
1592
  // 圆角拖拽收尾(批次 100):action='cornerRadius'(fabric transform 的
1592
1593
  // actionName 原值),before 快照含旧 radius 供撤销回放
1593
1594
  if (this.performed)
1594
- doc.applyTransform([g.node], () => ({}), 'modified', { action: 'cornerRadius', before: g.historyBefore });
1595
+ doc.applyTransform([g.node], () => ({}), 'modified', { action: CompatHistoryActions.cornerRadius, before: g.historyBefore });
1595
1596
  }
1596
1597
  else if (g.type === 'multi-scale' || g.type === 'multi-rotate') {
1597
1598
  if (this.performed)
1598
- doc.applyTransform(g.snapshot.members.map((m) => m.node), () => ({}), 'modified', { action: g.type === 'multi-scale' ? 'scale' : 'rotate', before: g.historyBefore });
1599
+ doc.applyTransform(g.snapshot.members.map((m) => m.node), () => ({}), 'modified', { action: g.type === 'multi-scale' ? CompatHistoryActions.scale : CompatHistoryActions.rotate, before: g.historyBefore });
1599
1600
  }
1600
1601
  else if (g.type === 'marquee') {
1601
1602
  doc.commitGeometry();
@@ -1619,23 +1620,23 @@ export class PointerController {
1619
1620
  g.node.borderDragging = false;
1620
1621
  if (this.performed) {
1621
1622
  g.node.rebuildTable();
1622
- doc.applyTransform([g.node], () => ({}), 'modified', { action: 'scale', before: g.historyBefore });
1623
+ doc.applyTransform([g.node], () => ({}), 'modified', { action: CompatHistoryActions.scale, before: g.historyBefore });
1623
1624
  }
1624
1625
  }
1625
1626
  else if (g.type === 'table-edge-resize') {
1626
1627
  // 逐帧已烘焙重排并回钉;up 只提交(纯点击不发历史)
1627
1628
  if (this.performed)
1628
- doc.applyTransform([g.node], () => ({}), 'modified', { action: 'scale', before: g.historyBefore });
1629
+ doc.applyTransform([g.node], () => ({}), 'modified', { action: CompatHistoryActions.scale, before: g.historyBefore });
1629
1630
  }
1630
1631
  else if (g.type === 'puzzle-edge-resize') {
1631
1632
  // 同 table-edge-resize:逐帧已烘焙并回钉,up 只提交(纯点击不发历史)
1632
1633
  if (this.performed)
1633
- doc.applyTransform([g.node], () => ({}), 'modified', { action: 'scale', before: g.historyBefore });
1634
+ doc.applyTransform([g.node], () => ({}), 'modified', { action: CompatHistoryActions.scale, before: g.historyBefore });
1634
1635
  }
1635
1636
  else if (g.type === 'puzzle-mask-edge-resize') {
1636
1637
  // 分割线拖拽逐帧已写回;up 对拼图组提交一条(应用 historyTarget=group 同口径)
1637
1638
  if (this.performed)
1638
- doc.applyTransform([g.node], () => ({}), 'modified', { action: 'scale', before: g.historyBefore });
1639
+ doc.applyTransform([g.node], () => ({}), 'modified', { action: CompatHistoryActions.scale, before: g.historyBefore });
1639
1640
  }
1640
1641
  else if (g.type === 'table-indicator-click') {
1641
1642
  // up 时复核指示器命中(fabric 控件 mouseUp 在 up 命中的控件上触发,移开即不插入)
@@ -24,6 +24,7 @@ import { DocBusBinder } from '../core/events';
24
24
  import { TextNode } from '../model/scene';
25
25
  import { getCellData, masterPosition } from '../model/tableEdit';
26
26
  import { TextAlignValues } from '../model/textAlign';
27
+ import { CompatHistoryActions } from '../model/compatEvents';
27
28
  /** 应用 TableDefaultOptions.fontSize(tableLayout 的 CONSTRUCTOR_FONT_SIZE 同源) */
28
29
  const DEFAULT_FONT_SIZE = 14;
29
30
  /** 应用 Table.defaults.fontFamily(fromObject 不透传——表格级恒为应用默认) */
@@ -190,7 +191,7 @@ export class TableCellEditingController {
190
191
  // 整表全量写回含 cellData;TableNode.set 的结构键自动重排承接视觉恢复)
191
192
  const beforeMap = new Map();
192
193
  beforeMap.set(s.table, JSON.parse(s.snapshot));
193
- doc.applyTransform([s.table], () => ({}), 'modified', { action: 'table-cell-edit', before: beforeMap });
194
+ doc.applyTransform([s.table], () => ({}), 'modified', { action: CompatHistoryActions.tableCellEdit, before: beforeMap });
194
195
  }
195
196
  this.host.requestRenderAll();
196
197
  }
@@ -34,6 +34,7 @@
34
34
  import { Warpvas } from 'warpvas';
35
35
  import { AnimatedNode } from '../model/scene';
36
36
  import { objectOriginFromCenter, transformPoint } from '../core/mat2d';
37
+ import { CompatHistoryActions } from '../model/compatEvents';
37
38
  import { lineQuad } from '../render/selectionOverlay';
38
39
  /** 锚点命中半径(屏幕 px;fabric controls cornerSize 口径的圆近似) */
39
40
  const ANCHOR_HIT_PX = 12;
@@ -448,7 +449,7 @@ export class WarpSessionController {
448
449
  // objectModifiedDirtyHandler 标脏/刷内存 templates[i](扭曲状态入
449
450
  // templates[i]——保存/翻页真正读的数据源;此前退出零事件,store 不知
450
451
  // 情 =「扭曲状态没有记录」根因:保存回旧图、翻页回旧图)
451
- this.host.document.applyTransform([node], () => ({}), 'modified', { action: 'warpvas-image', before: new Map([[node, before]]) });
452
+ this.host.document.applyTransform([node], () => ({}), 'modified', { action: CompatHistoryActions.warpImage, before: new Map([[node, before]]) });
452
453
  committed = true;
453
454
  }
454
455
  this.requestRenderAll();
@@ -47,8 +47,10 @@ import { bakePsdShadow, bakePsdStrokes } from '../render/imageEffects';
47
47
  /** 掩码单边上限(同 app alphaMask:512×512=256KB/张) */
48
48
  const ALPHA_MASK_MAX_SIZE = 512;
49
49
  /** 生成类位图(二维码/条码/图表):内容整块生成无镂空语义,命中恒实心。
50
- * QRCode 另按 name 兜底豁免(app _checkTransparencyWithCache 同款)。 */
51
- const GENERATED_IMAGE_TYPES = new Set(['qrcode', 'QRCode', 'barcode', 'BarCode', 'echart', 'FabricEchart']);
50
+ * 判型一律走 typeKey——raw.type 保留 fabric toObject 原始大小写('QRCode'/
51
+ * 'BarCode'),裸比对会漏豁免。QRCode 另按 name 兜底豁免(app
52
+ * _checkTransparencyWithCache 同款)。 */
53
+ const GENERATED_IMAGE_TYPES = new Set([ElementTypes.QRCODE, ElementTypes.BARCODE, ElementTypes.ECHART, ElementTypes.FABRIC_ECHART]);
52
54
  /** 扩出型效果声明(引擎真渲染且扩出源 alpha 之外):dropShadow(阴影画在源外)
53
55
  * 与 stroke(outside/center 段超出源轮廓)。null = 无(掩码只看源 alpha)。 */
54
56
  const extendingFxDecls = (node) => {
@@ -246,11 +248,13 @@ export const isHitTransparent = (node, x, y, ctx) => {
246
248
  return !groupChildHitAt(node, x, y, ctx);
247
249
  if (!node.isImageType)
248
250
  return false;
249
- if (GENERATED_IMAGE_TYPES.has(node.raw.type))
251
+ // 判型走 typeKey(小写坍缩):raw.type 是 fabric toObject 原始大小写——模板
252
+ // 序列化图片恒 'Image',裸比对过不了小写集合 → 误判实心 → 透传失效(模板269)
253
+ if (GENERATED_IMAGE_TYPES.has(node.typeKey))
250
254
  return false;
251
255
  if (typeof node.raw.name === 'string' && node.raw.name.toLowerCase() === 'qrcode')
252
256
  return false;
253
- if (!IMAGE_LIKE_TYPES.has(node.raw.type))
257
+ if (!IMAGE_LIKE_TYPES.has(node.typeKey))
254
258
  return false;
255
259
  // PSD 效果不设门:solidFill 族 α⊆源由源掩码涵盖;扩出型(阴影/描边)的
256
260
  // alpha 已并进掩码(unionExtendingFxAlpha)——效果层 bake 失败时掩码为
@@ -21,6 +21,28 @@ export interface CompatSelectionEvent {
21
21
  export interface CompatObjectEvent {
22
22
  target: CompatObject;
23
23
  }
24
+ /**
25
+ * compat 历史协议常量(P3 历史契约升级,2026-10-16——主仓风险册 R1/R12):
26
+ * - 动作名以本常量对象为**唯一事实源**——引擎内发射点一律引用成员,不再散布
27
+ * 裸字符串;应用侧消费判定(如 crop 族跳过录制)经主仓锁定 spec 对齐本源,
28
+ * 引擎侧改名/删除时主仓测试拦红(而非靠注释约定)。
29
+ * - protocolVersion:compat 事件契约版本。1 = 无版本位现状(≤v0.0.16);
30
+ * 2 = object:modified 携带 transactionId/protocolVersion。应用侧对
31
+ * 「事件携带版本 < 期望版本」告警;缺省(旧引擎)不告警。
32
+ */
33
+ export declare const COMPAT_PROTOCOL_VERSION = 2;
34
+ export declare const CompatHistoryActions: {
35
+ /** 指针拖拽 / 方向键平移 */
36
+ readonly drag: "drag";
37
+ /** 缩放手柄族(手势类型值亦为 'scale'/'rotate',经 g.type 透出) */
38
+ readonly scale: "scale";
39
+ readonly rotate: "rotate";
40
+ readonly cornerRadius: "cornerRadius";
41
+ /** crop 族:应用历史层跳过录制(cropSession / expandSession 同值) */
42
+ readonly crop: "crop";
43
+ readonly tableCellEdit: "table-cell-edit";
44
+ readonly warpImage: "warpvas-image";
45
+ };
24
46
  export interface CompatObjectModifiedEvent extends CompatObjectEvent {
25
47
  /** 引擎批量语义的原生载荷;fabric 单 target 之上的扩展字段 */
26
48
  targets?: CompatObject[];
@@ -30,8 +52,15 @@ export interface CompatObjectModifiedEvent extends CompatObjectEvent {
30
52
  transform?: {
31
53
  original?: unknown;
32
54
  };
33
- /** fabric 动作名(drag/scale/rotate;crop 族供历史层跳过录制) */
55
+ /** fabric 动作名(值域=CompatHistoryActions;crop 族供历史层跳过录制) */
34
56
  action?: string;
57
+ /** 事务锚点(P3/R12):一次用户事务(手势/会话/编辑退出)= 一个 id,引擎侧
58
+ * 统一生成并随事件透出;应用侧透传进 History.transactionId(主仓 buildHistory
59
+ * 的 ?? 透传位),把「一次操作」锚成可对账的链。 */
60
+ transactionId?: string;
61
+ /** compat 事件协议版本(P3/R1):缺省 = 1(≤v0.0.16 无版本位);应用侧对
62
+ * 低于期望版本的携带值告警(双仓字段漂移的运行时观测位)。 */
63
+ protocolVersion?: number;
35
64
  }
36
65
  /** 引擎扩展事件(fabric 没有):一次文本编辑会话的 before/after 差值提交 */
37
66
  export interface CompatTextCommittedEvent {
@@ -1,3 +1,25 @@
1
+ /**
2
+ * compat 历史协议常量(P3 历史契约升级,2026-10-16——主仓风险册 R1/R12):
3
+ * - 动作名以本常量对象为**唯一事实源**——引擎内发射点一律引用成员,不再散布
4
+ * 裸字符串;应用侧消费判定(如 crop 族跳过录制)经主仓锁定 spec 对齐本源,
5
+ * 引擎侧改名/删除时主仓测试拦红(而非靠注释约定)。
6
+ * - protocolVersion:compat 事件契约版本。1 = 无版本位现状(≤v0.0.16);
7
+ * 2 = object:modified 携带 transactionId/protocolVersion。应用侧对
8
+ * 「事件携带版本 < 期望版本」告警;缺省(旧引擎)不告警。
9
+ */
10
+ export const COMPAT_PROTOCOL_VERSION = 2;
11
+ export const CompatHistoryActions = {
12
+ /** 指针拖拽 / 方向键平移 */
13
+ drag: 'drag',
14
+ /** 缩放手柄族(手势类型值亦为 'scale'/'rotate',经 g.type 透出) */
15
+ scale: 'scale',
16
+ rotate: 'rotate',
17
+ cornerRadius: 'cornerRadius',
18
+ /** crop 族:应用历史层跳过录制(cropSession / expandSession 同值) */
19
+ crop: 'crop',
20
+ tableCellEdit: 'table-cell-edit',
21
+ warpImage: 'warpvas-image'
22
+ };
1
23
  /** 把 EngineDocument 事件桥接成 compat 口径;返回解绑函数 */
2
24
  export const attachDocumentEventBridge = (document, deps) => {
3
25
  const { bus, wrap, syncSelection, settleSnap } = deps;
@@ -39,7 +61,8 @@ export const attachDocumentEventBridge = (document, deps) => {
39
61
  const beforeAll = detail?.before;
40
62
  const before = beforeAll?.length ? keep.map((i) => beforeAll[i]).filter((s) => !!s) : undefined;
41
63
  const transform = before && (before.length > 1 || keep.length > 1) ? { original: { objects: before } } : before ? { original: before[0] } : undefined;
42
- bus.fire('object:modified', { target: wrapped[0], targets: wrapped, transform, action: detail?.action });
64
+ // P3 历史契约:事务锚点与协议版本随事件透出(tid 由 document 发射层统一补全)
65
+ bus.fire('object:modified', { target: wrapped[0], targets: wrapped, transform, action: detail?.action, transactionId: detail?.transactionId, protocolVersion: COMPAT_PROTOCOL_VERSION });
43
66
  }),
44
67
  ev.on('text:editing:entered', (node) => fireObject('text:editing:entered', node)),
45
68
  ev.on('text:editing:exited', (node) => fireObject('text:editing:exited', node)),
@@ -532,7 +532,7 @@ export declare class CompatObject {
532
532
  refreshTextDimensions(): void;
533
533
  /** 应用 Textbox.replaceFontFamily 逐字移植:对象级 + 逐字 styles 同步替换 */
534
534
  replaceFontFamily(oldFont: string, newFont: string): boolean;
535
- /** 引擎 raw.type 小写归一(类型键两形态并存) */
535
+ /** 引擎 raw.type 小写归一(类型键两形态并存;typeKeyOf 单源) */
536
536
  private get rawTypeLower();
537
537
  /** 应用 ArcText.setRadius(→setCurvature):曲率直写(引擎 arcLayout 同键消费,
538
538
  * curvature=1° 也经 radius=1e5 近直渲染——0 值合法) */
@@ -28,6 +28,9 @@ import { isGroupWidthHandleNode } from './groupResize';
28
28
  import { deriveArcCharTransformations } from './arcTextTransform';
29
29
  import { buildEngineShapePath } from './shapePath';
30
30
  import { attachTableFacade } from './tableFacade';
31
+ /** 变形文字族(archtext/waisttext/flagtext):setWarpStrength/clearCache 门
32
+ * (const 对象数组 includes 对 string 协变拒绝——模块级 string 集合单源) */
33
+ const WARP_TEXT_TYPES = new Set([ElementTypes.ARCHTEXT, ElementTypes.WAISTTEXT, ElementTypes.FLAGTEXT]);
31
34
  /** 文本排版三件的快照形态校验(svgExport.parseTextLayout 同口径——string[] 行 +
32
35
  * 逐行 charBox 数组 + finite 行高;不引引擎 export 模块防依赖倒挂) */
33
36
  const isValidTextLayoutSnapshot = (o) => {
@@ -104,7 +107,7 @@ export class CompatObject {
104
107
  // 拼图 resizeByContainer 同语义):next = cover(new) × (prev / cover(old)),
105
108
  // 幂等。同批显式写 clipImage 的面自带语义跳过(防双重折算)。
106
109
  let propsToWrite = props;
107
- if ((typeof props.width === 'number' || typeof props.height === 'number') && !('clipImage' in props) && MASK_TYPES.has(String(this.node.raw.type ?? ''))) {
110
+ if ((typeof props.width === 'number' || typeof props.height === 'number') && !('clipImage' in props) && MASK_TYPES.has(typeKeyOf(this.node.raw))) {
108
111
  const clip = clipImageRawOf(this.node);
109
112
  const raw = this.node.raw;
110
113
  const prevW = Number(raw.width) || 0;
@@ -772,7 +775,7 @@ export class CompatObject {
772
775
  /** fabric isType:types 含 constructor.type 或 this.type——引擎 raw.type 兼存小写
773
776
  * 形态('rect')而应用调用恒用规范名,改大小写不敏感比对(check.isTextObject 等消费) */
774
777
  isType(...types) {
775
- const own = String(this.node.raw.type ?? '').toLowerCase();
778
+ const own = typeKeyOf(this.node.raw);
776
779
  return types.some((type) => type.toLowerCase() === own);
777
780
  }
778
781
  /** fabric getStyleAtPosition(fontSize 多值检测等消费):扁平字符位按 '\n' 分解到
@@ -1070,21 +1073,21 @@ export class CompatObject {
1070
1073
  // 存在性=类型判别器(ARC/WARP/CIRCLE 变形面板按 typeof 判可写),按文本子类型
1071
1074
  // 条件暴露;引擎布局键同名直读 raw(arcLayout 消费 curvature/circle*、warpText
1072
1075
  // 消费 warpStrength),写值经 set 触发排版重算与重绘 ——
1073
- /** 引擎 raw.type 小写归一(类型键两形态并存) */
1076
+ /** 引擎 raw.type 小写归一(类型键两形态并存;typeKeyOf 单源) */
1074
1077
  get rawTypeLower() {
1075
- return String(this.node.raw.type ?? '').toLowerCase();
1078
+ return typeKeyOf(this.node.raw);
1076
1079
  }
1077
1080
  /** 应用 ArcText.setRadius(→setCurvature):曲率直写(引擎 arcLayout 同键消费,
1078
1081
  * curvature=1° 也经 radius=1e5 近直渲染——0 值合法) */
1079
1082
  get setRadius() {
1080
- if (this.rawTypeLower !== 'arctext')
1083
+ if (this.rawTypeLower !== ElementTypes.ARCTEXT)
1081
1084
  return undefined;
1082
1085
  return (value) => this.set({ curvature: value });
1083
1086
  }
1084
1087
  /** 应用 ArchText/WaistText/FlagText.setWarpStrength:钳 [-1,1] 后直写(引擎
1085
1088
  * warpText 同键消费;原实现的 store setElement 同步由面板历史链承接,不重复) */
1086
1089
  get setWarpStrength() {
1087
- if (!['archtext', 'waisttext', 'flagtext'].includes(this.rawTypeLower))
1090
+ if (!WARP_TEXT_TYPES.has(this.rawTypeLower))
1088
1091
  return undefined;
1089
1092
  return (value) => this.set({ warpStrength: Math.max(-1, Math.min(1, value)) });
1090
1093
  }
@@ -1094,7 +1097,7 @@ export class CompatObject {
1094
1097
  * font.ts rerenderTextObjects/refreshReplacedTextElements 的 typeof 守卫消费面
1095
1098
  * 同步点亮。ArchText 同烘焙族顺带覆盖(fabric 侧由各自 _render 缓存键自愈) */
1096
1099
  get clearCache() {
1097
- if (!['archtext', 'waisttext', 'flagtext'].includes(this.rawTypeLower))
1100
+ if (!WARP_TEXT_TYPES.has(this.rawTypeLower))
1098
1101
  return undefined;
1099
1102
  return () => {
1100
1103
  this.ctx.invalidateNodeBakes?.(this.node);
@@ -1104,7 +1107,7 @@ export class CompatObject {
1104
1107
  /** 应用 CircleText.setCircleParams:补丁直写(circleSize/circleStartAngle/
1105
1108
  * circleSweep/circleEccentricity/circleDirection——引擎 arcLayout 同键消费) */
1106
1109
  get setCircleParams() {
1107
- if (this.rawTypeLower !== 'circletext')
1110
+ if (this.rawTypeLower !== ElementTypes.CIRCLETEXT)
1108
1111
  return undefined;
1109
1112
  return (patch) => this.set(patch);
1110
1113
  }
@@ -48,6 +48,10 @@ export interface SelectionFrame {
48
48
  export interface ObjectModifiedDetail {
49
49
  action?: string;
50
50
  before?: SerializedNode[];
51
+ /** 事务锚点(P3/R12,2026-10-16):一次用户事务=一个 id。调用方(会话)携带
52
+ * 则透传共享;缺省由 fireObjectModified 统一生成——引擎内所有 object:modified
53
+ * 必经该发射口,保证事件恒带 tid。 */
54
+ transactionId?: string;
51
55
  }
52
56
  export interface EngineDocumentEvents {
53
57
  'selection:created': [targets: SceneNode[]];
@@ -269,7 +273,15 @@ export declare class EngineDocument {
269
273
  applyTransform(targets: SceneNode[], props: (target: SceneNode) => Partial<SerializedNode>, phase: 'moving' | 'scaling' | 'rotating' | 'cornerRadius' | 'modified', detail?: {
270
274
  action?: string;
271
275
  before?: Map<SceneNode, SerializedNode>;
276
+ transactionId?: string;
272
277
  }): void;
278
+ /**
279
+ * object:modified 的统一发射口(P3 历史契约,2026-10-16——主仓风险册 R12):
280
+ * detail 携带调用方 transactionId 则透传(同会话多事件共享一事务),缺省
281
+ * 生成——引擎内**所有** object:modified 必经此口(applyTransform/文本编辑
282
+ * 退出/直发手势收尾),保证事件恒带事务锚点。增量字段,旧订阅方零改动。
283
+ */
284
+ fireObjectModified(targets: SceneNode[], detail?: ObjectModifiedDetail): void;
273
285
  enterEditing(node: TextNode, options?: {
274
286
  transient?: boolean;
275
287
  }): void;
@@ -17,6 +17,13 @@ import { EventBus } from '../core/events';
17
17
  import { isHitTransparent } from './alphaHit';
18
18
  import { buildScene, GroupNode, isReferenceLineNode, isStrokeLineNode, LINE_STROKE_HIT_TOLERANCE, PuzzleNode, TableNode, WORKSPACE_IDS } from './scene';
19
19
  import RBush from 'rbush';
20
+ /** 历史事务锚点生成:会话内递增序号+时间戳——诊断/对账锚点用途(非安全域,
21
+ * 引擎零外部依赖故不引 nanoid) */
22
+ let historyTransactionSeq = 0;
23
+ const newHistoryTransactionId = () => {
24
+ historyTransactionSeq = (historyTransactionSeq + 1) % 0xffffffff;
25
+ return `tx-${Date.now().toString(36)}-${historyTransactionSeq.toString(36)}`;
26
+ };
20
27
  export class EngineDocument {
21
28
  events = new EventBus();
22
29
  _nodes = [];
@@ -444,18 +451,29 @@ export class EngineDocument {
444
451
  if (phase === 'modified') {
445
452
  this.commitGeometry();
446
453
  const before = detail?.before;
447
- const firedDetail = before || detail?.action
454
+ const firedDetail = before || detail?.action || detail?.transactionId
448
455
  ? {
449
456
  action: detail?.action,
450
- before: before ? targets.map((t) => before.get(t)).filter((s) => !!s) : undefined
457
+ before: before ? targets.map((t) => before.get(t)).filter((s) => !!s) : undefined,
458
+ transactionId: detail?.transactionId
451
459
  }
452
460
  : undefined;
453
- this.events.fire('object:modified', [...targets], firedDetail);
461
+ this.fireObjectModified([...targets], firedDetail);
454
462
  }
455
463
  else {
456
464
  this.events.fire(`object:${phase}`, targets[0]);
457
465
  }
458
466
  }
467
+ /**
468
+ * object:modified 的统一发射口(P3 历史契约,2026-10-16——主仓风险册 R12):
469
+ * detail 携带调用方 transactionId 则透传(同会话多事件共享一事务),缺省
470
+ * 生成——引擎内**所有** object:modified 必经此口(applyTransform/文本编辑
471
+ * 退出/直发手势收尾),保证事件恒带事务锚点。增量字段,旧订阅方零改动。
472
+ */
473
+ fireObjectModified(targets, detail) {
474
+ const transactionId = detail?.transactionId ?? newHistoryTransactionId();
475
+ this.events.fire('object:modified', targets, { ...detail, transactionId });
476
+ }
459
477
  // #endregion
460
478
  // #region 文本编辑态
461
479
  enterEditing(node, options = {}) {
@@ -513,7 +531,7 @@ export class EngineDocument {
513
531
  const after = node.raw.text ?? '';
514
532
  if (after !== this._editingTextSnapshot) {
515
533
  this.events.fire('text:editing:committed', node, this._editingTextSnapshot, after);
516
- this.events.fire('object:modified', [node], { before: this._editingBeforeObject ? [this._editingBeforeObject] : undefined });
534
+ this.fireObjectModified([node], { before: this._editingBeforeObject ? [this._editingBeforeObject] : undefined });
517
535
  }
518
536
  else if (this._editingBitmapSnapshot) {
519
537
  // 批次 314 五补:值等价退出(纯进入退出/键入后删回原文)——恢复位图声明
@@ -1087,14 +1087,14 @@ export class ShapeNode extends SceneNode {
1087
1087
  if (this._mesh === undefined) {
1088
1088
  const raw = this.raw;
1089
1089
  const kind = this.shapeKind;
1090
- if (kind === 'ellipse') {
1090
+ if (kind === ElementTypes.ELLIPSE) {
1091
1091
  this._mesh = buildEllipseMesh(raw.rx ?? 0, raw.ry ?? 0);
1092
1092
  }
1093
- else if (kind === 'circle') {
1093
+ else if (kind === ElementTypes.CIRCLE) {
1094
1094
  const r = raw.radius ?? 0;
1095
1095
  this._mesh = buildEllipseMesh(r, r);
1096
1096
  }
1097
- else if (kind === 'triangle') {
1097
+ else if (kind === ElementTypes.TRIANGLE) {
1098
1098
  this._mesh = buildPolygonMesh(trianglePoints(raw));
1099
1099
  }
1100
1100
  else {
@@ -1107,11 +1107,11 @@ export class ShapeNode extends SceneNode {
1107
1107
  get dims() {
1108
1108
  const raw = this.raw;
1109
1109
  const kind = this.shapeKind;
1110
- if (kind === 'ellipse')
1110
+ if (kind === ElementTypes.ELLIPSE)
1111
1111
  return { x: 2 * (raw.rx ?? 0), y: 2 * (raw.ry ?? 0) };
1112
- if (kind === 'circle')
1112
+ if (kind === ElementTypes.CIRCLE)
1113
1113
  return { x: 2 * (raw.radius ?? 0), y: 2 * (raw.radius ?? 0) };
1114
- if (kind === 'triangle')
1114
+ if (kind === ElementTypes.TRIANGLE)
1115
1115
  return { x: raw.width ?? 0, y: raw.height ?? 0 };
1116
1116
  return polygonDims(raw.points);
1117
1117
  }
@@ -1123,7 +1123,7 @@ export class ShapeNode extends SceneNode {
1123
1123
  return hitStrokeVisible(this) && this.outlineStrokeHitAt(x, y, hitBand);
1124
1124
  const local = this.localPoint(x, y);
1125
1125
  const kind = this.shapeKind;
1126
- if (kind === 'ellipse' || kind === 'circle') {
1126
+ if (kind === ElementTypes.ELLIPSE || kind === ElementTypes.CIRCLE) {
1127
1127
  const rx = this.dims.x / 2;
1128
1128
  const ry = this.dims.y / 2;
1129
1129
  if (!(rx > 0) || !(ry > 0))
@@ -1133,13 +1133,13 @@ export class ShapeNode extends SceneNode {
1133
1133
  return nx * nx + ny * ny <= 1;
1134
1134
  }
1135
1135
  const mesh = this.shapeMesh;
1136
- if (kind === 'polyline' || kind === 'polygon') {
1136
+ if (kind === ElementTypes.POLYLINE || kind === ElementTypes.POLYGON) {
1137
1137
  // 空填充 polyline/polygon(线段工具产物——2 点无网格)按描边命中带
1138
1138
  // (fabric perPixelTargetFind 口径,半径与 LineNode.containsPoint 同源);
1139
1139
  // 有填充仍走网格偶奇
1140
1140
  if (mesh)
1141
1141
  return pointInPolygon(mesh.verts, local.x, local.y);
1142
- return polylineStrokeHit(this.raw.points, local, kind === 'polygon', Math.max((Number(this.raw.strokeWidth) || 1) / 2, 3, hitBand));
1142
+ return polylineStrokeHit(this.raw.points, local, kind === ElementTypes.POLYGON, Math.max((Number(this.raw.strokeWidth) || 1) / 2, 3, hitBand));
1143
1143
  }
1144
1144
  if (!mesh)
1145
1145
  return false;
@@ -1152,7 +1152,7 @@ export class ShapeNode extends SceneNode {
1152
1152
  const local = this.localPoint(x, y);
1153
1153
  const kind = this.shapeKind;
1154
1154
  const r = strokeHitRadius(this, hitBand);
1155
- if (kind === 'ellipse' || kind === 'circle') {
1155
+ if (kind === ElementTypes.ELLIPSE || kind === ElementTypes.CIRCLE) {
1156
1156
  const rx = this.dims.x / 2;
1157
1157
  const ry = this.dims.y / 2;
1158
1158
  if (!(rx > 0) || !(ry > 0))
@@ -1165,9 +1165,9 @@ export class ShapeNode extends SceneNode {
1165
1165
  const g = (local.x * local.x) / (rx * rx) + (local.y * local.y) / (ry * ry) - 1;
1166
1166
  return Math.abs(g) / gl <= r;
1167
1167
  }
1168
- if (kind === 'triangle')
1168
+ if (kind === ElementTypes.TRIANGLE)
1169
1169
  return polylineStrokeHit(trianglePoints(this.raw), local, true, r);
1170
- return polylineStrokeHit(this.raw.points, local, kind === 'polygon', r);
1170
+ return polylineStrokeHit(this.raw.points, local, kind === ElementTypes.POLYGON, r);
1171
1171
  }
1172
1172
  }
1173
1173
  /** fabric Triangle 的顶点合成(_render 逐式:本地系 (w/2,0)→(w,h)→(0,h);
@@ -1510,9 +1510,9 @@ export class LineNode extends SceneNode {
1510
1510
  return true;
1511
1511
  // 装饰命中扩展:类型键小写归一(批次46 勘注——raw 两形态并存)
1512
1512
  const rawType = this.typeKey;
1513
- if (rawType === 'arrow')
1513
+ if (rawType === ElementTypes.ARROW)
1514
1514
  return arrowHeadHit(this.raw, local, p);
1515
- if (rawType === 'dimension')
1515
+ if (rawType === ElementTypes.DIMENSION)
1516
1516
  return dimensionDecorHit(this.raw, local, p, r);
1517
1517
  return false;
1518
1518
  }
@@ -19,6 +19,7 @@
19
19
  */
20
20
  import { getBoundsOfPath, parsePathData } from '../core/pathData';
21
21
  import { rectCornerRadii } from '../core/roundedRect';
22
+ import { ElementTypes, typeKeyOf } from './elementTypes';
22
23
  const num = (value, fallback = 0) => (typeof value === 'number' && Number.isFinite(value) ? value : fallback);
23
24
  /** scale 读位(缺省 1,零值兜 1 防除零/零尺寸) */
24
25
  const scaleOf = (raw) => ({
@@ -71,15 +72,15 @@ export const buildEngineShapePath = (node) => {
71
72
  if (node.isTextType)
72
73
  return undefined;
73
74
  const raw = node.raw;
74
- const type = String(raw.type ?? '').toLowerCase();
75
+ const type = typeKeyOf(raw);
75
76
  const { sx, sy } = scaleOf(raw);
76
- if (type === 'path') {
77
+ if (type === ElementTypes.PATH) {
77
78
  const path = typeof raw.path === 'string' ? raw.path : '';
78
79
  if (!path.trim())
79
80
  return undefined;
80
81
  return { path, pathOffset: declaredOffset(raw) ?? pathBoundsCenter(path) ?? { x: 0, y: 0 } };
81
82
  }
82
- if (type === 'rect' || type === 'fabricrect') {
83
+ if (type === ElementTypes.RECT || type === ElementTypes.FABRICRECT) {
83
84
  const w = node.dims.x * sx;
84
85
  const h = node.dims.y * sy;
85
86
  if (!(w > 0) || !(h > 0))
@@ -91,34 +92,34 @@ export const buildEngineShapePath = (node) => {
91
92
  const path = rx > 0 || ry > 0 ? roundedRectPath(w, h, rx, ry) : `M 0 0 L ${w} 0 L ${w} ${h} L 0 ${h} Z`;
92
93
  return { path, pathOffset: { x: w / 2, y: h / 2 } };
93
94
  }
94
- if (type === 'circle') {
95
+ if (type === ElementTypes.CIRCLE) {
95
96
  const r = num(raw.radius);
96
97
  if (!(r > 0))
97
98
  return undefined;
98
99
  return { path: ellipsePath(r * sx, r * sy), pathOffset: { x: 0, y: 0 } };
99
100
  }
100
- if (type === 'ellipse') {
101
+ if (type === ElementTypes.ELLIPSE) {
101
102
  const rx = (num(raw.rx) || node.dims.x / 2) * sx;
102
103
  const ry = (num(raw.ry) || node.dims.y / 2) * sy;
103
104
  if (!(rx > 0) || !(ry > 0))
104
105
  return undefined;
105
106
  return { path: ellipsePath(rx, ry), pathOffset: { x: 0, y: 0 } };
106
107
  }
107
- if (type === 'triangle') {
108
+ if (type === ElementTypes.TRIANGLE) {
108
109
  const w = node.dims.x * sx;
109
110
  const h = node.dims.y * sy;
110
111
  if (!(w > 0) || !(h > 0))
111
112
  return undefined;
112
113
  return { path: `M ${-w / 2} ${h / 2} L 0 ${-h / 2} L ${w / 2} ${h / 2} Z`, pathOffset: { x: 0, y: 0 } };
113
114
  }
114
- if (type === 'polygon' || type === 'polyline') {
115
+ if (type === ElementTypes.POLYGON || type === ElementTypes.POLYLINE) {
115
116
  const points = Array.isArray(raw.points) ? raw.points : [];
116
117
  if (points.length === 0)
117
118
  return { path: 'M 0 0', pathOffset: { x: 0, y: 0 } };
118
- const path = points.map((p, i) => `${i === 0 ? 'M' : 'L'} ${p.x} ${p.y}`).join(' ') + (type === 'polygon' ? ' Z' : '');
119
+ const path = points.map((p, i) => `${i === 0 ? 'M' : 'L'} ${p.x} ${p.y}`).join(' ') + (type === ElementTypes.POLYGON ? ' Z' : '');
119
120
  return { path, pathOffset: declaredOffset(raw) ?? pointsBoundsCenter(points) ?? { x: 0, y: 0 } };
120
121
  }
121
- if (type === 'line') {
122
+ if (type === ElementTypes.LINE) {
122
123
  const x1 = num(raw.x1);
123
124
  const y1 = num(raw.y1);
124
125
  const x2 = num(raw.x2);
@@ -2,12 +2,82 @@ import { type SceneNode, type SerializedNode } from '../model/scene';
2
2
  import type { GroupMaskTexture } from './GLIsolate';
3
3
  import type { SharedGpuPainters } from './sharedGpuPainters';
4
4
  import type { SceneRendererHost } from './SceneRenderer';
5
- /** raw.clipPath 声明(形状族序列化 + absolutePositioned/inverted);非法声明返回 null */
5
+ /**
6
+ * 平移无关烘焙签名(批次 416):decl JSON + 投影线性分量(a-d)+ 画布尺寸。
7
+ * 投影全阵 tm = dpr×viewport×host×clip 的平移分量(e/f)不入签——纯滚动
8
+ * (vpt/宿主平移)下整屏剪影位图 = 旧位图平移,数学等价可复用。
9
+ */
10
+ export declare const clipMaskBakeSig: (declJSON: string, tm: readonly number[], cw: number, ch: number) => string;
11
+ /**
12
+ * 纯平移差的蒙版复用补偿(批次 416):滚动帧命中平移无关签名时,maskInv
13
+ * 平移列(列主序数组位 6/7)加整数像素 uv 偏移——旧位图按 Δ 平移采样。
14
+ * 取整像素避免纹理插值软化 AA 边缘;残差恒 <1px(相对烘焙原点,不累积),
15
+ * 蒙版边缘本为 1px 级 AA 带不可感。Δ 为零返回原数组(引用恒等——帧内
16
+ * 零开销路径)。符号:采样位置 = 屏幕位 − Δ(M₁(px)=M₀(px−d))→ 平移列
17
+ * 减 Δ/尺寸(y 方向经 maskInv 自带翻转,推导同向)。
18
+ */
19
+ export declare const clipMaskPanShiftInv: (base: readonly number[], dxRaw: number, dyRaw: number, cw: number, ch: number) => readonly number[];
20
+ /**
21
+ * 剪影形状投影 bbox(批次 416 勘注二提纯):dims 中心系四角(±w/2,±h/2)
22
+ * 经全链 tm(view×host×clip,中心系原点=矩阵原点)——与 aCoords+分解矩阵
23
+ * 口径等价且免重复乘 clip 自身矩阵的陷阱;画布物理像素域。
24
+ */
25
+ export declare const clipMaskProjectedBBox: (dims: {
26
+ x: number;
27
+ y: number;
28
+ }, tm: readonly number[]) => {
29
+ minX: number;
30
+ minY: number;
31
+ maxX: number;
32
+ maxY: number;
33
+ } | null;
34
+ /**
35
+ * 剪影形状投影与画布的相交判定(批次 416 勘注):多页分段帧把所有页逐段
36
+ * 全渲——远离视口的页(如第 5 页)的组在懒建造首渲染时就走 mask(),形状
37
+ * 投影在整屏位图外 → 烘出全黑蒙版;平移无关签名使滚到位后也永不重烘 →
38
+ * 组内图片被全黑蒙版裁没(用户实测第 5 页图片消失)。画布外不烘(null=
39
+ * 不裁,画布外本就无帧内容),形状进画布(含部分相交)才首烘。
40
+ */
41
+ export declare const clipMaskShapeOnCanvas: (dims: {
42
+ x: number;
43
+ y: number;
44
+ }, tm: readonly number[], cw: number, ch: number) => boolean;
45
+ /**
46
+ * 烘焙位图域(批次 416 勘注二)= 形状投影 bbox ∪ 画布 的包围盒——部分相交
47
+ * 首烘时形状画布外切片也须入图(勘注一残留缺陷:整屏位图只含画布内切片,
48
+ * 滚动后新进画布的形状部分在图上是黑=被裁,用户实测「图文只露出一点」)。
49
+ * 任何未来平移采样的 p−d 恒落画布域 ⊆ 并集 → 复用完备。位图域原点/尺寸
50
+ * 同时是 maskInv 组装与平移补偿的分母。
51
+ */
52
+ export declare const clipMaskBakeDomain: (bb: {
53
+ minX: number;
54
+ minY: number;
55
+ maxX: number;
56
+ maxY: number;
57
+ }, cw: number, ch: number) => {
58
+ bx0: number;
59
+ by0: number;
60
+ bw: number;
61
+ bh: number;
62
+ };
63
+ /**
64
+ * 烘焙位图的 vUv→位图 uv 映射(列主序 mat3,批次 416 勘注二全式化):
65
+ * 屏幕像素 px=vUv.x×cw / py=(1−vUv.y)×ch(y 翻转),位图坐标=(px−bx0)/bw。
66
+ * 全屏域(bx0=by0=0、bw=cw、bh=ch)退化为勘注前的 [1,0,0,0,-1,0,0,1,1]。
67
+ */
68
+ export declare const clipMaskBakeInv: (dom: {
69
+ bx0: number;
70
+ by0: number;
71
+ bw: number;
72
+ bh: number;
73
+ }, cw: number, ch: number) => readonly number[];
6
74
  export declare const clipDecl: (node: SceneNode) => SerializedNode | null;
7
75
  export declare class ClipMaskPainter {
8
76
  private readonly host;
9
77
  private readonly gpu;
10
- /** clipPath 剪影纹理缓存(P4-3:节点 → {sig, mask}) */
78
+ /** clipPath 剪影纹理缓存(P4-3:节点 → {sig, panX, panY, bw, bh, mask};
79
+ * sig 平移无关(批次 416 滚动复用),panX/panY 为烘焙时投影平移,
80
+ * bw/bh 为位图域尺寸(勘注二:平移补偿的分母) */
11
81
  private clipBakes;
12
82
  constructor(host: SceneRendererHost, gpu: SharedGpuPainters);
13
83
  /** 剪影蒙版纹理与屏幕 uv 摆放(无合法声明/GPU 失败返回 null) */
@@ -14,30 +14,126 @@ import { renderViewportOf } from './renderViewport';
14
14
  import { isGpuClipMaskEnabled } from '../engineFlag';
15
15
  import { buildRoundedRectMesh, rectCornerRadii } from '../core/roundedRect';
16
16
  import { createNode, SHAPE_TYPES, ShapeNode } from '../model/scene';
17
+ import { ElementTypes, typeKeyOf } from '../model/elementTypes';
17
18
  import { traceShapeStrokePath } from './strokeBake';
18
19
  import { createTexture2D } from './textureUpload';
19
- /** clipPath 声明的合法类型(小写归一,批次 98):SHAPE_TYPES ∪ rect 族 */
20
- const SHAPE_CLIP_TYPES = new Set([...SHAPE_TYPES].map((t) => t.toLowerCase()).concat(['rect', 'fabricrect']));
21
- /** raw.clipPath 声明(形状族序列化 + absolutePositioned/inverted);非法声明返回 null */
20
+ /** clipPath 声明的合法类型(typeKey 归一,批次 98):SHAPE_TYPES ∪ rect 族 */
21
+ const SHAPE_CLIP_TYPES = new Set([...SHAPE_TYPES, ElementTypes.RECT, ElementTypes.FABRICRECT]);
22
+ /**
23
+ * 平移无关烘焙签名(批次 416):decl JSON + 投影线性分量(a-d)+ 画布尺寸。
24
+ * 投影全阵 tm = dpr×viewport×host×clip 的平移分量(e/f)不入签——纯滚动
25
+ * (vpt/宿主平移)下整屏剪影位图 = 旧位图平移,数学等价可复用。
26
+ */
27
+ export const clipMaskBakeSig = (declJSON, tm, cw, ch) => [declJSON, tm[0], tm[1], tm[2], tm[3], cw, ch].join(';');
28
+ /**
29
+ * 纯平移差的蒙版复用补偿(批次 416):滚动帧命中平移无关签名时,maskInv
30
+ * 平移列(列主序数组位 6/7)加整数像素 uv 偏移——旧位图按 Δ 平移采样。
31
+ * 取整像素避免纹理插值软化 AA 边缘;残差恒 <1px(相对烘焙原点,不累积),
32
+ * 蒙版边缘本为 1px 级 AA 带不可感。Δ 为零返回原数组(引用恒等——帧内
33
+ * 零开销路径)。符号:采样位置 = 屏幕位 − Δ(M₁(px)=M₀(px−d))→ 平移列
34
+ * 减 Δ/尺寸(y 方向经 maskInv 自带翻转,推导同向)。
35
+ */
36
+ export const clipMaskPanShiftInv = (base, dxRaw, dyRaw, cw, ch) => {
37
+ const dx = Math.round(dxRaw);
38
+ const dy = Math.round(dyRaw);
39
+ if (dx === 0 && dy === 0)
40
+ return base;
41
+ const inv = [...base];
42
+ inv[6] -= dx / cw;
43
+ inv[7] -= dy / ch;
44
+ return inv;
45
+ };
46
+ /**
47
+ * 剪影形状投影 bbox(批次 416 勘注二提纯):dims 中心系四角(±w/2,±h/2)
48
+ * 经全链 tm(view×host×clip,中心系原点=矩阵原点)——与 aCoords+分解矩阵
49
+ * 口径等价且免重复乘 clip 自身矩阵的陷阱;画布物理像素域。
50
+ */
51
+ export const clipMaskProjectedBBox = (dims, tm) => {
52
+ if (!(dims.x > 0) || !(dims.y > 0))
53
+ return null;
54
+ const hw = dims.x / 2;
55
+ const hh = dims.y / 2;
56
+ let minX = Infinity;
57
+ let minY = Infinity;
58
+ let maxX = -Infinity;
59
+ let maxY = -Infinity;
60
+ for (const [cx, cy] of [
61
+ [-hw, -hh],
62
+ [hw, -hh],
63
+ [hw, hh],
64
+ [-hw, hh]
65
+ ]) {
66
+ const x = tm[0] * cx + tm[2] * cy + tm[4];
67
+ const y = tm[1] * cx + tm[3] * cy + tm[5];
68
+ if (minX > x)
69
+ minX = x;
70
+ if (minY > y)
71
+ minY = y;
72
+ if (maxX < x)
73
+ maxX = x;
74
+ if (maxY < y)
75
+ maxY = y;
76
+ }
77
+ return { minX, minY, maxX, maxY };
78
+ };
79
+ /**
80
+ * 剪影形状投影与画布的相交判定(批次 416 勘注):多页分段帧把所有页逐段
81
+ * 全渲——远离视口的页(如第 5 页)的组在懒建造首渲染时就走 mask(),形状
82
+ * 投影在整屏位图外 → 烘出全黑蒙版;平移无关签名使滚到位后也永不重烘 →
83
+ * 组内图片被全黑蒙版裁没(用户实测第 5 页图片消失)。画布外不烘(null=
84
+ * 不裁,画布外本就无帧内容),形状进画布(含部分相交)才首烘。
85
+ */
86
+ export const clipMaskShapeOnCanvas = (dims, tm, cw, ch) => {
87
+ const bb = clipMaskProjectedBBox(dims, tm);
88
+ if (!bb)
89
+ return false;
90
+ return bb.maxX >= 0 && bb.minX <= cw && bb.maxY >= 0 && bb.minY <= ch;
91
+ };
92
+ /**
93
+ * 烘焙位图域(批次 416 勘注二)= 形状投影 bbox ∪ 画布 的包围盒——部分相交
94
+ * 首烘时形状画布外切片也须入图(勘注一残留缺陷:整屏位图只含画布内切片,
95
+ * 滚动后新进画布的形状部分在图上是黑=被裁,用户实测「图文只露出一点」)。
96
+ * 任何未来平移采样的 p−d 恒落画布域 ⊆ 并集 → 复用完备。位图域原点/尺寸
97
+ * 同时是 maskInv 组装与平移补偿的分母。
98
+ */
99
+ export const clipMaskBakeDomain = (bb, cw, ch) => {
100
+ const bx0 = Math.min(bb.minX, 0);
101
+ const by0 = Math.min(bb.minY, 0);
102
+ return { bx0, by0, bw: Math.max(bb.maxX, cw) - bx0, bh: Math.max(bb.maxY, ch) - by0 };
103
+ };
104
+ /**
105
+ * 烘焙位图的 vUv→位图 uv 映射(列主序 mat3,批次 416 勘注二全式化):
106
+ * 屏幕像素 px=vUv.x×cw / py=(1−vUv.y)×ch(y 翻转),位图坐标=(px−bx0)/bw。
107
+ * 全屏域(bx0=by0=0、bw=cw、bh=ch)退化为勘注前的 [1,0,0,0,-1,0,0,1,1]。
108
+ */
109
+ export const clipMaskBakeInv = (dom, cw, ch) => [
110
+ cw / dom.bw,
111
+ 0,
112
+ 0,
113
+ 0,
114
+ -ch / dom.bh,
115
+ 0,
116
+ -dom.bx0 / dom.bw,
117
+ (ch - dom.by0) / dom.bh,
118
+ 1
119
+ ];
22
120
  export const clipDecl = (node) => {
23
121
  const cp = node.raw.clipPath;
24
122
  if (!cp || typeof cp !== 'object' || Array.isArray(cp))
25
123
  return null;
26
- const type = cp.type;
27
- if (typeof type !== 'string')
28
- return null;
29
124
  // 形状族 + rect(SOLID 族——traceShapeStrokePath 的 rect 分支同样覆盖;
30
- // 曾漏 rect 致 rect 裁剪静默失效)。大小写不敏感:clipPath 子节点 type 恒走
125
+ // 曾漏 rect 致 rect 裁剪静默失效)。typeKey 归一:clipPath 子节点 type 恒走
31
126
  // toObject 注册名('Rect'/'FabricRect' 大写档与 trace 的归一口径一致,批次 98)
32
- const lower = type.toLowerCase();
33
- if (!SHAPE_CLIP_TYPES.has(lower))
127
+ if (!SHAPE_CLIP_TYPES.has(typeKeyOf(cp)))
34
128
  return null;
35
129
  return cp;
36
130
  };
37
131
  export class ClipMaskPainter {
38
132
  host;
39
133
  gpu;
40
- /** clipPath 剪影纹理缓存(P4-3:节点 → {sig, mask}) */
134
+ /** clipPath 剪影纹理缓存(P4-3:节点 → {sig, panX, panY, bw, bh, mask};
135
+ * sig 平移无关(批次 416 滚动复用),panX/panY 为烘焙时投影平移,
136
+ * bw/bh 为位图域尺寸(勘注二:平移补偿的分母) */
41
137
  clipBakes = new WeakMap();
42
138
  constructor(host, gpu) {
43
139
  this.host = host;
@@ -75,23 +171,41 @@ export class ClipMaskPainter {
75
171
  }
76
172
  return null;
77
173
  }
78
- const sig = [JSON.stringify({ ...decl, objects: undefined }), clipWorld.join(','), viewport.join(','), cw, ch].join(';');
174
+ // 批次 416:签名平移无关化——旧签 [decl, clipWorld, viewport, 尺寸] 含
175
+ // 平移分量,纯滚动(vpt/宿主 pan 变化)每帧失效:整屏 canvas 白填 +
176
+ // texImage2D 重传/可见组/帧是真机滚动卡顿主项(hook 实测 399 次/3s)。
177
+ // 命中签名时按平移差整数像素补偿 maskInv 复用位图(数学等价);宿主
178
+ // 旋转/缩放/视口缩放仍走线性分量变化 → 重烘
179
+ const declJSON = JSON.stringify({ ...decl, objects: undefined });
180
+ const view = multiply([this.host.dpr, 0, 0, this.host.dpr, 0, 0], viewport);
181
+ const tm = multiply(view, clipWorld);
182
+ // 画布外不烘(批次 416 勘注):分段帧全页渲染使远页组在画布外首烘——
183
+ // 全黑蒙版 + 平移复用永不重烘 = 图片被裁没;进画布才首烘
184
+ if (!clipMaskShapeOnCanvas(clipNode.dims, tm, cw, ch))
185
+ return null;
186
+ const sig = clipMaskBakeSig(declJSON, tm, cw, ch);
79
187
  let bake = this.clipBakes.get(hostNode);
80
188
  if (bake && bake.sig !== sig) {
81
189
  this.host.gl.deleteTexture(bake.mask.tex);
82
190
  bake = undefined;
83
191
  }
84
192
  if (!bake) {
193
+ // 位图域 = 形状 bbox ∪ 画布(勘注二):部分相交首烘把形状画布外切片
194
+ // 一并烘焙——纯平移复用完备(p−d ⊆ 画布域 ⊆ 位图域)
195
+ const bb = clipMaskProjectedBBox(clipNode.dims, tm);
196
+ if (!bb)
197
+ return null;
198
+ const dom = clipMaskBakeDomain(bb, cw, ch);
199
+ if (!(dom.bw > 0) || !(dom.bh > 0) || dom.bw > 8192 || dom.bh > 8192)
200
+ return null;
85
201
  const canvas = document.createElement('canvas');
86
- canvas.width = cw;
87
- canvas.height = ch;
202
+ canvas.width = Math.ceil(dom.bw);
203
+ canvas.height = Math.ceil(dom.bh);
88
204
  const ctx = canvas.getContext('2d');
89
205
  if (!ctx)
90
206
  return null;
91
- // 场景矩阵 → 像素(y 下)× dpr;dpr 缩放保证剪影与内容同分辨率
92
- const view = multiply([this.host.dpr, 0, 0, this.host.dpr, 0, 0], viewport);
93
- const tm = multiply(view, clipWorld);
94
- ctx.setTransform(tm[0], tm[1], tm[2], tm[3], tm[4], tm[5]);
207
+ // 场景矩阵 → 位图像素(y 下)× dpr,平移分量平移到位图域原点
208
+ ctx.setTransform(tm[0], tm[1], tm[2], tm[3], tm[4] - dom.bx0, tm[5] - dom.by0);
95
209
  ctx.fillStyle = '#ffffff';
96
210
  if (!traceShapeStrokePath(ctx, clipNode))
97
211
  return null;
@@ -101,20 +215,27 @@ export class ClipMaskPainter {
101
215
  return null;
102
216
  bake = {
103
217
  sig,
218
+ panX: tm[4],
219
+ panY: tm[5],
220
+ bw: dom.bw,
221
+ bh: dom.bh,
104
222
  mask: {
105
223
  tex,
106
- // 全屏纹理:vUv → 蒙版 uv 的 y 翻转(canvas 上传纹理 v=0 在顶行、屏幕
107
- // vUv y 上翻)。列主序打包:平移常数须落末列——旧值 [1,0,0, 0,-1,1,
108
- // 0,0,1] 把 +1 写进第二列,成剪切阵:muv.y = −vUv.y 恒负 → 全域出界
109
- // → ma=uCovers=0——非反相宿主全灭、inverted 全显(不裁),批次 99 勘误
110
- maskInv: [1, 0, 0, 0, -1, 0, 0, 1, 1],
224
+ // vUv → 位图域 uv(勘注二全式,含域原点缩放与 y 翻转;全屏域退化
225
+ // 为勘注前的 [1,0,0,0,-1,0,0,1,1])。列主序:平移常数落末列
226
+ maskInv: clipMaskBakeInv(dom, cw, ch),
111
227
  coversHost: false,
112
228
  invert: decl.inverted === true
113
229
  }
114
230
  };
115
231
  this.clipBakes.set(hostNode, bake);
116
232
  }
117
- return bake.mask;
233
+ // 滚动复用(批次 416):纯平移差 → 整数像素 uv 补偿(取整在
234
+ // clipMaskPanShiftInv 内);Δ=0 恒等引用零开销
235
+ const inv = clipMaskPanShiftInv(bake.mask.maskInv, tm[4] - bake.panX, tm[5] - bake.panY, bake.bw, bake.bh);
236
+ if (inv === bake.mask.maskInv)
237
+ return bake.mask;
238
+ return { ...bake.mask, maskInv: inv };
118
239
  }
119
240
  /** 失效(context lost):烘焙整删——clipBakes 是几何蒙版剪影不含文本,字体迟到不动 */
120
241
  invalidate() {
@@ -1,4 +1,5 @@
1
1
  import { isStrokeSdfDashEnabled, isStrokeSdfLineDecorationEnabled } from '../engineFlag';
2
+ import { ElementTypes, typeKeyOf } from '../model/elementTypes';
2
3
  import { segHash } from './segmentTable';
3
4
  /** 描边码位段(与 strokeSdf.ts/shaders.ts 解码一致) */
4
5
  const KIND_LINE = 2;
@@ -105,8 +106,8 @@ const readPoints = (raw) => {
105
106
  * 烘焙的混血形态不做,383 原则)。几何源=raw.x1..y2(对象中心系)。
106
107
  */
107
108
  export const lineDecorationPieces = (raw, decl, matrix, zoom, dpr) => {
108
- const type = typeof raw.type === 'string' ? raw.type.toLowerCase() : '';
109
- if (type !== 'arrow' && type !== 'dimension')
109
+ const type = typeKeyOf(raw);
110
+ if (type !== ElementTypes.ARROW && type !== ElementTypes.DIMENSION)
110
111
  return null;
111
112
  if (!isStrokeSdfLineDecorationEnabled())
112
113
  return null;
@@ -120,7 +121,7 @@ export const lineDecorationPieces = (raw, decl, matrix, zoom, dpr) => {
120
121
  const strokeWidth = decl.width;
121
122
  const cos = (p.x2 - p.x1) / Math.hypot(p.x2 - p.x1, p.y2 - p.y1);
122
123
  const sin = (p.y2 - p.y1) / Math.hypot(p.x2 - p.x1, p.y2 - p.y1);
123
- if (type === 'arrow') {
124
+ if (type === ElementTypes.ARROW) {
124
125
  const arrowW = Number(raw.arrowWidth) || 15;
125
126
  const arrowH = Number(raw.arrowHeight) || 22.5;
126
127
  const arrowType = raw.arrowType === 'start' || raw.arrowType === 'both' ? raw.arrowType : 'end';
@@ -27,6 +27,7 @@
27
27
  */
28
28
  import { EngineDocument } from '../model/document';
29
29
  import { WORKSPACE_IDS, WORKSPACE_ID } from '../model/scene';
30
+ import { ElementTypes, typeKeyOf } from '../model/elementTypes';
30
31
  import { invert, multiply, sceneToClipMatrix, transformPoint } from '../core/mat2d';
31
32
  import { renderSceneNodes } from './framePipeline';
32
33
  import { applyScissor, clearScissor, pageClipRect } from './screenClip';
@@ -291,7 +292,7 @@ function workspaceRectFromRaw(objects) {
291
292
  const id = String(raw.id ?? '');
292
293
  if (id !== WORKSPACE_ID && WORKSPACE_IDS.has(id))
293
294
  continue;
294
- if (String(raw.type ?? '').toLowerCase() === 'referenceline')
295
+ if (typeKeyOf(raw) === ElementTypes.REFERENCELINE)
295
296
  continue;
296
297
  const left = Number(raw.left ?? 0);
297
298
  const top = Number(raw.top ?? 0);
@@ -28,6 +28,7 @@ import { parseStrokeDecl } from '../core/stroke';
28
28
  import { getBoundsOfPath, parsePathData } from '../core/pathData';
29
29
  import { multiply } from '../core/mat2d';
30
30
  import { rectCornerRadii, traceRoundedRectPath } from '../core/roundedRect';
31
+ import { ElementTypes, typeKeyOf } from '../model/elementTypes';
31
32
  /** 描边在对象线性变换下的包围盒半扩展(斜接尖峰可达 width×miterLimit/2) */
32
33
  const strokeMargin = (decl, node) => {
33
34
  const m = node.matrix;
@@ -75,9 +76,9 @@ export const strokeSnapOrigin = (m, zoom, dpr, vpt, sceneW, sceneH) => {
75
76
  */
76
77
  export const traceShapeStrokePath = (ctx, node) => {
77
78
  const raw = node.raw;
78
- const type = typeof raw.type === 'string' ? raw.type.toLowerCase() : '';
79
+ const type = typeKeyOf(raw);
79
80
  ctx.beginPath();
80
- if (type === 'path') {
81
+ if (type === ElementTypes.PATH) {
81
82
  const commands = parsePathData(raw.path);
82
83
  if (!commands)
83
84
  return false;
@@ -107,7 +108,7 @@ export const traceShapeStrokePath = (ctx, node) => {
107
108
  }
108
109
  return true;
109
110
  }
110
- if (type === 'polygon' || type === 'polyline') {
111
+ if (type === ElementTypes.POLYGON || type === ElementTypes.POLYLINE) {
111
112
  const points = Array.isArray(raw.points) ? raw.points : [];
112
113
  if (points.length < 2)
113
114
  return false;
@@ -132,11 +133,11 @@ export const traceShapeStrokePath = (ctx, node) => {
132
133
  ctx.moveTo(points[0].x - cx, points[0].y - cy);
133
134
  for (let i = 0; i < points.length; i++)
134
135
  ctx.lineTo(points[i].x - cx, points[i].y - cy);
135
- if (raw.type === 'polygon')
136
+ if (type === ElementTypes.POLYGON)
136
137
  ctx.closePath();
137
138
  return true;
138
139
  }
139
- if (type === 'triangle') {
140
+ if (type === ElementTypes.TRIANGLE) {
140
141
  // fabric Triangle:points 不持久化,几何由 width/height 合成(本地系
141
142
  // (w/2,0)→(w,h)→(0,h),scene.trianglePoints/svgExport 同源)——bbox 中心
142
143
  // (w/2,h/2) 归一到中心原点(与填充网格 buildPolygonMesh 同口径)
@@ -150,15 +151,15 @@ export const traceShapeStrokePath = (ctx, node) => {
150
151
  ctx.closePath();
151
152
  return true;
152
153
  }
153
- if (type === 'ellipse' || type === 'circle') {
154
- const rx = (type === 'circle' ? Number(raw.radius) : Number(raw.rx)) || 0;
155
- const ry = (type === 'circle' ? Number(raw.radius) : Number(raw.ry)) || 0;
154
+ if (type === ElementTypes.ELLIPSE || type === ElementTypes.CIRCLE) {
155
+ const rx = (type === ElementTypes.CIRCLE ? Number(raw.radius) : Number(raw.rx)) || 0;
156
+ const ry = (type === ElementTypes.CIRCLE ? Number(raw.radius) : Number(raw.ry)) || 0;
156
157
  if (!(rx > 0) || !(ry > 0))
157
158
  return false;
158
159
  ctx.ellipse(0, 0, rx, ry, 0, 0, Math.PI * 2);
159
160
  return true;
160
161
  }
161
- if (type === 'line' || type === 'referenceline') {
162
+ if (type === ElementTypes.LINE || type === ElementTypes.REFERENCELINE) {
162
163
  // 线族:x1..y2 即中心相对坐标(calcLinePoints 恒等映射),开放路径
163
164
  const x1 = Number(raw.x1);
164
165
  const y1 = Number(raw.y1);
@@ -170,7 +171,7 @@ export const traceShapeStrokePath = (ctx, node) => {
170
171
  ctx.lineTo(x2, y2);
171
172
  return true;
172
173
  }
173
- if (type === 'rect' || type === 'fabricrect') {
174
+ if (type === ElementTypes.RECT || type === ElementTypes.FABRICRECT) {
174
175
  const w = node.dims.x;
175
176
  const h = node.dims.y;
176
177
  if (!(w > 0) || !(h > 0))
@@ -197,8 +198,8 @@ export const bakeNodeStroke = (node, view) => {
197
198
  const decl = parseStrokeDecl(node.raw);
198
199
  if (!decl)
199
200
  return null;
200
- const type = typeof node.raw.type === 'string' ? node.raw.type.toLowerCase() : '';
201
- if (type === 'arrow' || type === 'dimension') {
201
+ const type = typeKeyOf(node.raw);
202
+ if (type === ElementTypes.ARROW || type === ElementTypes.DIMENSION) {
202
203
  // 线族装饰同主路径模型设备分辨率烘焙(zoom×dpr 光栅 + 窗口左上角设备像素
203
204
  // 吸附)。首版维持 1× 的判据(2026-09-23「杆宽 ≥2px/文本不敏感」)失准:
204
205
  // 箭头三角头两条斜边长,dpr 1.25~2 屏上 GL 双线性上采样把边缘抹成 3-4px
@@ -334,8 +335,8 @@ const bakeLineDecoration = (node, decl, view) => {
334
335
  const raw = node.raw;
335
336
  // 类型键小写归一(批次46 勘注:raw 两形态并存——store 装载小写 / fabric
336
337
  // 构造器 toObject 大写,外层分支已归一,内层箭头/标注分派同口径)
337
- const rawType = typeof raw.type === 'string' ? raw.type.toLowerCase() : '';
338
- const isArrow = rawType === 'arrow';
338
+ const rawType = typeKeyOf(raw);
339
+ const isArrow = rawType === ElementTypes.ARROW;
339
340
  const strokeWidth = Number(raw.strokeWidth) || 1;
340
341
  const stroke = typeof raw.stroke === 'string' ? raw.stroke : isArrow ? '#000000' : '#000000';
341
342
  const dash = Array.isArray(raw.strokeDashArray) ? raw.strokeDashArray : null;
@@ -1,5 +1,6 @@
1
1
  import { isStrokeSdfDashEnabled, isStrokeSdfPolygonEnabled } from '../engineFlag';
2
2
  import { rectCornerRadii } from '../core/roundedRect';
3
+ import { ElementTypes, typeKeyOf } from '../model/elementTypes';
3
4
  import { MAX_SEG_BATCH, segHash } from './segmentTable';
4
5
  import { buildMiterOutline } from './strokeMiterOutline';
5
6
  /** 描边码位段:kind(0-2) | cap(3-5) | penUniform(6)——与 strokeCoverage 解码一致 */
@@ -90,17 +91,17 @@ export const strokeSdfParams = (node, decl, zoom, dpr) => {
90
91
  if (decl.alignment !== 'center')
91
92
  return null;
92
93
  const raw = node.raw;
93
- const type = typeof raw.type === 'string' ? raw.type.toLowerCase() : '';
94
+ const type = typeKeyOf(raw);
94
95
  const dims = node.dims;
95
96
  // rect/ellipse 须正尺寸;line 的 bbox 允许单轴为零(水平/垂直线最常见形态,
96
97
  // margin 使 quad 两轴恒正)
97
- if (type !== 'line' && (!(dims.x > 0) || !(dims.y > 0)))
98
+ if (type !== ElementTypes.LINE && (!(dims.x > 0) || !(dims.y > 0)))
98
99
  return null;
99
- const kindSel = type === 'line'
100
+ const kindSel = type === ElementTypes.LINE
100
101
  ? STROKE_KIND_LINE
101
- : type === 'ellipse' || type === 'circle'
102
+ : type === ElementTypes.ELLIPSE || type === ElementTypes.CIRCLE
102
103
  ? STROKE_KIND_ELLIPSE
103
- : type === 'polygon' || type === 'polyline' || type === 'triangle'
104
+ : type === ElementTypes.POLYGON || type === ElementTypes.POLYLINE || type === ElementTypes.TRIANGLE
104
105
  ? STROKE_KIND_SEGMENT
105
106
  : STROKE_KIND_RECT;
106
107
  const halfW = decl.width / 2;
@@ -112,7 +113,7 @@ export const strokeSdfParams = (node, decl, zoom, dpr) => {
112
113
  let marginY = halfW;
113
114
  /** kind=4 段表模式位(0=capsule/round、1=轮廓填充/miter);其余 kind 恒 0 */
114
115
  let modeSlot = 0;
115
- if (type === 'rect' || type === 'fabricrect') {
116
+ if (type === ElementTypes.RECT || type === ElementTypes.FABRICRECT) {
116
117
  // 圆角与填充 quad 同源归一(rectCornerRadii:FabricRect 视觉 radius 反算/
117
118
  // 单写 rx 提升 ry/钳半宽高)——角语义与批次 98 填充角天然同口径
118
119
  const r = rectCornerRadii(raw, dims.x, dims.y);
@@ -129,7 +130,7 @@ export const strokeSdfParams = (node, decl, zoom, dpr) => {
129
130
  return null;
130
131
  shape = [rx, ry, dims.x / 2, dims.y / 2];
131
132
  }
132
- else if (type === 'line') {
133
+ else if (type === ElementTypes.LINE) {
133
134
  const x1 = Number(raw.x1);
134
135
  const y1 = Number(raw.y1);
135
136
  const x2 = Number(raw.x2);
@@ -140,13 +141,13 @@ export const strokeSdfParams = (node, decl, zoom, dpr) => {
140
141
  return null;
141
142
  shape = [x1, y1, x2, y2];
142
143
  }
143
- else if (type === 'ellipse' || type === 'circle') {
144
+ else if (type === ElementTypes.ELLIPSE || type === ElementTypes.CIRCLE) {
144
145
  // 椭圆 dash:弧长无初等解析式(需椭圆积分近似)——回落(蓝图独立下刀)
145
146
  if (dash)
146
147
  return null;
147
148
  shape = [0, 0, dims.x / 2, dims.y / 2];
148
149
  }
149
- else if (type === 'polygon' || type === 'polyline' || type === 'triangle') {
150
+ else if (type === ElementTypes.POLYGON || type === ElementTypes.POLYLINE || type === ElementTypes.TRIANGLE) {
150
151
  // 方向三第二刀两放行面:round=capsule 并(批次 383)/ miter=双偏移轮廓
151
152
  // winding 填充(批次 385);bevel 与超限顶点回落(枚举见文件头注)
152
153
  if (!isStrokeSdfPolygonEnabled())
@@ -155,9 +156,9 @@ export const strokeSdfParams = (node, decl, zoom, dpr) => {
155
156
  return null;
156
157
  if (decl.uniform)
157
158
  return null;
158
- const closed = type !== 'polyline';
159
+ const closed = type !== ElementTypes.POLYLINE;
159
160
  let src;
160
- if (type === 'triangle') {
161
+ if (type === ElementTypes.TRIANGLE) {
161
162
  // fabric Triangle:points 不持久化,几何由 w/h 合成(strokeBake/
162
163
  // buildPolygonMesh(trianglePoints) 同源口径),直接给中心系三点
163
164
  const w = dims.x;
@@ -19,17 +19,19 @@
19
19
  * 边界扫描 therefore 含特效墨(与 fabric 逐式一致——它也扫 super._render 产物)。
20
20
  */
21
21
  import { drawParagraphPrefix, fontDeclaration, resolveStrokeDecl, charJitterY } from '../model/textLayout';
22
+ import { ElementTypes, typeKeyOf } from '../model/elementTypes';
22
23
  import { bakePsdSolidFill, bakePsdStrokes, buildTextEffectSource } from './imageEffects';
23
24
  import { drawVerticalGlyph, glyphStyleAt, verticalGlyphOps } from './verticalText';
24
25
  export const warpTextKind = (raw) => {
25
26
  const s = Number(raw.warpStrength) || 0;
26
27
  if (!s)
27
28
  return null;
28
- if (raw.type === 'ArchText')
29
+ const t = typeKeyOf(raw);
30
+ if (t === ElementTypes.ARCHTEXT)
29
31
  return 'arch';
30
- if (raw.type === 'WaistText')
32
+ if (t === ElementTypes.WAISTTEXT)
31
33
  return 'waist';
32
- if (raw.type === 'FlagText')
34
+ if (t === ElementTypes.FLAGTEXT)
33
35
  return 'flag';
34
36
  return null;
35
37
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yft-design/engine",
3
- "version": "0.0.16",
3
+ "version": "0.0.17",
4
4
  "description": "yft-design 的 WebGL2 画布引擎:接受 fabric toObject 格式 JSON,输出 GL 画布 / 位图(任意倍率 FBO 读回)/ SVG(纯数据序列化器)",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,6 +33,7 @@
33
33
  "warpvas": "^1.0.4"
34
34
  },
35
35
  "devDependencies": {
36
+ "@types/node": "^22.19.17",
36
37
  "@types/rbush": "^4.0.0",
37
38
  "jsdom": "^29.1.1",
38
39
  "typescript": "^6.0.3",