@yft-design/engine 0.0.3 → 0.0.4

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.
@@ -16,9 +16,10 @@
16
16
  * 贝塞尔的最大偏差 <0.03% r,MSAA 下不可分辨)。
17
17
  */
18
18
  /** fabric Rect._render 的圆角贝塞尔常数(1 − 4/3·(√2−1) 的工程截断值) */
19
+ import { ElementTypes, typeKeyOf } from '../model/elementTypes';
19
20
  const K_RECT = 1 - 0.5522847498;
20
- /** FabricRect 族(应用类注册名双档):radius 视觉系为圆角源 */
21
- const RADIUS_SOURCED_TYPES = new Set(['FabricRect', 'fabricrect']);
21
+ /** FabricRect 族(应用类注册名双档,小写键口径坍缩):radius 视觉系为圆角源 */
22
+ const RADIUS_SOURCED_TYPES = new Set([ElementTypes.FABRICRECT]);
22
23
  const numOr = (v, fallback) => (typeof v === 'number' && Number.isFinite(v) ? v : fallback);
23
24
  /**
24
25
  * FabricRect 族 radius → 本地 rx/ry 反算(fabric render 同式)。radius 非正
@@ -36,7 +37,7 @@ export const deriveFabricRectRadii = (radius, scaleX, scaleY) => {
36
37
  * 一致时以 radius 为准(引擎渲染消费位同源,raw 归一只为序列化往返对齐)。
37
38
  */
