@yft-design/engine 0.0.2 → 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.
@@ -46,6 +46,10 @@ export interface EngineCanvasOptions {
46
46
  background?: [number, number, number, number];
47
47
  /** 设备像素比;e2e parity 模式固定 1 */
48
48
  dpr?: number;
49
+ /** 移动端控件面(批次 354):true 时单选常规族选区右中出移动图标柄
50
+ * (fabric moveControls 的 move 控件——app fabricConf hasMobile 门引擎面;
51
+ * 宿主按 isMobile() 判定传入,引擎零 UA 耦合) */
52
+ mobileControls?: boolean;
49
53
  }
50
54
  /** 摘要类型随实现体迁至 debug/canvasInspection(批次 224),转口保持原导入路径 */
51
55
  export type { SceneNodeSummary } from './debug/canvasInspection';
@@ -86,6 +90,9 @@ export declare class EngineCanvas implements PointerHost, TextEditingHost, Sourc
86
90
  private readonly bus;
87
91
  private readonly doc;
88
92
  readonly dpr: number;
93
+ /** 移动端控件面(批次 354):public——PointerHost/OverlayTailHost 双面消费
94
+ * (pointer hitMoveControl + frameOverlay 选区覆盖层),构造期定死 */
95
+ readonly mobileControls: boolean;
89
96
  private vpt;
90
97
  private cssWidth;
91
98
  private cssHeight;
