@yft-design/engine 0.0.3 → 0.0.5

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.
@@ -0,0 +1,295 @@
1
+ /**
2
+ * 智能对象置入层透视光栅烘焙(批次 363 自主仓 extension/object/FabricSmartObject.ts 迁居,
3
+ * 逐式 verbatim、仅剥 import.meta.env.DEV 调试日志——引擎构建无 vite env 注入)。
4
+ *
5
+ * PSD placed layer 的 smartObject 元数据携带 8 元组 quad(nonAffineTransform 优先、
6
+ * transform 兜底)——超出仿射的透视形变 fabric 时代无法渲染,主仓把子文档合成画布
7
+ * 经 quad 预光栅成普通图片 src 写回对象(template store 智能对象同步管线唯一消费方,
8
+ * 批次 257/258 建链)。迁居引擎后 parity 一源(同 imageMaskBake 先例):后续 PS 智能
9
+ * 对象新形态(变形/网格变换,warpvas 同族)在引擎侧统一承接;GPU 原生透视渲染
10
+ * (非破坏性编辑,免预光栅)就绪后经 render/ 落地,quad 数学同源复用 core/homography。
11
+ *
12
+ * 口径(迁居零行为变化):
13
+ * - 仿射 quad(br ≈ tr + bl − tl)→ setTransform 直绘;
14
+ * - 透视 quad → 逐像素反投射双线性采样;无 2d 上下文/奇异单应回退网格三角剖分
15
+ * (drawAffineTriangle 逐格 clip + setTransform 近似);
16
+ * - objectBounds 在 quad 外接框内 → 裁剪出 object 可见子区域;跨坐标系(object 在
17
+ * group 内或经 workspace 偏移)→ 整 quad 缩放到 object 尺寸;
18
+ * - 编码优先 canvas.toBlob(Chromium 后台线程编码,大画布 webp 同步编码实测阻塞
19
+ * 主线程 ~1s;主线程只剩 FileReader 读 base64),不可用/返回空回退同步 toDataURL。
20
+ */
21
+ import { getQuadBounds, getSmartObjectTransformQuad, getSquareToQuadHomography, invertHomography, isAffineQuad, offsetQuad, projectPoint } from '../core/homography';
22
+ const DEFAULT_GRID_SIZE = 32;
23
+ const MAX_GRID_COUNT = 120;
24
+ const EPSILON = 0.000001;
25
+ const createCanvasElement = () => {
26
+ const element = document.createElement('canvas');
27
+ if (!element || typeof element.getContext === 'undefined') {
28
+ throw new Error('Failed to create `canvas` element');
29
+ }
30
+ return element;
31
+ };
32
+ const copyCanvasElement = (canvas) => {
33
+ const newCanvas = createCanvasElement();
34
+ newCanvas.width = canvas.width;
35
+ newCanvas.height = canvas.height;
36
+ newCanvas.getContext('2d', { willReadFrequently: true })?.drawImage(canvas, 0, 0);
37
+ return newCanvas;
38
+ };
39
+ const toDataURL = (canvasEl, format, quality) => canvasEl.toDataURL?.(`image/${format}`, quality);
40
+ const readBlobAsDataURL = (blob) => new Promise((resolve, reject) => {
41
+ const reader = new FileReader();
42
+ reader.onload = () => resolve(String(reader.result));
43
+ reader.onerror = () => reject(reader.error);
44
+ reader.readAsDataURL(blob);
45
+ });
46
+ /** toDataURL 的异步版:优先 canvas.toBlob(离线程编码),不可用/返回空回退同步 toDataURL */
47
+ const toDataURLAsync = async (canvasEl, format, quality) => {
48
+ try {
49
+ const blob = await new Promise((resolve) => canvasEl.toBlob(resolve, `image/${format}`, quality));
50
+ if (blob)
51
+ return await readBlobAsDataURL(blob);
52
+ }
53
+ catch {
54
+ // 跨域污染等异常走同步兜底(同样会抛,由调用方处理)
55
+ }
56
+ return toDataURL(canvasEl, format, quality);
57
+ };
58
+ /** 源画布重采样到 smartObject 记录的文档精确尺寸(canvas 像素可能受 retina 缩放影响) */
59
+ const createLogicalSourceCanvas = (sourceCanvas, width, height) => {
60
+ const canvasWidth = Math.max(1, sourceCanvas.width);
61
+ const canvasHeight = Math.max(1, sourceCanvas.height);
62
+ const logicalWidth = Math.max(1, Math.round(width));
63
+ const logicalHeight = Math.max(1, Math.round(height));
64
+ if (Math.abs(canvasWidth - logicalWidth) < EPSILON && Math.abs(canvasHeight - logicalHeight) < EPSILON) {
65
+ return sourceCanvas;
66
+ }
67
+ const logicalCanvas = document.createElement('canvas');
68
+ logicalCanvas.width = logicalWidth;
69
+ logicalCanvas.height = logicalHeight;
70
+ const ctx = logicalCanvas.getContext('2d');
71
+ if (!ctx)
72
+ return sourceCanvas;
73
+ ctx.imageSmoothingEnabled = true;
74
+ ctx.imageSmoothingQuality = 'high';
75
+ ctx.drawImage(sourceCanvas, 0, 0, canvasWidth, canvasHeight, 0, 0, logicalWidth, logicalHeight);
76
+ return logicalCanvas;
77
+ };
78
+ const sampleBilinear = (sourceData, width, height, x, y) => {
79
+ const sx = Math.max(0, Math.min(width - 1, x));
80
+ const sy = Math.max(0, Math.min(height - 1, y));
81
+ const x0 = Math.floor(sx);
82
+ const y0 = Math.floor(sy);
83
+ const x1 = Math.min(width - 1, x0 + 1);
84
+ const y1 = Math.min(height - 1, y0 + 1);
85
+ const tx = sx - x0;
86
+ const ty = sy - y0;
87
+ const i00 = (y0 * width + x0) * 4;
88
+ const i10 = (y0 * width + x1) * 4;
89
+ const i01 = (y1 * width + x0) * 4;
90
+ const i11 = (y1 * width + x1) * 4;
91
+ const top = 1 - ty;
92
+ const left = 1 - tx;
93
+ const w00 = left * top;
94
+ const w10 = tx * top;
95
+ const w01 = left * ty;
96
+ const w11 = tx * ty;
97
+ return [
98
+ sourceData[i00] * w00 + sourceData[i10] * w10 + sourceData[i01] * w01 + sourceData[i11] * w11,
99
+ sourceData[i00 + 1] * w00 + sourceData[i10 + 1] * w10 + sourceData[i01 + 1] * w01 + sourceData[i11 + 1] * w11,
100
+ sourceData[i00 + 2] * w00 + sourceData[i10 + 2] * w10 + sourceData[i01 + 2] * w01 + sourceData[i11 + 2] * w11,
101
+ sourceData[i00 + 3] * w00 + sourceData[i10 + 3] * w10 + sourceData[i01 + 3] * w01 + sourceData[i11 + 3] * w11
102
+ ];
103
+ };
104
+ /** 逐像素反投射透视光栅:输出画布每像素经逆单应映射回源图双线性采样(真透视,非网格近似) */
105
+ const renderPerspectivePixels = (ctx, sourceCanvas, quad) => {
106
+ const homography = getSquareToQuadHomography(quad);
107
+ const inverseHomography = homography ? invertHomography(homography) : undefined;
108
+ if (!inverseHomography) {
109
+ renderPerspectiveMesh(ctx, sourceCanvas, quad, DEFAULT_GRID_SIZE);
110
+ return;
111
+ }
112
+ const sourceWidth = Math.max(1, sourceCanvas.width);
113
+ const sourceHeight = Math.max(1, sourceCanvas.height);
114
+ const sourceCtx = sourceCanvas.getContext('2d', { willReadFrequently: true });
115
+ if (!sourceCtx) {
116
+ renderPerspectiveMesh(ctx, sourceCanvas, quad, DEFAULT_GRID_SIZE);
117
+ return;
118
+ }
119
+ const sourceImageData = sourceCtx.getImageData(0, 0, sourceWidth, sourceHeight);
120
+ const outputImageData = ctx.createImageData(ctx.canvas.width, ctx.canvas.height);
121
+ const outputData = outputImageData.data;
122
+ for (let y = 0; y < ctx.canvas.height; y++) {
123
+ for (let x = 0; x < ctx.canvas.width; x++) {
124
+ const sourcePoint = projectPoint(inverseHomography, x + 0.5, y + 0.5);
125
+ if (sourcePoint.x < 0 || sourcePoint.x > 1 || sourcePoint.y < 0 || sourcePoint.y > 1) {
126
+ continue;
127
+ }
128
+ const sourceX = sourcePoint.x * (sourceWidth - 1);
129
+ const sourceY = sourcePoint.y * (sourceHeight - 1);
130
+ const rgba = sampleBilinear(sourceImageData.data, sourceWidth, sourceHeight, sourceX, sourceY);
131
+ const index = (y * ctx.canvas.width + x) * 4;
132
+ outputData[index] = rgba[0];
133
+ outputData[index + 1] = rgba[1];
134
+ outputData[index + 2] = rgba[2];
135
+ outputData[index + 3] = rgba[3];
136
+ }
137
+ }
138
+ ctx.putImageData(outputImageData, 0, 0);
139
+ };
140
+ /** 仿射三角剖分近似透视:源/目标三角形三点定仿射,clip 后 setTransform 绘源图 */
141
+ const drawAffineTriangle = (ctx, sourceCanvas, source, destination) => {
142
+ const [s0, s1, s2] = source;
143
+ const [d0, d1, d2] = destination;
144
+ const denominator = s0.x * (s1.y - s2.y) + s1.x * (s2.y - s0.y) + s2.x * (s0.y - s1.y);
145
+ if (Math.abs(denominator) < EPSILON)
146
+ return;
147
+ const a = (d0.x * (s1.y - s2.y) + d1.x * (s2.y - s0.y) + d2.x * (s0.y - s1.y)) / denominator;
148
+ const b = (d0.y * (s1.y - s2.y) + d1.y * (s2.y - s0.y) + d2.y * (s0.y - s1.y)) / denominator;
149
+ const c = (d0.x * (s2.x - s1.x) + d1.x * (s0.x - s2.x) + d2.x * (s1.x - s0.x)) / denominator;
150
+ const d = (d0.y * (s2.x - s1.x) + d1.y * (s0.x - s2.x) + d2.y * (s1.x - s0.x)) / denominator;
151
+ const e = (d0.x * (s1.x * s2.y - s2.x * s1.y) + d1.x * (s2.x * s0.y - s0.x * s2.y) + d2.x * (s0.x * s1.y - s1.x * s0.y)) / denominator;
152
+ const f = (d0.y * (s1.x * s2.y - s2.x * s1.y) + d1.y * (s2.x * s0.y - s0.x * s2.y) + d2.y * (s0.x * s1.y - s1.x * s0.y)) / denominator;
153
+ ctx.save();
154
+ ctx.beginPath();
155
+ ctx.moveTo(d0.x, d0.y);
156
+ ctx.lineTo(d1.x, d1.y);
157
+ ctx.lineTo(d2.x, d2.y);
158
+ ctx.closePath();
159
+ ctx.clip();
160
+ ctx.setTransform(a, b, c, d, e, f);
161
+ ctx.drawImage(sourceCanvas, 0, 0);
162
+ ctx.restore();
163
+ };
164
+ /** 网格三角剖分兜底(无 2d 读位/奇异单应时):源面按 maxGridSize 分格逐格双三角仿射近似 */
165
+ const renderPerspectiveMesh = (ctx, sourceCanvas, quad, maxGridSize) => {
166
+ const homography = getSquareToQuadHomography(quad);
167
+ if (!homography) {
168
+ ctx.drawImage(sourceCanvas, 0, 0, ctx.canvas.width, ctx.canvas.height);
169
+ return;
170
+ }
171
+ const sourceWidth = Math.max(1, sourceCanvas.width);
172
+ const sourceHeight = Math.max(1, sourceCanvas.height);
173
+ const columns = Math.min(MAX_GRID_COUNT, Math.max(1, Math.ceil(sourceWidth / maxGridSize)));
174
+ const rows = Math.min(MAX_GRID_COUNT, Math.max(1, Math.ceil(sourceHeight / maxGridSize)));
175
+ for (let row = 0; row < rows; row++) {
176
+ const y0 = row / rows;
177
+ const y1 = (row + 1) / rows;
178
+ const sy0 = y0 * sourceHeight;
179
+ const sy1 = y1 * sourceHeight;
180
+ for (let col = 0; col < columns; col++) {
181
+ const x0 = col / columns;
182
+ const x1 = (col + 1) / columns;
183
+ const sx0 = x0 * sourceWidth;
184
+ const sx1 = x1 * sourceWidth;
185
+ const p00 = projectPoint(homography, x0, y0);
186
+ const p10 = projectPoint(homography, x1, y0);
187
+ const p11 = projectPoint(homography, x1, y1);
188
+ const p01 = projectPoint(homography, x0, y1);
189
+ drawAffineTriangle(ctx, sourceCanvas, [
190
+ { x: sx0, y: sy0 },
191
+ { x: sx1, y: sy0 },
192
+ { x: sx1, y: sy1 }
193
+ ], [p00, p10, p11]);
194
+ drawAffineTriangle(ctx, sourceCanvas, [
195
+ { x: sx0, y: sy0 },
196
+ { x: sx1, y: sy1 },
197
+ { x: sx0, y: sy1 }
198
+ ], [p00, p11, p01]);
199
+ }
200
+ }
201
+ };
202
+ /**
203
+ * 置入层智能对象光栅:子文档合成画布经 smartObject quad(仿射/透视)烘焙成普通图片。
204
+ * 无 quad(无变换元数据)时源画布原样编码返回。
205
+ */
206
+ export const renderPlacedSmartObjectLayer = async (sourceCanvas, smartObject, options = {}) => {
207
+ const quality = options.quality ?? 0.92;
208
+ const format = options.format || 'webp';
209
+ const canvasWidth = Math.max(1, sourceCanvas.width);
210
+ const canvasHeight = Math.max(1, sourceCanvas.height);
211
+ // 优先使用 smartObject 存储的内部文档尺寸,而非 canvas 像素尺寸
212
+ // canvas 尺寸可能受 retina 缩放等因素影响,而 smartObject.width/height 是 PSD 中记录的精确值
213
+ const sourceWidth = Math.max(1, smartObject?.width || canvasWidth);
214
+ const sourceHeight = Math.max(1, smartObject?.height || canvasHeight);
215
+ const logicalSourceCanvas = createLogicalSourceCanvas(sourceCanvas, sourceWidth, sourceHeight);
216
+ const quad = getSmartObjectTransformQuad(smartObject?.nonAffineTransform || smartObject?.transform);
217
+ if (!quad) {
218
+ const canvas = copyCanvasElement(sourceCanvas);
219
+ return {
220
+ src: await toDataURLAsync(canvas, format, quality),
221
+ width: canvasWidth,
222
+ height: canvasHeight,
223
+ sourceWidth,
224
+ sourceHeight
225
+ };
226
+ }
227
+ const quadBounds = getQuadBounds(quad);
228
+ const localQuad = offsetQuad(quad, -quadBounds.minX, -quadBounds.minY);
229
+ const objectBounds = options.objectBounds;
230
+ // 在 quadBounds 尺寸的 canvas 上完整渲染
231
+ const quadCanvas = document.createElement('canvas');
232
+ quadCanvas.width = quadBounds.width;
233
+ quadCanvas.height = quadBounds.height;
234
+ const ctx = quadCanvas.getContext('2d');
235
+ if (!ctx)
236
+ throw new Error('无法创建智能对象渲染画布');
237
+ ctx.imageSmoothingEnabled = true;
238
+ ctx.imageSmoothingQuality = 'high';
239
+ if (isAffineQuad(localQuad)) {
240
+ const a = (localQuad.tr.x - localQuad.tl.x) / sourceWidth;
241
+ const b = (localQuad.tr.y - localQuad.tl.y) / sourceWidth;
242
+ const c = (localQuad.bl.x - localQuad.tl.x) / sourceHeight;
243
+ const d = (localQuad.bl.y - localQuad.tl.y) / sourceHeight;
244
+ const e = localQuad.tl.x;
245
+ const f = localQuad.tl.y;
246
+ ctx.setTransform(a, b, c, d, e, f);
247
+ ctx.drawImage(logicalSourceCanvas, 0, 0);
248
+ }
249
+ else {
250
+ renderPerspectivePixels(ctx, logicalSourceCanvas, localQuad);
251
+ }
252
+ // 决定输出策略:裁剪还是缩放
253
+ let outputCanvas;
254
+ if (objectBounds) {
255
+ const cropX = Math.round(objectBounds.left - quadBounds.minX);
256
+ const cropY = Math.round(objectBounds.top - quadBounds.minY);
257
+ const cropW = Math.max(1, Math.round(objectBounds.width));
258
+ const cropH = Math.max(1, Math.round(objectBounds.height));
259
+ // 判断 object 是否在 quad 内部(同一坐标系下)
260
+ const canCrop = cropX >= 0 && cropY >= 0 && cropX + cropW <= quadBounds.width + 1 && cropY + cropH <= quadBounds.height + 1;
261
+ if (canCrop) {
262
+ // object 是 quad 的子区域 → 裁剪出 object 可见部分
263
+ outputCanvas = document.createElement('canvas');
264
+ outputCanvas.width = cropW;
265
+ outputCanvas.height = cropH;
266
+ const cropCtx = outputCanvas.getContext('2d');
267
+ if (cropCtx) {
268
+ cropCtx.drawImage(quadCanvas, cropX, cropY, cropW, cropH, 0, 0, cropW, cropH);
269
+ }
270
+ }
271
+ else {
272
+ // 坐标不在同一空间(object 在 group 内或经过 workspace 偏移)→ 缩放整个 quad 到 object 尺寸
273
+ outputCanvas = document.createElement('canvas');
274
+ outputCanvas.width = cropW;
275
+ outputCanvas.height = cropH;
276
+ const scaleCtx = outputCanvas.getContext('2d');
277
+ if (scaleCtx) {
278
+ scaleCtx.imageSmoothingEnabled = true;
279
+ scaleCtx.imageSmoothingQuality = 'high';
280
+ scaleCtx.drawImage(quadCanvas, 0, 0, quadBounds.width, quadBounds.height, 0, 0, cropW, cropH);
281
+ }
282
+ }
283
+ }
284
+ else {
285
+ outputCanvas = quadCanvas;
286
+ }
287
+ return {
288
+ // toBlob 离线程编码:2267×2333 webp 同步编码实测阻塞主线程 ~1s,异步化后主线程只剩 FileReader
289
+ src: await toDataURLAsync(outputCanvas, format, quality),
290
+ width: outputCanvas.width,
291
+ height: outputCanvas.height,
292
+ sourceWidth,
293
+ sourceHeight
294
+ };
295
+ };
@@ -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.5",
4
4
  "description": "yft-design 的 WebGL2 画布引擎:接受 fabric toObject 格式 JSON,输出 GL 画布 / 位图(任意倍率 FBO 读回)/ SVG(纯数据序列化器)",
5
5
  "repository": {
6
6
  "type": "git",