38
39
  export const normalizeFabricRectRadii = (raw) => {
39
- if (typeof raw.type !== 'string' || !RADIUS_SOURCED_TYPES.has(raw.type))
40
+ if (!RADIUS_SOURCED_TYPES.has(typeKeyOf(raw)))
40
41
  return;
41
42
  const radii = deriveFabricRectRadii(raw.radius, raw.scaleX, raw.scaleY);
42
43
  if (radii) {
@@ -50,7 +51,7 @@ export const normalizeFabricRectRadii = (raw) => {
50
51
  * rx/ry 注入 props 一并落 raw。返回是否注入。
51
52
  */
52
53
  export const syncFabricRectRadiusProps = (raw, props) => {
53
- if (typeof raw.type !== 'string' || !RADIUS_SOURCED_TYPES.has(raw.type))
54
+ if (!RADIUS_SOURCED_TYPES.has(typeKeyOf(raw)))
54
55
  return false;
55
56
  const radiusTouched = 'radius' in props;
56
57
  const scaleTouched = 'scaleX' in props || 'scaleY' in props;
@@ -72,7 +73,7 @@ export const syncFabricRectRadiusProps = (raw, props) => {
72
73
  export const rectCornerRadii = (raw, width, height) => {
73
74
  if (!(width > 0) || !(height > 0))
74
75
  return null;
75
- const radii = typeof raw.type === 'string' && RADIUS_SOURCED_TYPES.has(raw.type) ? deriveFabricRectRadii(raw.radius, raw.scaleX, raw.scaleY) : null;
76
+ const radii = RADIUS_SOURCED_TYPES.has(typeKeyOf(raw)) ? deriveFabricRectRadii(raw.radius, raw.scaleX, raw.scaleY) : null;
76
77
  const rx0 = radii ? radii.rx : numOr(raw.rx, 0);
77
78
  let ry0 = radii ? radii.ry : numOr(raw.ry, 0);
78
79
  // fabric Rect._initRxRy 同构:单写 rx 提升 ry=rx(手写/旧档数据常见——
@@ -8,6 +8,7 @@
8
8
  * P3-5b 已做);paintFirst 缺省 'fill'(描边盖填充)。
9
9
  */
10
10
  import { parseColor } from './color';
11
+ import { ElementTypes, typeKeyOf } from '../model/elementTypes';
11
12
  const JOINS = new Set(['miter', 'round', 'bevel']);
12
13
  const CAPS = new Set(['butt', 'round', 'square']);
13
14
  /** raw 的 stroke 字段 → 声明;无描边(宽 0/无色)返回 null */
@@ -32,8 +33,8 @@ export const parseStrokeDecl = (raw) => {
32
33
  paintFirst: raw.paintFirst === 'stroke' ? 'stroke' : 'fill',
33
34
  alignment: raw.strokeAlignment === 'inside' || raw.strokeAlignment === 'outside' ? raw.strokeAlignment : 'center',
34
35
  // 应用语义:FabricPath 构造器无条件 this.strokeUniform = true(序列化值也被
35
- // 覆盖)——Path 节点强制 uniform,对齐 main
36
- uniform: raw.strokeUniform === true || raw.type === 'Path'
36
+ // 覆盖)——Path 节点强制 uniform,对齐 main;小写键口径承接历史 'path' 模板
37
+ uniform: raw.strokeUniform === true || typeKeyOf(raw) === ElementTypes.PATH
37
38
  };
38
39
  };
39
40
  /** 描边声明缓存键(烘焙纹理复用) */
@@ -41,29 +41,26 @@ import { parsePathData } from '../core/pathData';
41
41
  import { computeTableLayout } from '../model/tableLayout';
42
42
  import { parsePatternDecl, patternSpaceMatrix } from '../core/pattern';
43
43
  import { arcTextKind, computeArcTextLayout } from '../model/arcLayout';
44
- import { imageCropRect, IMAGE_LIKE_TYPES, textBitmapFillAlpha, WORKSPACE_IDS } from '../model/scene';
44
+ import { imageCropRect, textBitmapFillAlpha, WORKSPACE_IDS } from '../model/scene';
45
+ import { ElementTypes, typeKeyOf, IMAGE_LIKE_TYPES, TEXT_TYPES, SOLID_TYPES, LINE_TYPES, MASK_TYPES } from '../model/elementTypes';
45
46
  import { charJitterY, layoutTextbox, verticalAnchorShiftX, verticalAnchorShiftY, verticalCharClass, verticalRenderAdvance } from '../model/textLayout';
46
47
  import { planTextHighlight } from '../render/textHighlight';
47
- // ---- 类型集(与 model/scene 的集合对齐的序列化侧子集 + 小写历史口径兜底) ----
48
- const SOLID_TYPES = new Set(['rect', 'Rect', 'fabricrect']);
49
- const ROUND_TYPES = new Set(['ellipse', 'Ellipse', 'circle', 'Circle']);
50
- const TRIANGLE_TYPES = new Set(['triangle', 'Triangle']);
51
- const PATH_TYPES = new Set(['Path', 'path']);
52
- const POLYGON_TYPES = new Set(['polygon', 'Polygon']);
53
- const POLYLINE_TYPES = new Set(['polyline', 'Polyline']);
54
- /** 线段族:纯线段(emitNode 的 dims 兜底同覆盖 arrow/Dimension 两形态) */
55
- const LINE_TYPES = new Set(['Line', 'line', 'ReferenceLine', 'arrow', 'Arrow', 'dimension', 'Dimension']);
56
- /** 线族装饰(arrow/Dimension——端头装饰走 emitLineDecoration 专用 emitter,几何与渲染侧 bakeLineDecoration 同构) */
57
- const ARROW_TYPES = new Set(['arrow', 'Arrow']);
58
- const DIMENSION_TYPES = new Set(['dimension', 'Dimension']);
59
- const GROUP_TYPES = new Set(['group', 'Group', 'Puzzle', 'puzzle']);
60
- /** 序列化侧图片族 = scene IMAGE_LIKE_TYPES + GIF(SVG 以 <image href> 引用——
48
+ // ---- 类型集(小写键口径,批次 360:家族集合复用 model/elementTypes,细分
49
+ // 子集本地小写化;比较位的 type 一律 typeKeyOf(raw) 派生,双形态就地坍缩) ----
50
+ const ROUND_TYPES = new Set([ElementTypes.ELLIPSE, ElementTypes.CIRCLE]);
51
+ const TRIANGLE_TYPES = new Set([ElementTypes.TRIANGLE]);
52
+ const POLYGON_TYPES = new Set([ElementTypes.POLYGON]);
53
+ const POLYLINE_TYPES = new Set([ElementTypes.POLYLINE]);
54
+ /** 线族装饰(arrow/dimension——端头装饰走 emitLineDecoration 专用 emitter,几何与渲染侧 bakeLineDecoration 同构) */
55
+ const ARROW_TYPES = new Set([ElementTypes.ARROW]);
56
+ const DIMENSION_TYPES = new Set([ElementTypes.DIMENSION]);
57
+ const GROUP_TYPES = new Set([ElementTypes.GROUP, ElementTypes.PUZZLE]);
58
+ /** 序列化侧图片族 = IMAGE_LIKE_TYPES + GIF(SVG 以 <image href> 引用——
61
59
  * 动图在支持的查看器播放、静态查看器显首帧;不动 scene 共享集避免
62
60
  * AnimatedNode.isImageType 语义牵连。Video 不承接——SVG 规范无视频引用,须
63
61
  * 帧位图化(余量登记) */
64
- const SVG_IMAGE_TYPES = new Set([...IMAGE_LIKE_TYPES, 'GIF', 'gif']);
65
- const TABLE_TYPES = new Set(['Table', 'table']);
66
- const MASK_TYPES = new Set(['Mask', 'mask']);
62
+ const SVG_IMAGE_TYPES = new Set([...IMAGE_LIKE_TYPES, ElementTypes.GIF]);
63
+ const TABLE_TYPES = new Set([ElementTypes.TABLE]);
67
64
  /** gco → SVG mix-blend-mode 直通白名单(同值域;fabric toSVG 时代同样以平铺/
68
65
  * 混合近似承接);白名单外(source-atop 等合成态)继续 skip */
69
66
  const BLEND_MODES = new Set([
@@ -83,21 +80,22 @@ const BLEND_MODES = new Set([
83
80
  'color',
84
81
  'luminosity'
85
82
  ]);
86
- /** 常规文本族(含 ScrollText 静态基态承接——滚动循环视口截断是动画态,静态导出
87
- * 出整行基串为登记近似;ArcText/CircleText 进 emitText 后由 arcTextKind 分派
88
- * 弧形专用 emitter;ArchText/WaistText/FlagText 由 warp 分派变形 emitter) */
89
- const TEXT_TYPES = new Set(['textbox', 'Textbox', 'itext', 'IText', 'i-text', 'text', 'Text', 'ScrollText', 'scrollText', 'ArcText', 'CircleText', 'ArchText', 'WaistText', 'FlagText', 'TextImage']);
83
+ /** 常规文本族:词表本体复用 elementTypes 的 TEXT_TYPES(含 ScrollText 静态基态
84
+ * 承接、'i-text' 旧模板兜底;ArcText/CircleText 进 emitText 后由 arcTextKind
85
+ * 分派弧形专用 emitter;ArchText/WaistText/FlagText 由 warp 分派变形 emitter)。
86
+ * 序列化侧与场景侧同源,防本地副本成员漂移 */
90
87
  /** 变形族判别(render/warpText.warpTextKind 同式——export 不引 render 域,内联):
91
88
  * warpStrength=0 的变形族是普通文本(走常规快照路径) */
92
89
  const warpKindOf = (raw) => {
93
90
  const s = Number(raw.warpStrength) || 0;
94
91
  if (!s)
95
92
  return null;
96
- if (raw.type === 'ArchText')
93
+ const t = typeKeyOf(raw);
94
+ if (t === ElementTypes.ARCHTEXT)
97
95
  return 'arch';
98
- if (raw.type === 'WaistText')
96
+ if (t === ElementTypes.WAISTTEXT)
99
97
  return 'waist';
100
- if (raw.type === 'FlagText')
98
+ if (t === ElementTypes.FLAGTEXT)
101
99
  return 'flag';
102
100
  return null;
103
101
  };
@@ -192,7 +190,7 @@ const commandsToPathD = (commands) => commands
192
190
  .join(' ')}`)
193
191
  .join(' ');
194
192
  const shapeGeometry = (raw, width, height) => {
195
- const type = raw.type;
193
+ const type = typeKeyOf(raw);
196
194
  if (SOLID_TYPES.has(type)) {
197
195
  const rx = Math.min(num(raw, 'rx', 0), width / 2);
198
196
  const ry = Math.min(num(raw, 'ry', 0), height / 2);
@@ -212,7 +210,7 @@ const shapeGeometry = (raw, width, height) => {
212
210
  internalTransform: null
213
211
  };
214
212
  }
215
- if (PATH_TYPES.has(type)) {
213
+ if (type === ElementTypes.PATH) {
216
214
  // 双形态:SVG 串 / fabric toObject 的指令数组(默认模板实测形态)——parsePathData 归一
217
215
  const commands = parsePathData(raw.path);
218
216
  if (!commands)
@@ -1349,7 +1347,7 @@ export class SvgExporter {
1349
1347
  return layoutTextbox(text, baseTextStyle(raw), {
1350
1348
  measure: this.layoutMeasure,
1351
1349
  // boxWidth 判定与 TextNode.textLayout 同式(弧形/竖排非 textbox 盒)
1352
- boxWidth: raw.type === 'textbox' || raw.type === 'Textbox' ? raw.width ?? 0 : null,
1350
+ boxWidth: typeKeyOf(raw) === ElementTypes.TEXTBOX ? raw.width ?? 0 : null,
1353
1351
  styles: stylesArrayToMap(text, raw.styles),
1354
1352
  splitByGrapheme: raw.splitByGrapheme === true,
1355
1353
  vertical,
@@ -1442,7 +1440,7 @@ export class SvgExporter {
1442
1440
  }
1443
1441
  /** 单对象内容序列化(不含外层 <g>——由调用方包矩阵/透明度);null = 不支持(已计数) */
1444
1442
  emitObjectContent(raw, matrix, width, height) {
1445
- const type = raw.type;
1443
+ const type = typeKeyOf(raw);
1446
1444
  if (GROUP_TYPES.has(type)) {
1447
1445
  const children = raw.objects;
1448
1446
  if (!Array.isArray(children)) {
@@ -1472,7 +1470,7 @@ export class SvgExporter {
1472
1470
  // effects 拦截与 crop 语义;转正态(renderSrc 已删)落下方常规文本族通道。
1473
1471
  // renderRect.angle=PSD 文档系轴对齐位图对元素角的逆旋(渲染侧 SceneRenderer
1474
1472
  // 同口径——SVG rotate 正向与引擎一致,绕本地位图中心)
1475
- if (type === 'TextImage' && typeof raw.renderSrc === 'string') {
1473
+ if (type === ElementTypes.TEXTIMAGE && typeof raw.renderSrc === 'string') {
1476
1474
  const rect = raw.renderRect;
1477
1475
  const w = typeof rect?.w === 'number' && rect.w > 0 ? rect.w : num(raw, 'width', NaN);
1478
1476
  const h = typeof rect?.h === 'number' && rect.h > 0 ? rect.h : num(raw, 'height', NaN);
@@ -1510,7 +1508,7 @@ export class SvgExporter {
1510
1508
  }
1511
1509
  const geometry = shapeGeometry(raw, width, height);
1512
1510
  if (!geometry) {
1513
- this.skip(`type:${type}`);
1511
+ this.skip(`type:${String(raw.type ?? '')}`);
1514
1512
  return null;
1515
1513
  }
1516
1514
  const fill = this.resolvePaint(raw.fill, width, height);
@@ -1547,13 +1545,12 @@ export class SvgExporter {
1547
1545
  * (转曲语义只约束模板字体外发)。
1548
1546
  */
1549
1547
  emitLineDecoration(raw, isArrow) {
1550
- const type = typeof raw.type === 'string' ? raw.type : 'line-decoration';
1551
1548
  const x1 = num(raw, 'x1', NaN);
1552
1549
  const y1 = num(raw, 'y1', NaN);
1553
1550
  const x2 = num(raw, 'x2', NaN);
1554
1551
  const y2 = num(raw, 'y2', NaN);
1555
1552
  if (!Number.isFinite(x1) || !Number.isFinite(y1) || !Number.isFinite(x2) || !Number.isFinite(y2)) {
1556
- this.skip(`dims-missing:${type}`);
1553
+ this.skip(`dims-missing:${String(raw.type ?? '')}`);
1557
1554
  return null;
1558
1555
  }
1559
1556
  // 线色兜底 #000000(渲染侧同款——线族 stroke 缺省仍画黑,不走形状族 strokeVisible 判定)
@@ -1659,7 +1656,7 @@ export class SvgExporter {
1659
1656
  return '';
1660
1657
  if (raw.visible === false)
1661
1658
  return '';
1662
- const type = raw.type;
1659
+ const type = typeKeyOf(raw);
1663
1660
  // 内容尺寸(矩阵中心换算与几何共用):裁剪图用可见尺寸、图片缺宽回退自然尺寸
1664
1661
  let width = num(raw, 'width', NaN);
1665
1662
  let height = num(raw, 'height', NaN);
@@ -1759,7 +1756,7 @@ export class SvgExporter {
1759
1756
  }
1760
1757
  }
1761
1758
  if (!Number.isFinite(width) || !Number.isFinite(height)) {
1762
- this.skip(`dims-missing:${type}`);
1759
+ this.skip(`dims-missing:${String(raw.type ?? '')}`);
1763
1760
  return null;
1764
1761
  }
1765
1762
  const matrix = ownMatrix(raw, width, height);
package/dist/index.d.ts CHANGED
@@ -25,6 +25,10 @@ export { isCanvasPerfEnabled, markCanvasPerfCounter, recordCanvasPerfDuration }
25
25
  export { rectCornerRadii } from './core/roundedRect';
26
26
  export { parsePsdEffects } from './core/psdEffects';
27
27
  export { EngineDocument, type EngineDocumentEvents, type IndexedItem, type SelectionFrame } from './model/document';
28
+ /** 元素类型规范词表(批次 361 主仓同源):小写键 + typeKeyOf 坍缩 + 家族集合——
29
+ * 主仓 @/types/elements 的 ElementNames 即本导出的别名(引擎=渲染权限守门人,
30
+ * 类型词汇的单一事实源在引擎,新增元素类型须先在此登记可渲染) */
31
+ export { ElementTypes, typeKeyOf, TEXT_TYPES, SHAPE_TYPES, LINE_TYPES, PUZZLE_TYPES, GIF_TYPES, VIDEO_TYPES, type ElementTypeKey } from './model/elementTypes';
28
32
  export { buildScene, loadImageElement, IMAGE_LIKE_TYPES, SOLID_TYPES, MASK_TYPES, createNode, isTextBitmapState, textBitmapFillAlpha, SceneNode, TextNode, ShapeNode, PathNode, LineNode, GroupNode, MaskNode, PuzzleNode, TableNode, AnimatedNode, type SerializedNode } from './model/scene';
29
33
  export { SvgExporter, serializePageToSvg, buildTextGlyphPathData, type SvgPageRequest, type SvgPageOptions, type SvgPageResult, type SvgExporterOptions, type SvgViewBox, type SvgFontResolver, type SvgGlyphFont, type SvgGlyphCommand, type SvgMeasureFn, type SvgTextBitmap, type SvgTextBitmapBaker, type SvgTextBitmapFamily } from './export/svgExport';
30
34
  export { parsePathData, getBoundsOfPath, type PathCommand } from './core/pathData';
package/dist/index.js CHANGED
@@ -26,6 +26,10 @@ export { isCanvasPerfEnabled, markCanvasPerfCounter, recordCanvasPerfDuration }
26
26
  export { rectCornerRadii } from './core/roundedRect';
27
27
  export { parsePsdEffects } from './core/psdEffects';
28
28
  export { EngineDocument } from './model/document';
29
+ /** 元素类型规范词表(批次 361 主仓同源):小写键 + typeKeyOf 坍缩 + 家族集合——
30
+ * 主仓 @/types/elements 的 ElementNames 即本导出的别名(引擎=渲染权限守门人,
31
+ * 类型词汇的单一事实源在引擎,新增元素类型须先在此登记可渲染) */
32
+ export { ElementTypes, typeKeyOf, TEXT_TYPES, SHAPE_TYPES, LINE_TYPES, PUZZLE_TYPES, GIF_TYPES, VIDEO_TYPES } from './model/elementTypes';
29
33
  export { buildScene, loadImageElement, IMAGE_LIKE_TYPES, SOLID_TYPES, MASK_TYPES, createNode, isTextBitmapState, textBitmapFillAlpha, SceneNode, TextNode, ShapeNode, PathNode, LineNode, GroupNode, MaskNode, PuzzleNode, TableNode, AnimatedNode } from './model/scene';
30
34
  export { SvgExporter, serializePageToSvg, buildTextGlyphPathData } from './export/svgExport';
31
35
  export { parsePathData, getBoundsOfPath } from './core/pathData';
@@ -24,6 +24,7 @@ import { invert, objectOriginFromCenter, transformPoint } from '../core/mat2d';
24
24
  import { getBoundsOfPath, parsePathData } from '../core/pathData';
25
25
  import { parseColor } from '../core/color';
26
26
  import { LineNode } from '../model/scene';
27
+ import { ElementTypes } from '../model/elementTypes';
27
28
  import { describePathEdit, describePolyEdit, findInsertCandidate, insertAnchorAt, pathBBoxCenter, polyBBoxCenter, setAnchorType as setAnchorTypeOp, shiftedCenter, writePathCoordinate, writePolyPoint } from '../model/pathEdit';
28
29
  import { buildNodeBorderOverlay, lineQuad } from '../render/selectionOverlay';
29
30
  /** 锚点/手柄命中半径(屏幕 px;引擎手柄命中惯例同 selectionOverlay.HANDLE_HIT_PX) */
@@ -57,13 +58,12 @@ const getCircleSprite = () => {
57
58
  };
58
59
  /** 编辑族判定:Path(命令)/ polygon·polyline(points)/ Line(端点);null = 不可编辑 */
59
60
  export const pathEditKindOf = (node) => {
60
- const type = String(node.raw.type ?? '');
61
- if (type === 'Path' || type === 'path')
61
+ const t = node.typeKey;
62
+ if (t === ElementTypes.PATH)
62
63
  return 'path';
63
- const lower = type.toLowerCase();
64
- if (lower === 'polygon' || lower === 'polyline')
64
+ if (t === ElementTypes.POLYGON || t === ElementTypes.POLYLINE)
65
65
  return 'poly';
66
- if (type === 'Line')
66
+ if (t === ElementTypes.LINE)
67
67
  return 'line';
68
68
  return null;
69
69
  };
@@ -5,6 +5,7 @@
5
5
  * (原私有方法的 this.host.document),语义逐行不变。
6
6
  */
7
7
  import { isTextBitmapState, TextNode } from '../model/scene';
8
+ import { ElementTypes } from '../model/elementTypes';
8
9
  import { applyGroupWidthBake, buildGroupWidthSnapshot, isGroupWidthHandleNode } from '../model/groupResize';
9
10
  import { invert, objectOriginFromCenter, transformPoint } from '../core/mat2d';
10
11
  import { CORNER_HANDLES, deg, handleLocals, pointerLocal, quadCenter, quadDims, rad, solveScales } from './pointerTypes';
@@ -21,7 +22,7 @@ export function buildScaleSnapshot(node, handle, doc) {
21
22
  // 批次 314:TextImage 位图态(renderSrc 在场)ml/mr 走通用 scaleX(图片口径
22
23
  //——改盒宽对位图无视觉意义,且写 width 会触发转正防线);转正后按盒宽语义
23
24
  const textBitmap = isTextBitmapState(node);
24
- const widthBake = (node.raw.type === 'textbox' || node.raw.type === 'Textbox' || (node.raw.type === 'TextImage' && !textBitmap)) && (handle === 'ml' || handle === 'mr');
25
+ const widthBake = (node.typeKey === ElementTypes.TEXTBOX || (node.typeKey === ElementTypes.TEXTIMAGE && !textBitmap)) && (handle === 'ml' || handle === 'mr');
25
26
  if (widthBake) {
26
27
  a.x = -u.x;
27
28
  a.y = -h / 2;
@@ -268,7 +269,7 @@ export function applyFontBake(doc, s, v) {
268
269
  };
269
270
  // textbox 的盒宽是排版输入必须随 ratio;itext/text 宽=最长行(排版推导),写了也不作数。
270
271
  // 双口径同上:大写 'Textbox' 漏判时盒宽不随字号 → 下次排版按旧宽换行(盒宽陈旧回归)
271
- if (s.node.raw.type === 'textbox' || s.node.raw.type === 'Textbox')
272
+ if (s.node.typeKey === ElementTypes.TEXTBOX)
272
273
  props.width = Math.max(s.width * ratio, 1);
273
274
  // 盒高同随 ratio(fabric changeObjectFontSize 等比分支写 height×ratioY):不写则
274
275
  // 序列化旧 height 钉死 TextNode.dims 的盒高下限 max(内容高, raw.height)——字号
@@ -31,6 +31,7 @@
31
31
  * 线宽/十字/刻度全部按 zoom 折算成屏幕恒定像素(1/3/8px,main 同值)。
32
32
  */
33
33
  import { parseColor } from '../core/color';
34
+ import { ElementTypes } from '../model/elementTypes';
34
35
  import { lineQuad, selectionQuadCoords } from '../render/selectionOverlay';
35
36
  import { CORNER_HANDLE_LIST, isCornerHandle } from '../model/handles';
36
37
  import { buildAxisSortedPoints, buildGapIndex, coordsToPoints, getReferenceSnapPoints, round, snapDraggedElements, snapResizingElements } from '../core/snap';
@@ -173,7 +174,7 @@ export class SnapGuideController {
173
174
  registerScaling(node, handle) {
174
175
  if (!this.enabled())
175
176
  return;
176
- if (node.raw.type === 'circle')
177
+ if (node.typeKey === ElementTypes.CIRCLE)
177
178
  return;
178
179
  this.clearLines();
179
180
  this.activeType = node.raw.type;
@@ -38,6 +38,7 @@
38
38
  * = 误透传(点阴影落空),方向比误实心更错。
39
39
  */
40
40
  import { ALPHA_HIT_TRANSPARENT_LIMIT, AnimatedNode, GroupNode, IMAGE_LIKE_TYPES, MaskNode, PuzzleNode, TableNode } from './scene';
41
+ import { ElementTypes } from './elementTypes';
41
42
  import { parsePsdEffects, psdEffectsKey } from '../core/psdEffects';
42
43
  import { bakePsdShadow, bakePsdStrokes } from '../render/imageEffects';
43
44
  /** 与 app fabricCanvas.isTransparent / alphaMask 的 alphaChannel > 10 同口径
@@ -232,7 +233,7 @@ export const isHitTransparent = (node, x, y, ctx) => {
232
233
  const gco = typeof node.raw.globalCompositeOperation === 'string' ? node.raw.globalCompositeOperation : '';
233
234
  if (gco === 'multiply' && !ctx.selection.includes(node))
234
235
  return true;
235
- if (gco && gco !== 'source-over' && node.raw.type !== 'ReferenceLine' && ctx.hasSelectableBelow())
236
+ if (gco && gco !== 'source-over' && node.typeKey !== ElementTypes.REFERENCELINE && ctx.hasSelectableBelow())
236
237
  return true;
237
238
  // 豁免清单(app _checkTransparencyWithCache / _checkTarget):拼图/蒙版/
238
239
  // 文本(含 TextImage 位图态——文字元素语义盒内空白属于文字层,用户定义
@@ -26,6 +26,7 @@
26
26
  * 分派在效果层之前返回)。
27
27
  */
28
28
  import { FONT_SIZE_FRACTION } from './textLayout';
29
+ import { ElementTypes, typeKeyOf } from './elementTypes';
29
30
  /** fabric Text 常量同源(ArcText BaseRadius / MIN_TEXT_WIDTH) */
30
31
  const BASE_RADIUS = 10000;
31
32
  const MIN_TEXT_WIDTH = 2;
@@ -80,9 +81,9 @@ const sectorBoundingBox = (E, F, C, radius) => {
80
81
  };
81
82
  /** ArcText 类型判定(curvature 任意值都走摆位机——0° 也经 radius=1e5 的近直渲染) */
82
83
  export const arcTextKind = (raw) => {
83
- if (raw.type === 'ArcText')
84
+ if (typeKeyOf(raw) === ElementTypes.ARCTEXT)
84
85
  return 'arc';
85
- if (raw.type === 'CircleText')
86
+ if (typeKeyOf(raw) === ElementTypes.CIRCLETEXT)
86
87
  return 'circle';
87
88
  return null;
88
89
  };
@@ -294,7 +295,7 @@ const computeCirclePlacements = (layout, lineHeight, params) => {
294
295
  /** 弧形/圆形文本统一入口:参数缺省对齐应用类字段默认(curvature 300 /
295
296
  * circleSize 40 / startAngle 0 / sweep 360 / eccentricity 0 / normal) */
296
297
  export const computeArcTextLayout = (layout, raw, lineHeight) => {
297
- if (raw.type === 'CircleText') {
298
+ if (typeKeyOf(raw) === ElementTypes.CIRCLETEXT) {
298
299
  return computeCirclePlacements(layout, lineHeight, {
299
300
  size: typeof raw.circleSize === 'number' ? raw.circleSize : 40,
300
301
  startAngle: typeof raw.circleStartAngle === 'number' ? raw.circleStartAngle : 0,
@@ -305,7 +305,7 @@ export declare class CompatObject {
305
305
  * target 不进失效链 */
306
306
  get ref(): CompatObject;
307
307
  /** 图像族判定:IMAGE_LIKE_TYPES + Mask(ElementMask 面板蒙版源)+ gif/video
308
- * (AnimatedNode 图像管线)。类型键大小写兼容(引擎 raw 两形态并存) */
308
+ * (AnimatedNode 图像管线)。小写键口径(typeKeyOf 坍缩,批次 360) */
309
309
  private get isImageLikeNode();
310
310
  /** 应用 FabricImage.getSrc 覆写语义:originalSrc 优先(换图后历史快照 before/after
311
311
  * 以 originalSrc 判等回放);无则 src。filtered 位不承接(引擎无滤镜后源缓存) */
@@ -18,6 +18,7 @@
18
18
  */
19
19
  import { CompatPoint } from '../core/point';
20
20
  import { AnimatedNode, GroupNode, IMAGE_LIKE_TYPES, MASK_TYPES, PathNode, PuzzleNode, TableNode, TextNode } from './scene';
21
+ import { ElementTypes, typeKeyOf } from './elementTypes';
21
22
  import { anchorStyleAt } from './pathEdit';
22
23
  import { parsePathData } from '../core/pathData';
23
24
  import { pathEditKindOf } from '../interact/pathSession';
@@ -141,8 +142,8 @@ export class CompatObject {
141
142
  return;
142
143
  if (props.width < 0)
143
144
  return;
144
- const rawType = String(this.node.raw.type ?? '');
145
- if (rawType !== 'textbox' && rawType !== 'Textbox')
145
+ const rawType = typeKeyOf(this.node.raw);
146
+ if (rawType !== ElementTypes.TEXTBOX)
146
147
  return;
147
148
  if (arcTextKind(this.node.raw))
148
149
  return;
@@ -345,10 +346,10 @@ export class CompatObject {
345
346
  // 面板的换图与图源读位。方法存在性=类型判别器(main.ts 背景图/AI 技法/useChat
346
347
  // 以 typeof getSrc 判图像族后回落 raw.src),仅图像族暴露——fabric 同款缺席语义 ——
347
348
  /** 图像族判定:IMAGE_LIKE_TYPES + Mask(ElementMask 面板蒙版源)+ gif/video
348
- * (AnimatedNode 图像管线)。类型键大小写兼容(引擎 raw 两形态并存) */
349
+ * (AnimatedNode 图像管线)。小写键口径(typeKeyOf 坍缩,批次 360) */
349
350
  get isImageLikeNode() {
350
- const t = String(this.node.raw.type ?? '');
351
- return IMAGE_LIKE_TYPES.has(t) || MASK_TYPES.has(t) || ['gif', 'video'].includes(t.toLowerCase());
351
+ const t = typeKeyOf(this.node.raw);
352
+ return IMAGE_LIKE_TYPES.has(t) || MASK_TYPES.has(t) || t === ElementTypes.GIF || t === ElementTypes.VIDEO;
352
353
  }
353
354
  /** 应用 FabricImage.getSrc 覆写语义:originalSrc 优先(换图后历史快照 before/after
354
355
  * 以 originalSrc 判等回放);无则 src。filtered 位不承接(引擎无滤镜后源缓存) */
@@ -1413,7 +1414,7 @@ export class CompatObject {
1413
1414
  /** clipImage 序列化声明读位(非 Mask 节点/坏声明 null——type 两形态同 isImageLikeNode 口径) */
1414
1415
  const clipImageRawOf = (node) => {
1415
1416
  const raw = node.raw;
1416
- if (!MASK_TYPES.has(String(raw.type ?? '')))
1417
+ if (!MASK_TYPES.has(typeKeyOf(raw)))
1417
1418
  return null;
1418
1419
  const c = raw.clipImage;
1419
1420
  if (!c || typeof c !== 'object' || typeof c.src !== 'string')
@@ -0,0 +1,99 @@
1
+ /**
2
+ * 元素类型规范词表(小写规范形态)+装载期一次性小写化比较键。
3
+ *
4
+ * 双产源域不再逐集合枚举双形态:fabric 基类 toObject 写小写、自定义类
5
+ * toObject 恒大写(classRegistry 亦注册小写兜底旧数据)、PDF producer
6
+ * 场景级 'Path'(批次 357 正名)。历史方案是每族 Set 收双形态——漏一枚
7
+ * 即 buildScene 静默跳过(批次 338 表格线 / 357 path / 360 i-text 事故族)。
8
+ * 现统一为:比较一律走 typeKeyOf(raw)(raw 层,装载/序列化侧)或
9
+ * node.typeKey(节点层,构造期缓存 + set 写 type 重算),集合只收小写。
10
+ *
11
+ * 性能约束(批次 222 先例):帧循环热路径禁止逐比较 toLowerCase 分配
12
+ * 字符串——万级场景每帧万次分配;判定必须消费缓存键。
13
+ *
14
+ * 词表值域与主仓 ElementNames(@/types/elements)收敛:'ArcText'→'arctext'
15
+ * 等小写坍缩后两仓同一套词汇;'IText' 与 'itext' 小写同形坍缩同族。
16
+ * raw.type 原文不被改写(toObject/序列化保原大小写往返)。
17
+ */
18
+ export declare const ElementTypes: {
19
+ readonly TEXTBOX: "textbox";
20
+ readonly TEXT: "text";
21
+ /** fabric IText 基类 toObject 小写(与 INPUTTEXT 'itext' 是两个串) */
22
+ readonly ITEXT: "i-text";
23
+ readonly INPUTTEXT: "itext";
24
+ readonly ARCHTEXT: "archtext";
25
+ readonly WAISTTEXT: "waisttext";
26
+ readonly FLAGTEXT: "flagtext";
27
+ readonly ARCTEXT: "arctext";
28
+ readonly CIRCLETEXT: "circletext";
29
+ readonly SCROLLTEXT: "scrolltext";
30
+ /** 批次 314 图片文字:位图态(raw.renderSrc 在场)按图片口径 */
31
+ readonly TEXTIMAGE: "textimage";
32
+ readonly IMAGE: "image";
33
+ readonly SVGIMAGE: "svgimage";
34
+ readonly CROPIMAGE: "cropimage";
35
+ readonly ECHART: "echart";
36
+ readonly FABRIC_ECHART: "fabricechart";
37
+ readonly QRCODE: "qrcode";
38
+ readonly BARCODE: "barcode";
39
+ readonly MASK: "mask";
40
+ readonly PATH: "path";
41
+ readonly RECT: "rect";
42
+ readonly FABRICRECT: "fabricrect";
43
+ readonly LINE: "line";
44
+ readonly ARROW: "arrow";
45
+ readonly POLYLINE: "polyline";
46
+ readonly POLYGON: "polygon";
47
+ readonly ELLIPSE: "ellipse";
48
+ readonly CIRCLE: "circle";
49
+ readonly TRIANGLE: "triangle";
50
+ readonly TABLE: "table";
51
+ readonly GROUP: "group";
52
+ /** 多选态合成类型(fabric ActiveSelection 序列化形态;主仓 GroupTypeSets 消费) */
53
+ readonly ACTIVE_SELECTION: "activeselection";
54
+ readonly PUZZLE: "puzzle";
55
+ readonly GIF: "gif";
56
+ readonly VIDEO: "video";
57
+ readonly DIMENSION: "dimension";
58
+ readonly REFERENCELINE: "referenceline";
59
+ };
60
+ export type ElementTypeKey = (typeof ElementTypes)[keyof typeof ElementTypes];
61
+ /** raw 层比较键(工厂/装载/序列化侧入口):一次性小写化;非串/缺席返 '' */
62
+ export declare const typeKeyOf: (raw: {
63
+ type?: unknown;
64
+ } | null | undefined) => string;
65
+ /** 文本族:textbox 有固定盒宽换行;itext/text 不换行(宽=最长行);
66
+ * 变形三类型(P4-5a)按 textbox 盒语义排版(warpStrength=0/编辑态走常规管线);
67
+ * 弧形/圆形(P4-5b)按 itext 语义排版(不换行),dims 走 arcLayout 的弧形 bbox;
68
+ * TextImage(批次 314 图片文字):PSD 导入的位图态文本——raw.renderSrc 在场时
69
+ * 渲染走位图 quad(零字体依赖),编辑态/转正后走常规字形管线;
70
+ * 'i-text'(fabric IText 基类 toObject 小写)=旧模板域兜底——漏收=旧模板
71
+ * 文本对象 buildScene 静默跳过(批次 360) */
72
+ export declare const TEXT_TYPES: Set<string>;
73
+ /** 序列化侧图片族(image/svgimage/cropimage/qrcode/barcode/echart 族;
74
+ * 'Image'/'QRCode'/'BarCode'/'FabricEchart' 等大写形态经 typeKeyOf 坍缩) */
75
+ export declare const IMAGE_LIKE_TYPES: Set<string>;
76
+ /** 填充形状族(P3-1 + P3-6a):三角化网格渲染;line/arrow 无填充(描边族属 P3-2)暂不进。
77
+ * 'path' 是 fabric Path/FabricPath 与 PDF producer(批次 357 正名 'Path')双产源的
78
+ * 坍缩形态;'triangle'(fabric Triangle)按 width/height 合成三点多边形(ShapeNode 分支) */
79
+ export declare const SHAPE_TYPES: Set<string>;
80
+ /** 路径族判定(批次 361 惯用法统一):单类型判断一律 `key === ElementTypes.PATH`
81
+ * 直比(单成员集合已退役);SHAPE_TYPES 同步收录 path 供 isShapeType 渲染/
82
+ * 阴影/命中门(SceneRenderer 形状分支按谓词分档,节点在而谓词 miss=不渲染) */
83
+ /** 线族(P3-6b):'Line' fabric toObject 与 'line' 历史小写坍缩同族;arrow/
84
+ * dimension/referenceline 是应用类注册名域(大写形态经 typeKeyOf 坍缩)。
85
+ * x1..y2 为中心相对坐标(calcLinePoints 恒等映射);渲染走描边烘焙(arrow/
86
+ * dimension 含端头/刻度/文本装饰) */
87
+ export declare const LINE_TYPES: Set<string>;
88
+ /** 填充实心族(rect/FabricRect 双产源坍缩) */
89
+ export declare const SOLID_TYPES: Set<string>;
90
+ /** 蒙版族(P4-5b(2/2)):FabricMask.toObject 恒写 'Mask'(classRegistry 亦注册小写 'mask')。
91
+ * 不进 IMAGE_LIKE_TYPES——Mask 的 cropX/cropY 是裁剪态暂存(渲染走 clipX/clipY),
92
+ * 与图片族静态裁剪语义不同,imageCropRect 不适用 */
93
+ export declare const MASK_TYPES: Set<string>;
94
+ /** 拼图(P4-5b(2/2)):FabricPuzzle.toObject 恒写 'Puzzle'(小写兜底) */
95
+ export declare const PUZZLE_TYPES: Set<string>;
96
+ /** 动画族(Phase 4):FabricGIF.toObject 恒写大写 'GIF'(classRegistry 亦注册小写 'gif',兜底旧数据) */
97
+ export declare const GIF_TYPES: Set<string>;
98
+ /** FabricVideo.toObject 恒写 'Video'(小写兜底) */
99
+ export declare const VIDEO_TYPES: Set<string>;
@@ -0,0 +1,119 @@
1
+ /**
2
+ * 元素类型规范词表(小写规范形态)+装载期一次性小写化比较键。
3
+ *
4
+ * 双产源域不再逐集合枚举双形态:fabric 基类 toObject 写小写、自定义类
5
+ * toObject 恒大写(classRegistry 亦注册小写兜底旧数据)、PDF producer
6
+ * 场景级 'Path'(批次 357 正名)。历史方案是每族 Set 收双形态——漏一枚
7
+ * 即 buildScene 静默跳过(批次 338 表格线 / 357 path / 360 i-text 事故族)。
8
+ * 现统一为:比较一律走 typeKeyOf(raw)(raw 层,装载/序列化侧)或
9
+ * node.typeKey(节点层,构造期缓存 + set 写 type 重算),集合只收小写。
10
+ *
11
+ * 性能约束(批次 222 先例):帧循环热路径禁止逐比较 toLowerCase 分配
12
+ * 字符串——万级场景每帧万次分配;判定必须消费缓存键。
13
+ *
14
+ * 词表值域与主仓 ElementNames(@/types/elements)收敛:'ArcText'→'arctext'
15
+ * 等小写坍缩后两仓同一套词汇;'IText' 与 'itext' 小写同形坍缩同族。
16
+ * raw.type 原文不被改写(toObject/序列化保原大小写往返)。
17
+ */
18
+ export const ElementTypes = {
19
+ TEXTBOX: 'textbox',
20
+ TEXT: 'text',
21
+ /** fabric IText 基类 toObject 小写(与 INPUTTEXT 'itext' 是两个串) */
22
+ ITEXT: 'i-text',
23
+ INPUTTEXT: 'itext',
24
+ ARCHTEXT: 'archtext',
25
+ WAISTTEXT: 'waisttext',
26
+ FLAGTEXT: 'flagtext',
27
+ ARCTEXT: 'arctext',
28
+ CIRCLETEXT: 'circletext',
29
+ SCROLLTEXT: 'scrolltext',
30
+ /** 批次 314 图片文字:位图态(raw.renderSrc 在场)按图片口径 */
31
+ TEXTIMAGE: 'textimage',
32
+ IMAGE: 'image',
33
+ SVGIMAGE: 'svgimage',
34
+ CROPIMAGE: 'cropimage',
35
+ ECHART: 'echart',
36
+ FABRIC_ECHART: 'fabricechart',
37
+ QRCODE: 'qrcode',
38
+ BARCODE: 'barcode',
39
+ MASK: 'mask',
40
+ PATH: 'path',
41
+ RECT: 'rect',
42
+ FABRICRECT: 'fabricrect',
43
+ LINE: 'line',
44
+ ARROW: 'arrow',
45
+ POLYLINE: 'polyline',
46
+ POLYGON: 'polygon',
47
+ ELLIPSE: 'ellipse',
48
+ CIRCLE: 'circle',
49
+ TRIANGLE: 'triangle',
50
+ TABLE: 'table',
51
+ GROUP: 'group',
52
+ /** 多选态合成类型(fabric ActiveSelection 序列化形态;主仓 GroupTypeSets 消费) */
53
+ ACTIVE_SELECTION: 'activeselection',
54
+ PUZZLE: 'puzzle',
55
+ GIF: 'gif',
56
+ VIDEO: 'video',
57
+ DIMENSION: 'dimension',
58
+ REFERENCELINE: 'referenceline'
59
+ };
60
+ /** raw 层比较键(工厂/装载/序列化侧入口):一次性小写化;非串/缺席返 '' */
61
+ export const typeKeyOf = (raw) => {
62
+ const t = raw?.type;
63
+ return typeof t === 'string' ? t.toLowerCase() : '';
64
+ };
65
+ /** 文本族:textbox 有固定盒宽换行;itext/text 不换行(宽=最长行);
66
+ * 变形三类型(P4-5a)按 textbox 盒语义排版(warpStrength=0/编辑态走常规管线);
67
+ * 弧形/圆形(P4-5b)按 itext 语义排版(不换行),dims 走 arcLayout 的弧形 bbox;
68
+ * TextImage(批次 314 图片文字):PSD 导入的位图态文本——raw.renderSrc 在场时
69
+ * 渲染走位图 quad(零字体依赖),编辑态/转正后走常规字形管线;
70
+ * 'i-text'(fabric IText 基类 toObject 小写)=旧模板域兜底——漏收=旧模板
71
+ * 文本对象 buildScene 静默跳过(批次 360) */
72
+ export const TEXT_TYPES = new Set([
73
+ ElementTypes.TEXTBOX,
74
+ ElementTypes.INPUTTEXT,
75
+ ElementTypes.ITEXT,
76
+ ElementTypes.TEXT,
77
+ ElementTypes.ARCHTEXT,
78
+ ElementTypes.WAISTTEXT,
79
+ ElementTypes.FLAGTEXT,
80
+ ElementTypes.ARCTEXT,
81
+ ElementTypes.CIRCLETEXT,
82
+ ElementTypes.SCROLLTEXT,
83
+ ElementTypes.TEXTIMAGE
84
+ ]);
85
+ /** 序列化侧图片族(image/svgimage/cropimage/qrcode/barcode/echart 族;
86
+ * 'Image'/'QRCode'/'BarCode'/'FabricEchart' 等大写形态经 typeKeyOf 坍缩) */
87
+ export const IMAGE_LIKE_TYPES = new Set([
88
+ ElementTypes.IMAGE,
89
+ ElementTypes.SVGIMAGE,
90
+ ElementTypes.CROPIMAGE,
91
+ ElementTypes.QRCODE,
92
+ ElementTypes.BARCODE,
93
+ ElementTypes.ECHART,
94
+ ElementTypes.FABRIC_ECHART
95
+ ]);
96
+ /** 填充形状族(P3-1 + P3-6a):三角化网格渲染;line/arrow 无填充(描边族属 P3-2)暂不进。
97
+ * 'path' 是 fabric Path/FabricPath 与 PDF producer(批次 357 正名 'Path')双产源的
98
+ * 坍缩形态;'triangle'(fabric Triangle)按 width/height 合成三点多边形(ShapeNode 分支) */
99
+ export const SHAPE_TYPES = new Set([ElementTypes.ELLIPSE, ElementTypes.CIRCLE, ElementTypes.POLYGON, ElementTypes.POLYLINE, ElementTypes.PATH, ElementTypes.TRIANGLE]);
100
+ /** 路径族判定(批次 361 惯用法统一):单类型判断一律 `key === ElementTypes.PATH`
101
+ * 直比(单成员集合已退役);SHAPE_TYPES 同步收录 path 供 isShapeType 渲染/
102
+ * 阴影/命中门(SceneRenderer 形状分支按谓词分档,节点在而谓词 miss=不渲染) */
103
+ /** 线族(P3-6b):'Line' fabric toObject 与 'line' 历史小写坍缩同族;arrow/
104
+ * dimension/referenceline 是应用类注册名域(大写形态经 typeKeyOf 坍缩)。
105
+ * x1..y2 为中心相对坐标(calcLinePoints 恒等映射);渲染走描边烘焙(arrow/
106
+ * dimension 含端头/刻度/文本装饰) */
107
+ export const LINE_TYPES = new Set([ElementTypes.LINE, ElementTypes.ARROW, ElementTypes.DIMENSION, ElementTypes.REFERENCELINE]);
108
+ /** 填充实心族(rect/FabricRect 双产源坍缩) */
109
+ export const SOLID_TYPES = new Set([ElementTypes.RECT, ElementTypes.FABRICRECT]);
110
+ /** 蒙版族(P4-5b(2/2)):FabricMask.toObject 恒写 'Mask'(classRegistry 亦注册小写 'mask')。
111
+ * 不进 IMAGE_LIKE_TYPES——Mask 的 cropX/cropY 是裁剪态暂存(渲染走 clipX/clipY),
112
+ * 与图片族静态裁剪语义不同,imageCropRect 不适用 */
113
+ export const MASK_TYPES = new Set([ElementTypes.MASK]);
114
+ /** 拼图(P4-5b(2/2)):FabricPuzzle.toObject 恒写 'Puzzle'(小写兜底) */
115
+ export const PUZZLE_TYPES = new Set([ElementTypes.PUZZLE]);
116
+ /** 动画族(Phase 4):FabricGIF.toObject 恒写大写 'GIF'(classRegistry 亦注册小写 'gif',兜底旧数据) */
117
+ export const GIF_TYPES = new Set([ElementTypes.GIF]);
118
+ /** FabricVideo.toObject 恒写 'Video'(小写兜底) */
119
+ export const VIDEO_TYPES = new Set([ElementTypes.VIDEO]);
@@ -1,9 +1,10 @@
1
1
  import { GroupNode, isTextBitmapState, PuzzleNode, TableNode, TextNode } from './scene';
2
+ import { ElementTypes } from './elementTypes';
2
3
  import { invert, objectOriginFromCenter, transformPoint } from '../core/mat2d';
3
4
  /** 固定盒宽文本判定(批次 95 双口径:模板/compat 桥恒写 'Textbox' 大写;
4
5
  * 批次 314:转正后的 TextImage(renderSrc 已删)同盒宽语义——位图态不进,
5
6
  * 组改宽按图片口径走 scaleX 分支) */
6
- export const isFixedBoxTextNode = (node) => node instanceof TextNode && (node.raw.type === 'textbox' || node.raw.type === 'Textbox' || (node.raw.type === 'TextImage' && !isTextBitmapState(node)));
7
+ export const isFixedBoxTextNode = (node) => node instanceof TextNode && (node.typeKey === ElementTypes.TEXTBOX || (node.typeKey === ElementTypes.TEXTIMAGE && !isTextBitmapState(node)));
7
8
  /** 手势起点快照(pointerTransform.buildScaleSnapshot 的组分支消费) */
8
9
  export function buildGroupWidthSnapshot(node, sign) {
9
10
  const w = node.dims.x;
@@ -66,15 +66,12 @@ export declare const WORKSPACE_ID = "WorkSpaceDrawType";
66
66
  * 选区;selectable 不随序列化落 raw,引擎按 id 族等价过滤。框选(document.
67
67
  * objectsIntersectingRect)/selectAll/svgExport 整页过滤同源) */
68
68
  export declare const WORKSPACE_IDS: Set<string>;
69
- /** fabric 原生 toObject 恒写类名首字母大写('Image');小写为历史/种子口径兜底 */
70
- export declare const IMAGE_LIKE_TYPES: Set<string>;
71
- export declare const SOLID_TYPES: Set<string>;
72
- /** 文本族:textbox 有固定盒宽换行;itext/text 不换行(宽=最长行);
73
- * 变形三类型(P4-5a)按 textbox 盒语义排版(warpStrength=0/编辑态走常规管线);
74
- * 弧形/圆形(P4-5b)按 itext 语义排版(不换行),dims 走 arcLayout 的弧形 bbox;
75
- * TextImage(批次 314 图片文字):PSD 导入的位图态文本——raw.renderSrc 在场时
76
- * 渲染走位图 quad(零字体依赖),编辑态/转正后走常规字形管线 */
77
- export declare const TEXT_TYPES: Set<string>;
69
+ /** 元素类型词表与家族集合(小写规范形态)统一收口 model/elementTypes——
70
+ * 双产源域(fabric 基类 toObject 小写/自定义类 toObject 恒大写/PDF producer
71
+ * 'Path')不再逐集合枚举双形态,比较一律走 typeKeyOf(raw)/node.typeKey,
72
+ * 漏枚举=buildScene 静默跳过的事故族(338/357/360)就此根绝;产源注释
73
+ * 与家族语义见该模块。此处 re-export 维持既有消费面导入路径不变 */
74
+ export { ElementTypes, typeKeyOf, TEXT_TYPES, IMAGE_LIKE_TYPES, SOLID_TYPES, SHAPE_TYPES, LINE_TYPES, MASK_TYPES, PUZZLE_TYPES, GIF_TYPES, VIDEO_TYPES } from './elementTypes';
78
75
  /** 批次 314 图片文字:TextImage 位图态判定(raw.renderSrc 在场)——渲染/命中/
79
76
  * 手柄/组语义全按图片口径(缩放手势走 scale、不做文本烘焙);转正(renderSrc
80
77
  * 删除)后按文本口径(盒宽/字号烘焙、组改宽回流) */
@@ -88,14 +85,6 @@ export declare const isTextBitmapState: (node: SceneNode) => boolean;
88
85
  export declare const textBitmapFillAlpha: (raw: {
89
86
  fill?: unknown;
90
87
  } | Record<string, unknown>) => number;
91
- /** 填充形状族(P3-1 + P3-6a):三角化网格渲染;line/arrow 无填充(描边族属 P3-2)暂不进。
92
- * 'Path' 是 fabric Path/FabricPath 的 toObject type(classRegistry 注册名);
93
- * 'triangle'(fabric Triangle)按 width/height 合成三点多边形(ShapeNode 分支) */
94
- export declare const SHAPE_TYPES: Set<string>;
95
- /** 线族(P3-6b):'Line' 是 fabric toObject type;arrow/Dimension/ReferenceLine 是应用类注册名。
96
- * x1..y2 为中心相对坐标(calcLinePoints 恒等映射);渲染走描边烘焙(arrow/Dimension
97
- * 含端头/刻度/文本装饰) */
98
- export declare const LINE_TYPES: Set<string>;
99
88
  /** 参考线(批次 72):视口横贯的引导 chrome——fabric 侧画在工作区遮罩之上的
100
89
  * overlay 通道(fabricCanvas._renderWorkspaceOverlay),引擎同相位走
101
90
  * frameOverlay(SceneRenderer 跳过——±999999 的线超 bakeNodeStroke 8192
@@ -112,12 +101,6 @@ export declare const isReferenceLineNode: (node: SceneNode) => boolean;
112
101
  * axis:'horizontal' = 横线(at 为场景 y)/ 'vertical' = 竖线(at 为场景 x)
113
102
  */
114
103
  export declare const createReferenceLineRaw: (axis: "horizontal" | "vertical", at: number) => SerializedNode;
115
- /** 蒙版族(P4-5b(2/2)):FabricMask.toObject 恒写 'Mask'(classRegistry 亦注册小写 'mask')。
116
- * 不进 IMAGE_LIKE_TYPES——Mask 的 cropX/cropY 是裁剪态暂存(渲染走 clipX/clipY),
117
- * 与图片族静态裁剪语义不同,imageCropRect 不适用 */
118
- export declare const MASK_TYPES: Set<string>;
119
- /** 拼图(P4-5b(2/2)):FabricPuzzle.toObject 恒写 'Puzzle'(小写兜底) */
120
- export declare const PUZZLE_TYPES: Set<string>;
121
104
  export declare class SceneNode {
122
105
  readonly raw: SerializedNode;
123
106
  /** 合成节点标记(运行时位,不进 raw/序列化):节点由宿主侧以其他节点为源派生
@@ -144,6 +127,10 @@ export declare class SceneNode {
144
127
  * 基态恢复天然干净),null = 基态。生效汇聚点 transformProps/renderOpacity */
145
128
  private _animationOverride;
146
129
  constructor(raw: SerializedNode);
130
+ /** 类型比较键缓存(批次 360,全类型比较消费;set 写 type 时重算) */
131
+ private _typeKey;
132
+ /** 小写规范类型键(ElementTypes 口径)——类型比较一律经此,禁裸比 raw.type */
133
+ get typeKey(): string;
147
134
  /** 参考线判定缓存(批次 222,帧循环消费;set 写 type 时重算) */
148
135
  private _isReferenceLine;
149
136
  get isReferenceLine(): boolean;
@@ -985,7 +972,9 @@ export declare class PuzzleNode extends GroupNode {
985
972
  * (应用侧无此组合),不在此列。
986
973
  */
987
974
  export declare const imageCropRect: (raw: SerializedNode) => SourceRect | null;
988
- /** 节点工厂(buildScene 与 GroupNode 递归共用);未识别类型返回 null */
975
+ /** 节点工厂(buildScene 与 GroupNode 递归共用);未识别类型返回 null。
976
+ * 类型分派一律走 typeKeyOf 小写键(批次 360)——大写 toObject/小写历史/
977
+ * producer 'Path' 双产源统一坍缩承接,Table/Group 等单形态枚举位同口径 */
989
978
  export declare const createNode: (raw: SerializedNode) => SceneNode | null;
990
979
  export declare const buildScene: (objects: SerializedNode[]) => {
991
980
  nodes: SceneNode[];
@@ -47,19 +47,13 @@ export const WORKSPACE_ID = 'WorkSpaceDrawType';
47
47
  * 选区;selectable 不随序列化落 raw,引擎按 id 族等价过滤。框选(document.
48
48
  * objectsIntersectingRect)/selectAll/svgExport 整页过滤同源) */
49
49
  export const WORKSPACE_IDS = new Set(['WorkSpaceDrawType', 'WorkSpaceClipType', 'WorkSpaceSafeType', 'WorkSpaceMaskType', 'WorkSpaceLineType', 'WorkSpaceShadowType']);
50
- /** fabric 原生 toObject 恒写类名首字母大写('Image');小写为历史/种子口径兜底 */
51
- export const IMAGE_LIKE_TYPES = new Set(['image', 'Image', 'svgimage', 'cropimage', 'qrcode', 'QRCode', 'barcode', 'BarCode', 'echart', 'FabricEchart']);
52
- /** 动画族(Phase 4):FabricGIF.toObject 恒写大写 'GIF'(classRegistry 亦注册小写 'gif',兜底旧数据) */
53
- const GIF_TYPES = new Set(['GIF', 'gif']);
54
- /** FabricVideo.toObject 恒写 'Video'(小写兜底) */
55
- const VIDEO_TYPES = new Set(['Video', 'video']);
56
- export const SOLID_TYPES = new Set(['rect', 'Rect', 'fabricrect', 'FabricRect']);
57
- /** 文本族:textbox 有固定盒宽换行;itext/text 不换行(宽=最长行);
58
- * 变形三类型(P4-5a)按 textbox 盒语义排版(warpStrength=0/编辑态走常规管线);
59
- * 弧形/圆形(P4-5b)按 itext 语义排版(不换行),dims 走 arcLayout 的弧形 bbox;
60
- * TextImage(批次 314 图片文字):PSD 导入的位图态文本——raw.renderSrc 在场时
61
- * 渲染走位图 quad(零字体依赖),编辑态/转正后走常规字形管线 */
62
- export const TEXT_TYPES = new Set(['textbox', 'Textbox', 'itext', 'IText', 'text', 'Text', 'ArchText', 'WaistText', 'FlagText', 'ArcText', 'CircleText', 'ScrollText', 'scrollText', 'TextImage']);
50
+ /** 元素类型词表与家族集合(小写规范形态)统一收口 model/elementTypes——
51
+ * 双产源域(fabric 基类 toObject 小写/自定义类 toObject 恒大写/PDF producer
52
+ * 'Path')不再逐集合枚举双形态,比较一律走 typeKeyOf(raw)/node.typeKey,
53
+ * 漏枚举=buildScene 静默跳过的事故族(338/357/360)就此根绝;产源注释
54
+ * 与家族语义见该模块。此处 re-export 维持既有消费面导入路径不变 */
55
+ export { ElementTypes, typeKeyOf, TEXT_TYPES, IMAGE_LIKE_TYPES, SOLID_TYPES, SHAPE_TYPES, LINE_TYPES, MASK_TYPES, PUZZLE_TYPES, GIF_TYPES, VIDEO_TYPES } from './elementTypes';
56
+ import { ElementTypes, GIF_TYPES, VIDEO_TYPES, typeKeyOf, TEXT_TYPES, IMAGE_LIKE_TYPES, SOLID_TYPES, SHAPE_TYPES, LINE_TYPES, MASK_TYPES, PUZZLE_TYPES } from './elementTypes';
63
57
  /** 批次 314 图片文字:TextImage 位图态判定(raw.renderSrc 在场)——渲染/命中/
64
58
  * 手柄/组语义全按图片口径(缩放手势走 scale、不做文本烘焙);转正(renderSrc
65
59
  * 删除)后按文本口径(盒宽/字号烘焙、组改宽回流) */
@@ -76,14 +70,6 @@ export const textBitmapFillAlpha = (raw) => {
76
70
  return 1;
77
71
  return Math.max(0, Math.min(1, parseColor(fill)[3]));
78
72
  };
79
- /** 填充形状族(P3-1 + P3-6a):三角化网格渲染;line/arrow 无填充(描边族属 P3-2)暂不进。
80
- * 'Path' 是 fabric Path/FabricPath 的 toObject type(classRegistry 注册名);
81
- * 'triangle'(fabric Triangle)按 width/height 合成三点多边形(ShapeNode 分支) */
82
- export const SHAPE_TYPES = new Set(['ellipse', 'Ellipse', 'circle', 'Circle', 'polygon', 'Polygon', 'polyline', 'Polyline', 'Path', 'triangle', 'Triangle']);
83
- /** 线族(P3-6b):'Line' 是 fabric toObject type;arrow/Dimension/ReferenceLine 是应用类注册名。
84
- * x1..y2 为中心相对坐标(calcLinePoints 恒等映射);渲染走描边烘焙(arrow/Dimension
85
- * 含端头/刻度/文本装饰) */
86
- export const LINE_TYPES = new Set(['Line', 'arrow', 'Dimension', 'ReferenceLine']);
87
73
  /**
88
74
  * 纯姿态键(批次 221):只参与矩阵合成(origin/scale/skew/flip/rotate/translate),
89
75
  * 不改变任何本地几何/网格/路径轮廓/文本排版/填充语义。多选拖拽每 pointermove
@@ -196,12 +182,6 @@ export const createReferenceLineRaw = (axis, at) => ({
196
182
  lockMovementY: axis === 'vertical',
197
183
  hoverCursor: axis === 'horizontal' ? 'ns-resize' : 'ew-resize'
198
184
  });
199
- /** 蒙版族(P4-5b(2/2)):FabricMask.toObject 恒写 'Mask'(classRegistry 亦注册小写 'mask')。
200
- * 不进 IMAGE_LIKE_TYPES——Mask 的 cropX/cropY 是裁剪态暂存(渲染走 clipX/clipY),
201
- * 与图片族静态裁剪语义不同,imageCropRect 不适用 */
202
- export const MASK_TYPES = new Set(['Mask', 'mask']);
203
- /** 拼图(P4-5b(2/2)):FabricPuzzle.toObject 恒写 'Puzzle'(小写兜底) */
204
- export const PUZZLE_TYPES = new Set(['Puzzle', 'puzzle']);
205
185
  /** 序列化往返保留的字段(与 src/configs/canvas 的 propertiesToInclude 白名单对齐的核心子集) */
206
186
  const OWN_KEYS = [
207
187
  'type',
@@ -258,8 +238,17 @@ export class SceneNode {
258
238
  // FabricRect 族圆角源归一(批次 98):radius>0 时反算本地 rx/ry——fabric
259
239
  // render 每帧同式覆写,手写数据 radius/rx 不一致以 radius 为准
260
240
  normalizeFabricRectRadii(this.raw);
241
+ // 类型比较键(批次 360):构造期一次性小写化(帧循环热路径禁逐比较
242
+ // toLowerCase 分配——批次 222 先例);raw.type 原文不改写,toObject 往返保原大小写
243
+ this._typeKey = typeKeyOf(this.raw);
261
244
  // 参考线判定预计算(批次 222):type 构造后不变(set 带 type 键重算)
262
- this._isReferenceLine = typeof raw.type === 'string' && raw.type.toLowerCase() === 'referenceline';
245
+ this._isReferenceLine = this._typeKey === ElementTypes.REFERENCELINE;
246
+ }
247
+ /** 类型比较键缓存(批次 360,全类型比较消费;set 写 type 时重算) */
248
+ _typeKey;
249
+ /** 小写规范类型键(ElementTypes 口径)——类型比较一律经此,禁裸比 raw.type */
250
+ get typeKey() {
251
+ return this._typeKey;
263
252
  }
264
253
  /** 参考线判定缓存(批次 222,帧循环消费;set 写 type 时重算) */
265
254
  _isReferenceLine;
@@ -311,8 +300,10 @@ export class SceneNode {
311
300
  this._fillPaint = undefined;
312
301
  this._strokeDecl = undefined;
313
302
  }
314
- if ('type' in props && typeof props.type === 'string')
315
- this._isReferenceLine = props.type.toLowerCase() === 'referenceline';
303
+ if ('type' in props) {
304
+ this._typeKey = typeKeyOf(props);
305
+ this._isReferenceLine = this._typeKey === ElementTypes.REFERENCELINE;
306
+ }
316
307
  this._renderNotify?.();
317
308
  }
318
309
  /** 动画覆写写入(P5-6 播放器逐帧调用;null 清除回基态)。矩阵/aCoords/
@@ -327,22 +318,22 @@ export class SceneNode {
327
318
  return typeof this.raw.id === 'string' ? this.raw.id : '';
328
319
  }
329
320
  get isImageType() {
330
- return IMAGE_LIKE_TYPES.has(this.raw.type);
321
+ return IMAGE_LIKE_TYPES.has(this.typeKey);
331
322
  }
332
323
  get isMaskType() {
333
- return MASK_TYPES.has(this.raw.type);
324
+ return MASK_TYPES.has(this.typeKey);
334
325
  }
335
326
  get isSolidType() {
336
- return SOLID_TYPES.has(this.raw.type);
327
+ return SOLID_TYPES.has(this.typeKey);
337
328
  }
338
329
  get isTextType() {
339
- return TEXT_TYPES.has(this.raw.type);
330
+ return TEXT_TYPES.has(this.typeKey);
340
331
  }
341
332
  get isLineType() {
342
- return LINE_TYPES.has(this.raw.type);
333
+ return LINE_TYPES.has(this.typeKey);
343
334
  }
344
335
  get isShapeType() {
345
- return SHAPE_TYPES.has(this.raw.type);
336
+ return SHAPE_TYPES.has(this.typeKey);
346
337
  }
347
338
  get visible() {
348
339
  return this.raw.visible !== false;
@@ -729,7 +720,7 @@ export class TextNode extends SceneNode {
729
720
  if (!this._layout) {
730
721
  const raw = this.raw;
731
722
  this._layout = layoutTextbox(raw.text ?? '', this.textStyle, {
732
- boxWidth: raw.type === 'textbox' || raw.type === 'Textbox' || raw.type === 'TextImage' ? raw.width ?? 0 : null,
723
+ boxWidth: typeKeyOf(raw) === ElementTypes.TEXTBOX || typeKeyOf(raw) === ElementTypes.TEXTIMAGE ? raw.width ?? 0 : null,
733
724
  styles: raw.styles,
734
725
  splitByGrapheme: raw.splitByGrapheme === true,
735
726
  vertical: raw.vertical === true,
@@ -1077,7 +1068,7 @@ export class ShapeNode extends SceneNode {
1077
1068
  }
1078
1069
  /** 形状族类型归一:椭圆/圆几何分支按小写比对(toObject 恒写注册名,大小写混档) */
1079
1070
  get shapeKind() {
1080
- return typeof this.raw.type === 'string' ? this.raw.type.toLowerCase() : '';
1071
+ return this.typeKey;
1081
1072
  }
1082
1073
  /** 三角化网格(懒构建;退化形状返回 null,渲染与命中按空处理) */
1083
1074
  get shapeMesh() {
@@ -1255,8 +1246,8 @@ export const LINE_STROKE_HIT_TOLERANCE = 8;
1255
1246
  * dimension 是引擎超集(app 未列——其同为细杆元素且引擎已有端刻/文本框
1256
1247
  * 装饰命中,方向=更易选中)。ReferenceLine 排除(辅助层自有拖拽交互)。 */
1257
1248
  export const isStrokeLineNode = (node) => {
1258
- const t = typeof node.raw.type === 'string' ? node.raw.type.toLowerCase() : '';
1259
- if (t === 'line' || t === 'arrow' || t === 'dimension' || t === 'polyline')
1249
+ const t = node.typeKey;
1250
+ if (t === ElementTypes.LINE || t === ElementTypes.ARROW || t === ElementTypes.DIMENSION || t === ElementTypes.POLYLINE)
1260
1251
  return true;
1261
1252
  // 形状/Path 填充有效透明(批次 345;旧判据只认空串/'transparent' 字串):
1262
1253
  // 命中退化为描边带 → 索引框按命中带外扩,带外命中不被预筛滤掉
@@ -1489,7 +1480,7 @@ export class LineNode extends SceneNode {
1489
1480
  if (Math.hypot(local.x - px, local.y - py) <= r)
1490
1481
  return true;
1491
1482
  // 装饰命中扩展:类型键小写归一(批次46 勘注——raw 两形态并存)
1492
- const rawType = typeof this.raw.type === 'string' ? this.raw.type.toLowerCase() : '';
1483
+ const rawType = this.typeKey;
1493
1484
  if (rawType === 'arrow')
1494
1485
  return arrowHeadHit(this.raw, local, p);
1495
1486
  if (rawType === 'dimension')
@@ -2281,13 +2272,10 @@ export class MaskNode extends SceneNode {
2281
2272
  clipDynamicVersion = 0;
2282
2273
  /** clipImage 是否动态源(Video/GIF;序列化 type 口径同应用 getIsDynamicElement) */
2283
2274
  get clipDynamicKind() {
2284
- const t = this.clipImageRaw?.type;
2285
- if (typeof t !== 'string')
2286
- return null;
2287
- const lower = t.toLowerCase();
2288
- if (lower === 'video')
2275
+ const t = typeKeyOf(this.clipImageRaw);
2276
+ if (t === ElementTypes.VIDEO)
2289
2277
  return 'video';
2290
- if (lower === 'gif')
2278
+ if (t === ElementTypes.GIF)
2291
2279
  return 'gif';
2292
2280
  return null;
2293
2281
  }
@@ -2753,7 +2741,7 @@ export class PuzzleNode extends GroupNode {
2753
2741
  * (应用侧无此组合),不在此列。
2754
2742
  */
2755
2743
  export const imageCropRect = (raw) => {
2756
- if (!IMAGE_LIKE_TYPES.has(raw.type))
2744
+ if (!IMAGE_LIKE_TYPES.has(typeKeyOf(raw)))
2757
2745
  return null;
2758
2746
  const cropX = Number(raw.cropX) || 0;
2759
2747
  const cropY = Number(raw.cropY) || 0;
@@ -2769,33 +2757,36 @@ export const imageCropRect = (raw) => {
2769
2757
  sh: Math.max(0, visible ? raw.height : raw.height - cropY)
2770
2758
  };
2771
2759
  };
2772
- /** 节点工厂(buildScene 与 GroupNode 递归共用);未识别类型返回 null */
2760
+ /** 节点工厂(buildScene 与 GroupNode 递归共用);未识别类型返回 null。
2761
+ * 类型分派一律走 typeKeyOf 小写键(批次 360)——大写 toObject/小写历史/
2762
+ * producer 'Path' 双产源统一坍缩承接,Table/Group 等单形态枚举位同口径 */
2773
2763
  export const createNode = (raw) => {
2774
2764
  if (!raw || typeof raw.type !== 'string')
2775
2765
  return null;
2776
- if (raw.type === 'Table')
2766
+ const t = typeKeyOf(raw);
2767
+ if (t === ElementTypes.TABLE)
2777
2768
  return new TableNode(raw, createNode);
2778
- if (PUZZLE_TYPES.has(raw.type))
2769
+ if (PUZZLE_TYPES.has(t))
2779
2770
  return new PuzzleNode(raw, createNode);
2780
- if (MASK_TYPES.has(raw.type) && typeof raw.src === 'string')
2771
+ if (MASK_TYPES.has(t) && typeof raw.src === 'string')
2781
2772
  return new MaskNode(raw);
2782
- if (raw.type === 'Group' || raw.type === 'group')
2773
+ if (t === ElementTypes.GROUP)
2783
2774
  return new GroupNode(raw, createNode);
2784
- if (GIF_TYPES.has(raw.type) && typeof raw.src === 'string')
2775
+ if (GIF_TYPES.has(t) && typeof raw.src === 'string')
2785
2776
  return new AnimatedNode(raw, 'gif');
2786
- if (VIDEO_TYPES.has(raw.type) && typeof raw.src === 'string')
2777
+ if (VIDEO_TYPES.has(t) && typeof raw.src === 'string')
2787
2778
  return new AnimatedNode(raw, 'video');
2788
- if (IMAGE_LIKE_TYPES.has(raw.type) && typeof raw.src === 'string')
2779
+ if (IMAGE_LIKE_TYPES.has(t) && typeof raw.src === 'string')
2789
2780
  return new SceneNode(raw);
2790
- if (SOLID_TYPES.has(raw.type))
2781
+ if (SOLID_TYPES.has(t))
2791
2782
  return new SceneNode(raw);
2792
- if (TEXT_TYPES.has(raw.type) && typeof raw.text === 'string')
2783
+ if (TEXT_TYPES.has(t) && typeof raw.text === 'string')
2793
2784
  return new TextNode(raw);
2794
- if (raw.type === 'Path')
2785
+ if (t === ElementTypes.PATH)
2795
2786
  return new PathNode(raw);
2796
- if (LINE_TYPES.has(raw.type))
2787
+ if (LINE_TYPES.has(t))
2797
2788
  return new LineNode(raw);
2798
- if (SHAPE_TYPES.has(raw.type))
2789
+ if (SHAPE_TYPES.has(t))
2799
2790
  return new ShapeNode(raw);
2800
2791
  return null;
2801
2792
  };
@@ -19,6 +19,7 @@ import { parsePsdEffects, psdEffectsKey } from '../core/psdEffects';
19
19
  import { composeMatrix, multiply } from '../core/mat2d';
20
20
  import { isGpuPsdFillEnabled, isGpuPsdShadowEnabled } from '../engineFlag';
21
21
  import { AnimatedNode, MaskNode, TextNode, isTextBitmapState } from '../model/scene';
22
+ import { ElementTypes } from '../model/elementTypes';
22
23
  import { pickZoomBucket } from './GlyphAtlas';
23
24
  import { bakePathEffectShadow, bakePsdShadow, bakePsdSolidFill, bakePsdStrokes, buildTextEffectSource, strokeSupersampleCap, imageFiltersSig } from './imageEffects';
24
25
  import { createTexture2D } from './textureUpload';
@@ -100,7 +101,7 @@ export class PsdEffectPainter {
100
101
  // Mask PSD effects(B1(余) 收尾片):drawShadows/drawFills/drawStrokes 的
101
102
  // 蒙版链——投影垫底(形状源)、填充/描边盖合成层(应用 render() 覆写序)
102
103
  const isMaskFx = node instanceof MaskNode;
103
- if (!node.isImageType && node.raw.type !== 'Path' && !isTextFx && !isMaskFx)
104
+ if (!node.isImageType && node.typeKey !== ElementTypes.PATH && !isTextFx && !isMaskFx)
104
105
  return;
105
106
  if (phase === 'above' && !node.isImageType && !isTextFx && !isMaskFx)
106
107
  return;
@@ -9,6 +9,7 @@
9
9
  */
10
10
  import { parseColor } from '../core/color';
11
11
  import { isReferenceLineNode, LINE_TYPES, MASK_TYPES, PuzzleNode, TableNode, GroupNode } from '../model/scene';
12
+ import { ElementTypes, typeKeyOf } from '../model/elementTypes';
12
13
  import { groupContentQuad } from '../model/groupChildMove';
13
14
  import { EDGE_HANDLE_SIDE, isEdgeHandle, isRadiusHandle, RADIUS_HANDLE_CORNER, RADIUS_HANDLE_LIST } from '../model/handles';
14
15
  /** 屏幕空间常量(px):手柄边长、命中半径、边框线宽、旋转柄偏移 */
@@ -178,7 +179,7 @@ export const moveControlTarget = (doc) => {
178
179
  const node = doc.selection[0];
179
180
  if (node instanceof TableNode || node instanceof PuzzleNode)
180
181
  return null;
181
- const type = String(node.raw.type ?? '');
182
+ const type = node.typeKey;
182
183
  if (LINE_TYPES.has(type) || MASK_TYPES.has(type))
183
184
  return null;
184
185
  if (isUserLockedNode(node))
@@ -378,12 +379,18 @@ export const cornerOffsetToRadius = (offset, maxRadius) => {
378
379
  };
379
380
  /** 圆角手柄宿主判定(矩形):app rectControls 只挂 FabricRect 类(useCanvas 的
380
381
  * ownDefaults 注入)——轻量 Rect 走 fabric 原生默认控件无圆角点,引擎同口径 */
381
- export const isRadiusHandleNode = (node) => !!node && (node.raw.type === 'FabricRect' || node.raw.type === 'fabricrect');
382
+ export const isRadiusHandleNode = (node) => !!node && node.typeKey === ElementTypes.FABRICRECT;
382
383
  /** 圆角手柄宿主判定(图片族,批次 101):app imageControls 挂应用 FabricImage 类
383
384
  * ——码图族(QRCode/BarCode/FabricEchart extends fabric 原生 Image,批次 92 口径)
384
385
  * 与动画族(GIF/Video 直绘帧无圆角渲染,批次 98 勘注⑤)不继承,无圆角点 */
385
- const IMAGE_RADIUS_EXCLUDED = new Set(['qrcode', 'QRCode', 'barcode', 'BarCode', 'echart', 'FabricEchart']);
386
- export const isImageRadiusHandleNode = (node) => !!node && !IMAGE_RADIUS_EXCLUDED.has(node.raw.type) && (node.raw.type === 'image' || node.raw.type === 'Image' || node.raw.type === 'svgimage' || node.raw.type === 'cropimage');
386
+ const IMAGE_RADIUS_EXCLUDED = new Set([ElementTypes.QRCODE, ElementTypes.BARCODE, ElementTypes.ECHART, ElementTypes.FABRIC_ECHART]);
387
+ export const isImageRadiusHandleNode = (node) => {
388
+ if (!node)
389
+ return false;
390
+ // typeKeyOf(raw) 而非 node.typeKey:单测以 { raw } 鸭子桩直喂本谓词
391
+ const t = typeKeyOf(node.raw);
392
+ return !IMAGE_RADIUS_EXCLUDED.has(t) && (t === ElementTypes.IMAGE || t === ElementTypes.SVGIMAGE || t === ElementTypes.CROPIMAGE);
393
+ };
387
394
  /** 视觉系圆角上限(app getRectCornerMaxRadius:min(视觉半宽, 视觉半高))。
388
395
  * 尺寸读 node.dims(transformProps 同口径)——拖放建图等路径 raw 无
389
396
  * width/height(图片默认取位图原宽),直读 raw 会得 0 半径上限/半宽,
@@ -558,7 +565,7 @@ export const handleAdaptiveVisible = (id, screenW, screenH) => {
558
565
  /** 专属控件集豁免:app 侧拼图/蒙版/表格的 ml/mr/mt/mb 族不挂 getVisibility
559
566
  * (fabric 模式同态常驻),引擎同豁免。线族不豁免——其 ml/mr 是 changeWidth
560
567
  * 端点手柄无 getVisibility 走下方常驻分支,族内其余键仍按 adaptive 裁剪 */
561
- const isAdaptiveExemptNode = (node) => node instanceof PuzzleNode || node instanceof TableNode || MASK_TYPES.has(String(node.raw.type ?? ''));
568
+ const isAdaptiveExemptNode = (node) => node instanceof PuzzleNode || node instanceof TableNode || MASK_TYPES.has(node.typeKey);
562
569
  /** 单选手柄集 × 自适应可见性(渲染 buildSelectionOverlay 与命中 pointer.hitHandle
563
570
  * 同源消费):多选不裁剪(fabric AS 原生控件集无 adaptive);线族 ml/mr 常驻 */
564
571
  export const getAdaptiveSelectionHandles = (doc, quad, angleDeg, zoom, radiusNode) => {
@@ -566,7 +573,7 @@ export const getAdaptiveSelectionHandles = (doc, quad, angleDeg, zoom, radiusNod
566
573
  const single = doc.selection.length === 1 ? doc.selection[0] : null;
567
574
  if (!single || isAdaptiveExemptNode(single))
568
575
  return handles;
569
- const lineFamily = LINE_TYPES.has(String(single.raw.type ?? ''));
576
+ const lineFamily = LINE_TYPES.has(single.typeKey);
570
577
  const size = quadScreenSize(quad, zoom);
571
578
  return handles.filter((h) => (lineFamily && (h.id === 'ml' || h.id === 'mr')) || handleAdaptiveVisible(h.id, size.width, size.height));
572
579
  };
@@ -580,7 +587,7 @@ export const getActiveChildHandles = (child, zoom) => {
580
587
  const handles = getSelectionHandles(quad, angle, zoom);
581
588
  if (isAdaptiveExemptNode(child))
582
589
  return handles;
583
- const lineFamily = LINE_TYPES.has(String(child.raw.type ?? ''));
590
+ const lineFamily = LINE_TYPES.has(child.typeKey);
584
591
  const size = quadScreenSize(quad, zoom);
585
592
  return handles.filter((h) => (lineFamily && (h.id === 'ml' || h.id === 'mr')) || handleAdaptiveVisible(h.id, size.width, size.height));
586
593
  };
@@ -15,6 +15,7 @@
15
15
  import { effectiveShadow, shadowMargin } from '../core/shadow';
16
16
  import { imageCornerRadius, rectCornerRadii, traceRoundedRectPath } from '../core/roundedRect';
17
17
  import { AnimatedNode, TextNode, isTextBitmapState } from '../model/scene';
18
+ import { ElementTypes, typeKeyOf } from '../model/elementTypes';
18
19
  import { charJitterY, drawParagraphPrefix, fontDeclaration } from '../model/textLayout';
19
20
  import { drawVerticalGlyph, glyphStyleAt, verticalGlyphOps } from './verticalText';
20
21
  /** 剪影在对象线性变换下的包围盒(旋转盒 AABB:绝对投影和,保守上界;GPU 阴影路径共用) */
@@ -84,7 +85,7 @@ export const drawSilhouette = (ctx, node, color) => {
84
85
  }
85
86
  if (node.isShapeType) {
86
87
  const raw = node.raw;
87
- if (raw.type === 'ellipse' || raw.type === 'Ellipse' || raw.type === 'circle' || raw.type === 'Circle') {
88
+ if (typeKeyOf(raw) === ElementTypes.ELLIPSE || typeKeyOf(raw) === ElementTypes.CIRCLE) {
88
89
  ctx.fillStyle = color;
89
90
  ctx.beginPath();
90
91
  ctx.ellipse(0, 0, w / 2, h / 2, 0, 0, Math.PI * 2);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yft-design/engine",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "yft-design 的 WebGL2 画布引擎:接受 fabric toObject 格式 JSON,输出 GL 画布 / 位图(任意倍率 FBO 读回)/ SVG(纯数据序列化器)",
5
5
  "repository": {
6
6
  "type": "git",