@@ -95,6 +95,9 @@ export class EngineCanvas {
95
95
  bus = new EventBus();
96
96
  doc = new EngineDocument();
97
97
  dpr;
98
+ /** 移动端控件面(批次 354):public——PointerHost/OverlayTailHost 双面消费
99
+ * (pointer hitMoveControl + frameOverlay 选区覆盖层),构造期定死 */
100
+ mobileControls;
98
101
  vpt = [1, 0, 0, 1, 0, 0];
99
102
  cssWidth = 300;
100
103
  cssHeight = 150;
@@ -172,6 +175,7 @@ export class EngineCanvas {
172
175
  // family 集 → 宿主补齐排版/度量/烘焙失效(见 fontInvalidation 的 pendingSettle)
173
176
  this.glyphAtlas = new GlyphAtlas(handle.gl, () => this.requestRenderAll(), (families) => this.fontInvalidation.queueSettle(families));
174
177
  this.dpr = options.dpr ?? (typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1);
178
+ this.mobileControls = options.mobileControls ?? false;
175
179
  this.background = options.background ?? [0, 0, 0, 0];
176
180
  this.sources = new SourceManager(this);
177
181
  this.textRenderer = new TextRenderer(handle.gl, this.batch, this.glyphAtlas);
@@ -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
  };
@@ -65,6 +65,12 @@ export declare class PointerController {
65
65
  * 锁定分支的 quad.br(app getHornControl 锁图标分支:br 且非组内),半径沿
66
66
  * 用 HANDLE_HIT_PX。命中即返回锁定节点供 fire unlock 事件 */
67
67
  hitLockControl(cssX: number, cssY: number): SceneNode | null;
68
+ /** 移动端移动控件命中(批次 354;app moveControls 的 move 控件引擎面):
69
+ * 宿主 mobileControls 门 + moveControlTarget 族判定(单选常规族/未锁),
70
+ * 位置与渲染共源 moveControlPosition(选区右中 +24 屏幕px 随姿态),命中
71
+ * 半径 MOVE_CONTROL_HIT_PX(finger 友好目标)。桌面态(mobileControls 缺席
72
+ * /false)恒 false——既有命中链零扰动 */
73
+ hitMoveControl(cssX: number, cssY: number): boolean;
68
74
  /** 四角隐形旋转区命中(批次 88;fabric baseControls tlr/trr/brr/blr +
69
75
  * Control.calcCornerCoords):每区=角点沿本地对角外偏 4 屏幕px 的中心、
70
76
  * 16×16 方形命中盒随对象角度旋转(point-in-polygon 的逆旋转回盒本地系
@@ -28,7 +28,7 @@
28
28
  import { createNode, createReferenceLineRaw, GroupNode, isReferenceLineNode, PuzzleNode, TableNode } from '../model/scene';
29
29
  import { RULER_SIZE } from '../render/ruler';
30
30
  import { buildSelectionRange, getBorderCursor, selectionBounds } from '../model/tableEdit';
31
- import { CORNER_ROTATE_CURSOR_OFFSET, CORNER_ROTATE_ZONE_PX, cornerOffsetToRadius, getActiveChildHandles, getAdaptiveSelectionHandles, getCornerRotateZones, HANDLE_HIT_PX, isImageRadiusHandleNode, isRadiusHandleNode, isUserLockedNode, radiusHandleTarget, rectCornerMaxRadius, rotateControlSpecByAngle, selectionQuadCoords } from '../render/selectionOverlay';
31
+ 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';
32
32
  import { EDGE_HANDLE_AXIS, isEdgeHandle, isRadiusHandle, RADIUS_HANDLE_CORNER } from '../model/handles';
33
33
  import { CLICK_THRESHOLD, CORNER_HANDLES, deg, DRAG_START_THRESHOLD, HANDLE_BASE_ANGLE, quadCenter, quadDims, SCALE_CURSORS } from './pointerTypes';
34
34
  import { applyMultiRotate, applyMultiScale, applyScale, buildMultiScaleSnapshot, buildScaleSnapshot } from './pointerTransform';
@@ -219,6 +219,23 @@ export class PointerController {
219
219
  const screen = this.host.toScreen(layout.quad.br.x, layout.quad.br.y);
220
220
  return Math.hypot(screen.x - cssX, screen.y - cssY) <= HANDLE_HIT_PX ? doc.selection[0] : null;
221
221
  }
222
+ /** 移动端移动控件命中(批次 354;app moveControls 的 move 控件引擎面):
223
+ * 宿主 mobileControls 门 + moveControlTarget 族判定(单选常规族/未锁),
224
+ * 位置与渲染共源 moveControlPosition(选区右中 +24 屏幕px 随姿态),命中
225
+ * 半径 MOVE_CONTROL_HIT_PX(finger 友好目标)。桌面态(mobileControls 缺席
226
+ * /false)恒 false——既有命中链零扰动 */
227
+ hitMoveControl(cssX, cssY) {
228
+ if (this.host.mobileControls !== true)
229
+ return false;
230
+ if (!moveControlTarget(this.host.document))
231
+ return false;
232
+ const layout = selectionQuadCoords(this.host.document);
233
+ if (!layout)
234
+ return false;
235
+ const pos = moveControlPosition(layout.quad, layout.angle, this.host.zoom);
236
+ const screen = this.host.toScreen(pos.x, pos.y);
237
+ return Math.hypot(screen.x - cssX, screen.y - cssY) <= MOVE_CONTROL_HIT_PX;
238
+ }
222
239
  /** 四角隐形旋转区命中(批次 88;fabric baseControls tlr/trr/brr/blr +
223
240
  * Control.calcCornerCoords):每区=角点沿本地对角外偏 4 屏幕px 的中心、
224
241
  * 16×16 方形命中盒随对象角度旋转(point-in-polygon 的逆旋转回盒本地系
@@ -364,6 +381,10 @@ export class PointerController {
364
381
  return SCALE_CURSORS[((Math.round(a / 45) % 4) + 4) % 4];
365
382
  }
366
383
  }
384
+ // 移动端移动控件光标(批次 354;app moveControls cursorStyleHandler 'move')
385
+ // ——命中序与 onPointerDown 一致(先于普通手柄;桌面态恒不命中)
386
+ if (this.hitMoveControl(cssX, cssY))
387
+ return 'move';
367
388
  const handle = this.hitHandle(cssX, cssY);
368
389
  // mtr 悬停光标 = 随对象角度转动的旋转箭头(app rotateControl
369
390
  // cursorStyleHandler 的 rotateIcon(angle+225);多选取合并框角度 = fabric AS 角度)
@@ -460,7 +481,9 @@ export class PointerController {
460
481
  // 蒙版会话是引擎侧选择:分割线手柄域不叠对象边框)
461
482
  const maskSession = doc.nodes.find((n) => n instanceof PuzzleNode && n.editingMask) ?? null;
462
483
  const sessionActive = !!this.host.cropSession || !!this.host.expandSession || !!this.host.pathSession || !!this.host.warpSession || !!maskSession;
463
- const handleFree = !this.hitHandle(cssX, cssY);
484
+ // 手柄/移动控件命中域不进悬停(app fabric findControl 命中即 target=活动
485
+ // 对象——其它对象 hover 边框不出;批次 354 move 控件并入同门)
486
+ const handleFree = !this.hitHandle(cssX, cssY) && !this.hitMoveControl(cssX, cssY);
464
487
  if (!sessionActive && handleFree) {
465
488
  const target = doc.findTarget(p.x, p.y);
466
489
  if (target instanceof GroupNode && !(target instanceof TableNode) && !(target instanceof PuzzleNode)) {
@@ -820,6 +843,24 @@ export class PointerController {
820
843
  }
821
844
  }
822
845
  }
846
+ // 1.01) 移动端移动控件(批次 354;app baseControls 的 moveControls——
847
+ // fabricConf hasMobile 门注入的常规族控件):单选常规族选区右中
848
+ // +24 屏幕px 的圆形移动图标柄,按下即起整选区 move 手势(app
849
+ // actionHandler=dragHandler 同语义——拖它=拖本体;move 手势自带
850
+ // 启动阈值+performed 门,纯点击零位移无提交)。命中先于普通手柄:
851
+ // fabric findControl 倒序里 move 排在缩放手柄后、mtr 前——mtr 与
852
+ // move 同位冲突(对象角 45°~135° 时 mtr 吸附到本地右缘=move 同位)
853
+ // move 赢(此处先判即同效);与 mr 的贴边 4px 重叠带(两心距 24、
854
+ // 半径和 28)引擎取 move——控件视觉在框外,让 mr 半径内贴边点
855
+ // 仍可拖本体语义无损。激活子手柄优先不变(1) 子柄块在前)
856
+ if (!exitedEditing && groupHandlesLive && this.hitMoveControl(cssX, cssY)) {
857
+ const node = doc.selection[0];
858
+ const snapshot = new Map();
859
+ snapshot.set(node, { left: node.raw.left ?? 0, top: node.raw.top ?? 0 });
860
+ this.gesture = { type: 'move', start: p, startCss: { x: cssX, y: cssY }, snapshot, historyBefore: captureHistoryBefore([node]) };
861
+ this.host.requestRenderAll();
862
+ return;
863
+ }
823
864
  const handle = exitedEditing || !groupHandlesLive ? null : this.hitHandle(cssX, cssY);
824
865
  if (handle) {
825
866
  if (doc.selection.length === 1) {
@@ -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)——字号
@@ -97,6 +97,11 @@ export interface PointerHost {
97
97
  };
98
98
  /** 旋转主体是激活子(覆盖只钉子手柄集,见 RotateGestureOverlay) */ onChild?: boolean;
99
99
  } | null;
100
+ /** 移动端控件面(批次 354):true 时单选常规族选区右中出移动图标柄
101
+ * (hitMoveControl/hoverCursor 消费——fabric moveControls 的 move 控件;
102
+ * EngineCanvasOptions.mobileControls 直通)。可选=单测桩宿主免实现
103
+ * (缺省无移动控件交互,桌面行为零变化) */
104
+ mobileControls?: boolean;
100
105
  }
101
106
  /** B3 扩图会话在 pointer 侧的消费面(ExpandSessionController 实现) */
102
107
  export interface ExpandSessionHandle {
@@ -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')