@yft-design/engine 0.0.0-stage → 0.0.1
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.
- package/README.md +39 -2
- package/dist/EngineCanvas.d.ts +500 -0
- package/dist/EngineCanvas.js +927 -0
- package/dist/core/canvasPerf.d.ts +23 -0
- package/dist/core/canvasPerf.js +170 -0
- package/dist/core/color.d.ts +52 -0
- package/dist/core/color.js +107 -0
- package/dist/core/distanceField.d.ts +15 -0
- package/dist/core/distanceField.js +92 -0
- package/dist/core/events.d.ts +34 -0
- package/dist/core/events.js +52 -0
- package/dist/core/gradient.d.ts +97 -0
- package/dist/core/gradient.js +175 -0
- package/dist/core/imageFilters.d.ts +150 -0
- package/dist/core/imageFilters.js +330 -0
- package/dist/core/mat2d.d.ts +151 -0
- package/dist/core/mat2d.js +241 -0
- package/dist/core/pathData.d.ts +53 -0
- package/dist/core/pathData.js +926 -0
- package/dist/core/pattern.d.ts +38 -0
- package/dist/core/pattern.js +40 -0
- package/dist/core/point.d.ts +59 -0
- package/dist/core/point.js +119 -0
- package/dist/core/psdEffects.d.ts +126 -0
- package/dist/core/psdEffects.js +158 -0
- package/dist/core/roundedRect.d.ts +62 -0
- package/dist/core/roundedRect.js +163 -0
- package/dist/core/shadow.d.ts +51 -0
- package/dist/core/shadow.js +47 -0
- package/dist/core/snap.d.ts +232 -0
- package/dist/core/snap.js +793 -0
- package/dist/core/stroke.d.ts +41 -0
- package/dist/core/stroke.js +44 -0
- package/dist/core/triangulate.d.ts +24 -0
- package/dist/core/triangulate.js +118 -0
- package/dist/debug/canvasInspection.d.ts +92 -0
- package/dist/debug/canvasInspection.js +113 -0
- package/dist/debug/pixelDiff.d.ts +22 -0
- package/dist/debug/pixelDiff.js +64 -0
- package/dist/debug/seed.d.ts +473 -0
- package/dist/debug/seed.js +3803 -0
- package/dist/decoders/gif2sprite.d.ts +9 -0
- package/dist/decoders/gif2sprite.js +84 -0
- package/dist/decoders/webp2sprite.d.ts +22 -0
- package/dist/decoders/webp2sprite.js +133 -0
- package/dist/engineFlag.d.ts +72 -0
- package/dist/engineFlag.js +86 -0
- package/dist/export/SceneExporter.d.ts +92 -0
- package/dist/export/SceneExporter.js +280 -0
- package/dist/export/glExport.d.ts +66 -0
- package/dist/export/glExport.js +79 -0
- package/dist/export/svgExport.d.ts +277 -0
- package/dist/export/svgExport.js +1790 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +48 -0
- package/dist/interact/animationPlayback.d.ts +125 -0
- package/dist/interact/animationPlayback.js +344 -0
- package/dist/interact/canvasInteractions.d.ts +50 -0
- package/dist/interact/canvasInteractions.js +150 -0
- package/dist/interact/cropSession.d.ts +123 -0
- package/dist/interact/cropSession.js +526 -0
- package/dist/interact/dblClick.d.ts +51 -0
- package/dist/interact/dblClick.js +106 -0
- package/dist/interact/expandSession.d.ts +107 -0
- package/dist/interact/expandSession.js +281 -0
- package/dist/interact/hotkeyActions.d.ts +16 -0
- package/dist/interact/hotkeyActions.js +41 -0
- package/dist/interact/pathSession.d.ts +141 -0
- package/dist/interact/pathSession.js +480 -0
- package/dist/interact/pointer.d.ts +106 -0
- package/dist/interact/pointer.js +1594 -0
- package/dist/interact/pointerTablePuzzle.d.ts +100 -0
- package/dist/interact/pointerTablePuzzle.js +358 -0
- package/dist/interact/pointerTransform.d.ts +86 -0
- package/dist/interact/pointerTransform.js +440 -0
- package/dist/interact/pointerTypes.d.ts +577 -0
- package/dist/interact/pointerTypes.js +96 -0
- package/dist/interact/snapGuide.d.ts +127 -0
- package/dist/interact/snapGuide.js +376 -0
- package/dist/interact/tableCellEditing.d.ts +61 -0
- package/dist/interact/tableCellEditing.js +198 -0
- package/dist/interact/tableInteraction.d.ts +55 -0
- package/dist/interact/tableInteraction.js +212 -0
- package/dist/interact/textEditing.d.ts +77 -0
- package/dist/interact/textEditing.js +410 -0
- package/dist/interact/warpFacade.d.ts +36 -0
- package/dist/interact/warpFacade.js +51 -0
- package/dist/interact/warpSession.d.ts +191 -0
- package/dist/interact/warpSession.js +582 -0
- package/dist/interact/wheelScroll.d.ts +62 -0
- package/dist/interact/wheelScroll.js +72 -0
- package/dist/model/alphaHit.d.ts +59 -0
- package/dist/model/alphaHit.js +262 -0
- package/dist/model/animation.d.ts +228 -0
- package/dist/model/animation.js +510 -0
- package/dist/model/arcLayout.d.ts +54 -0
- package/dist/model/arcLayout.js +307 -0
- package/dist/model/arcTextTransform.d.ts +7 -0
- package/dist/model/arcTextTransform.js +87 -0
- package/dist/model/compatEvents.d.ts +135 -0
- package/dist/model/compatEvents.js +73 -0
- package/dist/model/compatObject.d.ts +716 -0
- package/dist/model/compatObject.js +1579 -0
- package/dist/model/cropEdit.d.ts +118 -0
- package/dist/model/cropEdit.js +497 -0
- package/dist/model/document.d.ts +294 -0
- package/dist/model/document.js +572 -0
- package/dist/model/expandEdit.d.ts +93 -0
- package/dist/model/expandEdit.js +161 -0
- package/dist/model/fabricPrimitives.d.ts +156 -0
- package/dist/model/fabricPrimitives.js +9 -0
- package/dist/model/filler.d.ts +53 -0
- package/dist/model/filler.js +1 -0
- package/dist/model/groupAssemble.d.ts +7 -0
- package/dist/model/groupAssemble.js +98 -0
- package/dist/model/groupChildMove.d.ts +46 -0
- package/dist/model/groupChildMove.js +145 -0
- package/dist/model/groupResize.d.ts +78 -0
- package/dist/model/groupResize.js +108 -0
- package/dist/model/handles.d.ts +40 -0
- package/dist/model/handles.js +29 -0
- package/dist/model/imageMaskBake.d.ts +75 -0
- package/dist/model/imageMaskBake.js +136 -0
- package/dist/model/lineConstruct.d.ts +13 -0
- package/dist/model/lineConstruct.js +79 -0
- package/dist/model/maskCropEdit.d.ts +64 -0
- package/dist/model/maskCropEdit.js +90 -0
- package/dist/model/pathBackground.d.ts +51 -0
- package/dist/model/pathBackground.js +196 -0
- package/dist/model/pathConstruct.d.ts +27 -0
- package/dist/model/pathConstruct.js +55 -0
- package/dist/model/pathEdit.d.ts +114 -0
- package/dist/model/pathEdit.js +378 -0
- package/dist/model/puzzleEdit.d.ts +136 -0
- package/dist/model/puzzleEdit.js +742 -0
- package/dist/model/puzzleLayout.d.ts +91 -0
- package/dist/model/puzzleLayout.js +143 -0
- package/dist/model/scene.d.ts +1004 -0
- package/dist/model/scene.js +2841 -0
- package/dist/model/schema.d.ts +290 -0
- package/dist/model/schema.js +13 -0
- package/dist/model/shapePath.d.ts +14 -0
- package/dist/model/shapePath.js +136 -0
- package/dist/model/tableEdit.d.ts +196 -0
- package/dist/model/tableEdit.js +751 -0
- package/dist/model/tableFacade.d.ts +6 -0
- package/dist/model/tableFacade.js +808 -0
- package/dist/model/tableLayout.d.ts +85 -0
- package/dist/model/tableLayout.js +193 -0
- package/dist/model/textLayout.d.ts +357 -0
- package/dist/model/textLayout.js +822 -0
- package/dist/render/GLBlend.d.ts +40 -0
- package/dist/render/GLBlend.js +270 -0
- package/dist/render/GLContext.d.ts +25 -0
- package/dist/render/GLContext.js +48 -0
- package/dist/render/GLIsolate.d.ts +46 -0
- package/dist/render/GLIsolate.js +188 -0
- package/dist/render/GLTextureCache.d.ts +86 -0
- package/dist/render/GLTextureCache.js +187 -0
- package/dist/render/GlyphAtlas.d.ts +151 -0
- package/dist/render/GlyphAtlas.js +404 -0
- package/dist/render/MeshBatch.d.ts +123 -0
- package/dist/render/MeshBatch.js +416 -0
- package/dist/render/QuadBatch.d.ts +138 -0
- package/dist/render/QuadBatch.js +490 -0
- package/dist/render/SceneRenderer.d.ts +186 -0
- package/dist/render/SceneRenderer.js +700 -0
- package/dist/render/SourceManager.d.ts +121 -0
- package/dist/render/SourceManager.js +505 -0
- package/dist/render/TextRenderer.d.ts +140 -0
- package/dist/render/TextRenderer.js +795 -0
- package/dist/render/arcText.d.ts +40 -0
- package/dist/render/arcText.js +187 -0
- package/dist/render/batchOrder.d.ts +105 -0
- package/dist/render/batchOrder.js +168 -0
- package/dist/render/blendMode.d.ts +35 -0
- package/dist/render/blendMode.js +142 -0
- package/dist/render/clipMaskPainter.d.ts +17 -0
- package/dist/render/clipMaskPainter.js +121 -0
- package/dist/render/fontInvalidation.d.ts +25 -0
- package/dist/render/fontInvalidation.js +77 -0
- package/dist/render/fontInvalidationController.d.ts +76 -0
- package/dist/render/fontInvalidationController.js +114 -0
- package/dist/render/frameOverlay.d.ts +62 -0
- package/dist/render/frameOverlay.js +124 -0
- package/dist/render/framePipeline.d.ts +99 -0
- package/dist/render/framePipeline.js +95 -0
- package/dist/render/gpuFilterPasses.d.ts +25 -0
- package/dist/render/gpuFilterPasses.js +883 -0
- package/dist/render/gpuFx.d.ts +136 -0
- package/dist/render/gpuFx.js +614 -0
- package/dist/render/gpuImageFilters.d.ts +59 -0
- package/dist/render/gpuImageFilters.js +289 -0
- package/dist/render/gpuShadow.d.ts +52 -0
- package/dist/render/gpuShadow.js +289 -0
- package/dist/render/gradientRamp.d.ts +45 -0
- package/dist/render/gradientRamp.js +74 -0
- package/dist/render/imageEffects.d.ts +123 -0
- package/dist/render/imageEffects.js +390 -0
- package/dist/render/maskRender.d.ts +92 -0
- package/dist/render/maskRender.js +224 -0
- package/dist/render/progressiveLoad.d.ts +45 -0
- package/dist/render/progressiveLoad.js +86 -0
- package/dist/render/psdEffectPainter.d.ts +34 -0
- package/dist/render/psdEffectPainter.js +309 -0
- package/dist/render/puzzleClamp.d.ts +28 -0
- package/dist/render/puzzleClamp.js +30 -0
- package/dist/render/retainedFrame.d.ts +85 -0
- package/dist/render/retainedFrame.js +193 -0
- package/dist/render/ruler.d.ts +90 -0
- package/dist/render/ruler.js +287 -0
- package/dist/render/scrollText.d.ts +65 -0
- package/dist/render/scrollText.js +261 -0
- package/dist/render/selectionOverlay.d.ts +318 -0
- package/dist/render/selectionOverlay.js +921 -0
- package/dist/render/shaders.d.ts +38 -0
- package/dist/render/shaders.js +314 -0
- package/dist/render/shadowBake.d.ts +43 -0
- package/dist/render/shadowBake.js +202 -0
- package/dist/render/shadowPainter.d.ts +13 -0
- package/dist/render/shadowPainter.js +80 -0
- package/dist/render/sharedGpuPainters.d.ts +25 -0
- package/dist/render/sharedGpuPainters.js +40 -0
- package/dist/render/sourceHydration.d.ts +12 -0
- package/dist/render/sourceHydration.js +48 -0
- package/dist/render/strokeBake.d.ts +85 -0
- package/dist/render/strokeBake.js +515 -0
- package/dist/render/strokePainter.d.ts +28 -0
- package/dist/render/strokePainter.js +119 -0
- package/dist/render/strokeSdf.d.ts +35 -0
- package/dist/render/strokeSdf.js +74 -0
- package/dist/render/svgRaster.d.ts +46 -0
- package/dist/render/svgRaster.js +71 -0
- package/dist/render/tableOverlay.d.ts +38 -0
- package/dist/render/tableOverlay.js +233 -0
- package/dist/render/textHighlight.d.ts +117 -0
- package/dist/render/textHighlight.js +380 -0
- package/dist/render/textureUpload.d.ts +18 -0
- package/dist/render/textureUpload.js +26 -0
- package/dist/render/verticalText.d.ts +38 -0
- package/dist/render/verticalText.js +63 -0
- package/dist/render/warpText.d.ts +58 -0
- package/dist/render/warpText.js +380 -0
- package/dist/render/workspaceBackdrop.d.ts +35 -0
- package/dist/render/workspaceBackdrop.js +71 -0
- package/dist/render/workspaceChecker.d.ts +54 -0
- package/dist/render/workspaceChecker.js +170 -0
- package/dist/render/workspaceGlow.d.ts +51 -0
- package/dist/render/workspaceGlow.js +171 -0
- package/package.json +39 -3
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 形状描边 SDF 直绘的 eligibility 谓词与参数打包(GS 工程,2026-10-09 立项,
|
|
3
|
+
* docs/2026-10-09_stroke-sdf-painter-plan.md)。
|
|
4
|
+
*
|
|
5
|
+
* 把 rect/line/ellipse 三族的描边从 Canvas2D 烘焙改为着色器解析式 SDF
|
|
6
|
+
* (shaders.ts strokeCoverage):分辨率无关、缩放/平移零重烘零重传、零纹理
|
|
7
|
+
* 显存。参数经 QuadBatch 现有 18-float 实例布局复用槽位直通(aUv=形状参数,
|
|
8
|
+
* aRadius=(halfW, −code)——码取负与填充圆角实例的 ry≥0 判别),批合并/z 序/
|
|
9
|
+
* 增量上传/保留帧重放零改动。
|
|
10
|
+
*
|
|
11
|
+
* 回落烘焙门(返回 null 走 strokePainter 原链,stale 协议不动):dash 全族、
|
|
12
|
+
* alignment inside/outside(应用的 destination-out 残留 parity 单独立项)、
|
|
13
|
+
* path/polygon/polyline/triangle/arrow/Dimension/referenceline 族、直角 rect
|
|
14
|
+
* 的 join≠miter 或 miterLimit<1.5(bevel/round 角语义 Chebyshev 盒不承接)、
|
|
15
|
+
* 零长线段、非有限端点/尺寸。
|
|
16
|
+
*/
|
|
17
|
+
import type { StrokeDecl } from '../core/stroke';
|
|
18
|
+
import type { SceneNode } from '../model/scene';
|
|
19
|
+
export interface StrokeSdfParams {
|
|
20
|
+
/** aRadius 槽:本地(non-uniform)/声明(uniform)半笔宽——着色器按位分流 */
|
|
21
|
+
halfW: number;
|
|
22
|
+
/** aRadius 槽:描边码取负(与填充圆角实例 ry≥0 判别) */
|
|
23
|
+
code: number;
|
|
24
|
+
/** aUv 槽(直通 vShape):rect=(rx,ry,hx,hy) / line=(x1,y1,x2,y2) / ellipse=(0,0,hx,hy) */
|
|
25
|
+
shape: [number, number, number, number];
|
|
26
|
+
/** quad 尺寸(对象 dims + 2×margin;实例矩阵=对象矩阵,vLocal 含 margin 求值区) */
|
|
27
|
+
quadW: number;
|
|
28
|
+
quadH: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* eligibility 与打包:不合形态返回 null(调用方回落烘焙链)。
|
|
32
|
+
* zoom/dpr 与烘焙路径同源(host.zoom×host.dpr;导出期 applyExportViewport
|
|
33
|
+
* 换入的导出 vpt 自动跟随)——uniform 笔宽与烘焙分辨率换算共用同一 k。
|
|
34
|
+
*/
|
|
35
|
+
export declare const strokeSdfParams: (node: SceneNode, decl: StrokeDecl, zoom: number, dpr: number) => StrokeSdfParams | null;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { rectCornerRadii } from '../core/roundedRect';
|
|
2
|
+
/** 描边码位段:kind(0-2) | cap(3-5) | penUniform(6)——与 strokeCoverage 解码一致 */
|
|
3
|
+
const STROKE_KIND_RECT = 1;
|
|
4
|
+
const STROKE_KIND_LINE = 2;
|
|
5
|
+
const STROKE_KIND_ELLIPSE = 3;
|
|
6
|
+
const CAP_INDEX = { butt: 0, round: 1, square: 2 };
|
|
7
|
+
/** Chebyshev 盒角在 90° 恒 ≤ miterLimit×(w/2) 的安全下限(√2≈1.414) */
|
|
8
|
+
const MITER_SAFE_LIMIT = 1.5;
|
|
9
|
+
/**
|
|
10
|
+
* eligibility 与打包:不合形态返回 null(调用方回落烘焙链)。
|
|
11
|
+
* zoom/dpr 与烘焙路径同源(host.zoom×host.dpr;导出期 applyExportViewport
|
|
12
|
+
* 换入的导出 vpt 自动跟随)——uniform 笔宽与烘焙分辨率换算共用同一 k。
|
|
13
|
+
*/
|
|
14
|
+
export const strokeSdfParams = (node, decl, zoom, dpr) => {
|
|
15
|
+
if (decl.dashArray)
|
|
16
|
+
return null;
|
|
17
|
+
if (decl.alignment !== 'center')
|
|
18
|
+
return null;
|
|
19
|
+
const raw = node.raw;
|
|
20
|
+
const type = typeof raw.type === 'string' ? raw.type.toLowerCase() : '';
|
|
21
|
+
const dims = node.dims;
|
|
22
|
+
// rect/ellipse 须正尺寸;line 的 bbox 允许单轴为零(水平/垂直线最常见形态,
|
|
23
|
+
// margin 使 quad 两轴恒正)
|
|
24
|
+
if (type !== 'line' && (!(dims.x > 0) || !(dims.y > 0)))
|
|
25
|
+
return null;
|
|
26
|
+
const cap = CAP_INDEX[decl.lineCap] ?? 0;
|
|
27
|
+
const code = (type === 'line' ? STROKE_KIND_LINE : type === 'ellipse' || type === 'circle' ? STROKE_KIND_ELLIPSE : STROKE_KIND_RECT) + (cap << 3) + (decl.uniform ? 64 : 0);
|
|
28
|
+
const halfW = decl.width / 2;
|
|
29
|
+
let shape;
|
|
30
|
+
if (type === 'rect' || type === 'fabricrect') {
|
|
31
|
+
// 圆角与填充 quad 同源归一(rectCornerRadii:FabricRect 视觉 radius 反算/
|
|
32
|
+
// 单写 rx 提升 ry/钳半宽高)——角语义与批次 98 填充角天然同口径
|
|
33
|
+
const r = rectCornerRadii(raw, dims.x, dims.y);
|
|
34
|
+
const rx = r?.rx ?? 0;
|
|
35
|
+
const ry = r?.ry ?? 0;
|
|
36
|
+
// 直角(Chebyshev 盒)= canvas 90° miter 尖精确等价;join≠miter 或
|
|
37
|
+
// miterLimit 过低(bevel 截断)不承接。圆角路径角区平滑,join 无语义不设门
|
|
38
|
+
if (rx < 1e-4 && ry < 1e-4 && (decl.lineJoin !== 'miter' || decl.miterLimit < MITER_SAFE_LIMIT))
|
|
39
|
+
return null;
|
|
40
|
+
shape = [rx, ry, dims.x / 2, dims.y / 2];
|
|
41
|
+
}
|
|
42
|
+
else if (type === 'line') {
|
|
43
|
+
const x1 = Number(raw.x1);
|
|
44
|
+
const y1 = Number(raw.y1);
|
|
45
|
+
const x2 = Number(raw.x2);
|
|
46
|
+
const y2 = Number(raw.y2);
|
|
47
|
+
if (!Number.isFinite(x1) || !Number.isFinite(y1) || !Number.isFinite(x2) || !Number.isFinite(y2))
|
|
48
|
+
return null;
|
|
49
|
+
if (x1 === x2 && y1 === y2)
|
|
50
|
+
return null;
|
|
51
|
+
shape = [x1, y1, x2, y2];
|
|
52
|
+
}
|
|
53
|
+
else if (type === 'ellipse' || type === 'circle') {
|
|
54
|
+
shape = [0, 0, dims.x / 2, dims.y / 2];
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
// margin:本地半宽(uniform 笔宽的本地等价=halfW/minAxis)+ AA 余量(4 设备
|
|
60
|
+
// 像素折算本地单位)。Chebyshev 方角/方帽沿两轴各伸半宽、square 帽沿轴伸 hh
|
|
61
|
+
// ——均被同一 margin 覆盖(minAxis 是最劣方向)
|
|
62
|
+
const m = node.matrix;
|
|
63
|
+
const k = Math.max(1e-6, zoom * dpr);
|
|
64
|
+
const axis0 = Math.hypot(m[0], m[1]);
|
|
65
|
+
const axis1 = Math.hypot(m[2], m[3]);
|
|
66
|
+
const minAxis = Math.max(Math.min(axis0, axis1), 1e-6);
|
|
67
|
+
const localPerDevicePx = 1 / (minAxis * k);
|
|
68
|
+
const margin = (decl.uniform ? halfW / minAxis : halfW) + 4 * localPerDevicePx;
|
|
69
|
+
const quadW = dims.x + 2 * margin;
|
|
70
|
+
const quadH = dims.y + 2 * margin;
|
|
71
|
+
if (!Number.isFinite(quadW) || !Number.isFinite(quadH))
|
|
72
|
+
return null;
|
|
73
|
+
return { halfW, code: -code, shape, quadW, quadH };
|
|
74
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SVG 源按需重光栅化(批次 39——用户反馈「二维码/条形码 zoom 放大后模糊」)。
|
|
3
|
+
*
|
|
4
|
+
* 根因:二维码/条形码(QRCode/BarCode extends FabricImage)的 src 是
|
|
5
|
+
* data:image/svg+xml 位图化前的矢量——fabric Canvas2D 的 drawImage 直接吃
|
|
6
|
+
* <img src=svg>,浏览器按**当前变换**光栅化矢量,任意放大恒清晰;引擎纹理
|
|
7
|
+
* 是一次性上传的位图(LINEAR 采样),<img> 的自然尺寸(二维码 118×118)就是
|
|
8
|
+
* 纹理分辨率,放大 = 低分辨率纹理上采样 → 糊。
|
|
9
|
+
*
|
|
10
|
+
* 对齐语义:SVG 源按「本帧需要的设备像素尺寸」(自然尺寸 × |worldScale| ×
|
|
11
|
+
* zoom × dpr 的最长边口径)重光栅化到离屏 canvas,纹理改吃 canvas;位图源
|
|
12
|
+
* (png/jpeg)没有更高分辨率可挖,语义不变(原样返回 imageEl)。
|
|
13
|
+
*
|
|
14
|
+
* 分桶(2 的幂):factor ≡ 覆盖需求的最小 2 的幂(封顶 maxRasterPx 桶),
|
|
15
|
+
* 连续 zoom 手势内重光栅次数 = 跨桶数(对数级),桶内需求波动零重光栅。
|
|
16
|
+
* 升/降档都在桶边界单交叉点触发(bucket 用 ratio−ε 防浮点抖档)——二维码
|
|
17
|
+
* 级源图重光栅是微秒级 drawImage + 小纹理上传,边界往返的成本可忽略;
|
|
18
|
+
* factor 1 = 不建 canvas,纹理即原 <img>(1× 光栅与 img 等价)。
|
|
19
|
+
*
|
|
20
|
+
* drawImage(img-svg, 0,0, w,h) 到 canvas:Chromium/FF/Safari 现代版均按目标
|
|
21
|
+
* 尺寸重光栅化矢量(非先位图化再拉伸)——这是本方案成立的前提。
|
|
22
|
+
*/
|
|
23
|
+
export interface SvgRasterSize {
|
|
24
|
+
w: number;
|
|
25
|
+
h: number;
|
|
26
|
+
}
|
|
27
|
+
export interface SvgRasterPlan {
|
|
28
|
+
/** 光栅化倍率(相对自然尺寸):恒 ≥1 的 2 的幂;1 = 用原 <img> 不建 canvas */
|
|
29
|
+
factor: number;
|
|
30
|
+
/** true = 桶位变化需重光栅化;false = 维持现状(现 canvas 或原 <img>) */
|
|
31
|
+
needsRaster: boolean;
|
|
32
|
+
}
|
|
33
|
+
/** 单边光栅化上限(px):min(MAX_TEXTURE_SIZE, 4096) 由调用方钳制后传入;
|
|
34
|
+
* 4096² RGBA+mip ≈ 85MiB 是单张二维码级源图可接受的上界 */
|
|
35
|
+
export declare const SVG_RASTER_MAX_PX = 4096;
|
|
36
|
+
/** 源是否 SVG:data URL(base64/URI 编码两形态)或 .svg 路径(容忍 query/fragment) */
|
|
37
|
+
export declare const isSvgSource: (src: unknown) => boolean;
|
|
38
|
+
/**
|
|
39
|
+
* 光栅化桶位决策(纯函数):
|
|
40
|
+
* - needed = 自然尺寸 × |worldScale| × zoom × dpr(调用方算好传入)
|
|
41
|
+
* - factor = 覆盖 ratio 的最小 2 的幂,封顶 cap 桶;与现桶不同即需重光栅
|
|
42
|
+
* (升档补清晰度,降档回收显存——二维码级源图两者都是微秒级成本)
|
|
43
|
+
*/
|
|
44
|
+
export declare const planSvgRaster: (natural: SvgRasterSize, needed: SvgRasterSize, currentFactor: number, maxRasterPx?: number) => SvgRasterPlan;
|
|
45
|
+
/** SVG <img> 按倍率重光栅化到离屏 canvas(目标尺寸矢量重光栅,非位图拉伸) */
|
|
46
|
+
export declare const rasterizeSvgImage: (img: HTMLImageElement, factor: number) => HTMLCanvasElement;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SVG 源按需重光栅化(批次 39——用户反馈「二维码/条形码 zoom 放大后模糊」)。
|
|
3
|
+
*
|
|
4
|
+
* 根因:二维码/条形码(QRCode/BarCode extends FabricImage)的 src 是
|
|
5
|
+
* data:image/svg+xml 位图化前的矢量——fabric Canvas2D 的 drawImage 直接吃
|
|
6
|
+
* <img src=svg>,浏览器按**当前变换**光栅化矢量,任意放大恒清晰;引擎纹理
|
|
7
|
+
* 是一次性上传的位图(LINEAR 采样),<img> 的自然尺寸(二维码 118×118)就是
|
|
8
|
+
* 纹理分辨率,放大 = 低分辨率纹理上采样 → 糊。
|
|
9
|
+
*
|
|
10
|
+
* 对齐语义:SVG 源按「本帧需要的设备像素尺寸」(自然尺寸 × |worldScale| ×
|
|
11
|
+
* zoom × dpr 的最长边口径)重光栅化到离屏 canvas,纹理改吃 canvas;位图源
|
|
12
|
+
* (png/jpeg)没有更高分辨率可挖,语义不变(原样返回 imageEl)。
|
|
13
|
+
*
|
|
14
|
+
* 分桶(2 的幂):factor ≡ 覆盖需求的最小 2 的幂(封顶 maxRasterPx 桶),
|
|
15
|
+
* 连续 zoom 手势内重光栅次数 = 跨桶数(对数级),桶内需求波动零重光栅。
|
|
16
|
+
* 升/降档都在桶边界单交叉点触发(bucket 用 ratio−ε 防浮点抖档)——二维码
|
|
17
|
+
* 级源图重光栅是微秒级 drawImage + 小纹理上传,边界往返的成本可忽略;
|
|
18
|
+
* factor 1 = 不建 canvas,纹理即原 <img>(1× 光栅与 img 等价)。
|
|
19
|
+
*
|
|
20
|
+
* drawImage(img-svg, 0,0, w,h) 到 canvas:Chromium/FF/Safari 现代版均按目标
|
|
21
|
+
* 尺寸重光栅化矢量(非先位图化再拉伸)——这是本方案成立的前提。
|
|
22
|
+
*/
|
|
23
|
+
/** 单边光栅化上限(px):min(MAX_TEXTURE_SIZE, 4096) 由调用方钳制后传入;
|
|
24
|
+
* 4096² RGBA+mip ≈ 85MiB 是单张二维码级源图可接受的上界 */
|
|
25
|
+
export const SVG_RASTER_MAX_PX = 4096;
|
|
26
|
+
/** 源是否 SVG:data URL(base64/URI 编码两形态)或 .svg 路径(容忍 query/fragment) */
|
|
27
|
+
export const isSvgSource = (src) => {
|
|
28
|
+
if (typeof src !== 'string' || src.length === 0)
|
|
29
|
+
return false;
|
|
30
|
+
if (/^data:image\/svg\+xml/i.test(src))
|
|
31
|
+
return true;
|
|
32
|
+
return /\.svg(?:[?#]|$)/i.test(src);
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* 光栅化桶位决策(纯函数):
|
|
36
|
+
* - needed = 自然尺寸 × |worldScale| × zoom × dpr(调用方算好传入)
|
|
37
|
+
* - factor = 覆盖 ratio 的最小 2 的幂,封顶 cap 桶;与现桶不同即需重光栅
|
|
38
|
+
* (升档补清晰度,降档回收显存——二维码级源图两者都是微秒级成本)
|
|
39
|
+
*/
|
|
40
|
+
export const planSvgRaster = (natural, needed, currentFactor, maxRasterPx = SVG_RASTER_MAX_PX) => {
|
|
41
|
+
const natMax = Math.max(natural.w, natural.h);
|
|
42
|
+
if (!(natMax > 0) || !(currentFactor >= 1))
|
|
43
|
+
return { factor: 1, needsRaster: false };
|
|
44
|
+
const ratio = Math.max(needed.w / natural.w, needed.h / natural.h);
|
|
45
|
+
if (!(ratio > 0) || !Number.isFinite(ratio))
|
|
46
|
+
return { factor: 1, needsRaster: false };
|
|
47
|
+
// 封顶桶:最大 2 的幂 ≤ maxRasterPx / 最长自然边(恒 ≥1)
|
|
48
|
+
let cap = 1;
|
|
49
|
+
while (cap * 2 * natMax <= maxRasterPx)
|
|
50
|
+
cap *= 2;
|
|
51
|
+
// 需求桶:最小 2 的幂 ≥ ratio(epsilon 防 2.0 边界浮点抖档)
|
|
52
|
+
let target = 1;
|
|
53
|
+
while (target < ratio - 1e-9 && target < cap)
|
|
54
|
+
target *= 2;
|
|
55
|
+
return target === currentFactor ? { factor: currentFactor, needsRaster: false } : { factor: target, needsRaster: true };
|
|
56
|
+
};
|
|
57
|
+
/** SVG <img> 按倍率重光栅化到离屏 canvas(目标尺寸矢量重光栅,非位图拉伸) */
|
|
58
|
+
export const rasterizeSvgImage = (img, factor) => {
|
|
59
|
+
const natW = img.naturalWidth || img.width;
|
|
60
|
+
const natH = img.naturalHeight || img.height;
|
|
61
|
+
const canvas = document.createElement('canvas');
|
|
62
|
+
canvas.width = Math.max(1, Math.round(natW * factor));
|
|
63
|
+
canvas.height = Math.max(1, Math.round(natH * factor));
|
|
64
|
+
const ctx = canvas.getContext('2d');
|
|
65
|
+
if (ctx) {
|
|
66
|
+
ctx.imageSmoothingEnabled = true;
|
|
67
|
+
ctx.imageSmoothingQuality = 'high';
|
|
68
|
+
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
|
|
69
|
+
}
|
|
70
|
+
return canvas;
|
|
71
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 表格单元格覆盖层(main-webgl2 P4-4b)。
|
|
3
|
+
*
|
|
4
|
+
* 消费 TableNode 的交互态(selectedCells/hoveredBorder/hoveredIndicator/
|
|
5
|
+
* indicatorVisible,pointer + tableInteraction 驱动)产出 OverlayQuad:
|
|
6
|
+
* - 选中格:半透明蓝填充 + 四边描边(主格按 span 范围取合并区域矩形,
|
|
7
|
+
* 本地系 quad 经 node.matrix 跟随表格旋转/缩放;线宽按对象缩放补偿、
|
|
8
|
+
* zoom 换算保持屏幕恒定像素)
|
|
9
|
+
* - 悬停/拖拽边框:本地系竖/横线两端经 node.matrix 投到场景系,屏幕恒定线宽
|
|
10
|
+
* (拖拽期 position 可带钳制 overscroll 反馈偏移)
|
|
11
|
+
* - 行/列选择条(应用 renderTableSelectRow/ColumnControl):左缘/顶缘外
|
|
12
|
+
* TABLE_STRIP_EXTENT **屏幕恒定** px(本地 20/(zoom·|scale|) 按轴换算——
|
|
13
|
+
* 缩放/zoom 下外延不随对象生长,同指示器/选中手柄口径;应用现行 20·scale·
|
|
14
|
+
* zoom 随缩放生长,属有意偏差)、行高/列宽方向随表格走;悬停或该行/列被
|
|
15
|
+
* 选区覆盖(rowColCoverage,span 覆盖语义)时高亮蓝 #1890ff80,常态
|
|
16
|
+
* #eeeeee80;选中期间恒渲染(应用 controls 可见性,非指示器的邻近门控)
|
|
17
|
+
* - 左上角拖动把手(应用 renderTableDragControl):角外屏幕恒定 20×20 方块 +
|
|
18
|
+
* 汉堡线 sprite(2× 采样抗放大糊)
|
|
19
|
+
* - 加号指示器:**只画悬停中的那一条**(应用 drawInsertIndicator:无悬停即
|
|
20
|
+
* return,边框拖拽中不画 _isDraggingBorder;悬停边框线或命中圆都会出现),
|
|
21
|
+
* 边框位置沿表格上/左外偏(与 tableEdit 命中口径同源——content 尺寸不含
|
|
22
|
+
* cellStrokeWidth),圆+十字 sprite 经 GLTextureCache 上传成贴图 quad,
|
|
23
|
+
* 命中圆时用反色变体;尺寸按 SPRITE_PX/(zoom·|scale|) 换算保持屏幕恒定
|
|
24
|
+
* 大小、随表格姿态旋转;画在条带/把手**之上**(应用 drawInsertIndicator
|
|
25
|
+
* 在 drawControls 末尾,圆浮于条带——整排常显会把圆压在常显条带上,与应用
|
|
26
|
+
* 不符)
|
|
27
|
+
* - 选区右下角扩展柄(引擎侧增强,非应用同构):Excel 填充柄语义——拖动以
|
|
28
|
+
* 选区左上角为锚扩展矩形选区,免 shift 按键;尺寸/结构与元素 controls 手柄
|
|
29
|
+
* 同构(HANDLE_SIZE_PX 双层外蓝内白,用户 2026-09-24 反馈对齐)骑在选区
|
|
30
|
+
* 包围盒右下角,悬停整体变蓝;编辑态/全选不画
|
|
31
|
+
*
|
|
32
|
+
* 覆盖层只在单选表格时由 EngineCanvas 附加(选区生命周期保证非选中表格
|
|
33
|
+
* 无单元格态),不参与场景渲染——parity 对比前 clearSelection 即随选区消失。
|
|
34
|
+
*/
|
|
35
|
+
import type { TableNode } from '../model/scene';
|
|
36
|
+
import { type OverlayQuad } from './selectionOverlay';
|
|
37
|
+
/** 表格覆盖层:选中格填充/描边 + 悬停边框线 + 加号指示器 + 行/列选择条 + 拖动把手 */
|
|
38
|
+
export declare const buildTableOverlay: (node: TableNode, zoom: number) => OverlayQuad[];
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 表格单元格覆盖层(main-webgl2 P4-4b)。
|
|
3
|
+
*
|
|
4
|
+
* 消费 TableNode 的交互态(selectedCells/hoveredBorder/hoveredIndicator/
|
|
5
|
+
* indicatorVisible,pointer + tableInteraction 驱动)产出 OverlayQuad:
|
|
6
|
+
* - 选中格:半透明蓝填充 + 四边描边(主格按 span 范围取合并区域矩形,
|
|
7
|
+
* 本地系 quad 经 node.matrix 跟随表格旋转/缩放;线宽按对象缩放补偿、
|
|
8
|
+
* zoom 换算保持屏幕恒定像素)
|
|
9
|
+
* - 悬停/拖拽边框:本地系竖/横线两端经 node.matrix 投到场景系,屏幕恒定线宽
|
|
10
|
+
* (拖拽期 position 可带钳制 overscroll 反馈偏移)
|
|
11
|
+
* - 行/列选择条(应用 renderTableSelectRow/ColumnControl):左缘/顶缘外
|
|
12
|
+
* TABLE_STRIP_EXTENT **屏幕恒定** px(本地 20/(zoom·|scale|) 按轴换算——
|
|
13
|
+
* 缩放/zoom 下外延不随对象生长,同指示器/选中手柄口径;应用现行 20·scale·
|
|
14
|
+
* zoom 随缩放生长,属有意偏差)、行高/列宽方向随表格走;悬停或该行/列被
|
|
15
|
+
* 选区覆盖(rowColCoverage,span 覆盖语义)时高亮蓝 #1890ff80,常态
|
|
16
|
+
* #eeeeee80;选中期间恒渲染(应用 controls 可见性,非指示器的邻近门控)
|
|
17
|
+
* - 左上角拖动把手(应用 renderTableDragControl):角外屏幕恒定 20×20 方块 +
|
|
18
|
+
* 汉堡线 sprite(2× 采样抗放大糊)
|
|
19
|
+
* - 加号指示器:**只画悬停中的那一条**(应用 drawInsertIndicator:无悬停即
|
|
20
|
+
* return,边框拖拽中不画 _isDraggingBorder;悬停边框线或命中圆都会出现),
|
|
21
|
+
* 边框位置沿表格上/左外偏(与 tableEdit 命中口径同源——content 尺寸不含
|
|
22
|
+
* cellStrokeWidth),圆+十字 sprite 经 GLTextureCache 上传成贴图 quad,
|
|
23
|
+
* 命中圆时用反色变体;尺寸按 SPRITE_PX/(zoom·|scale|) 换算保持屏幕恒定
|
|
24
|
+
* 大小、随表格姿态旋转;画在条带/把手**之上**(应用 drawInsertIndicator
|
|
25
|
+
* 在 drawControls 末尾,圆浮于条带——整排常显会把圆压在常显条带上,与应用
|
|
26
|
+
* 不符)
|
|
27
|
+
* - 选区右下角扩展柄(引擎侧增强,非应用同构):Excel 填充柄语义——拖动以
|
|
28
|
+
* 选区左上角为锚扩展矩形选区,免 shift 按键;尺寸/结构与元素 controls 手柄
|
|
29
|
+
* 同构(HANDLE_SIZE_PX 双层外蓝内白,用户 2026-09-24 反馈对齐)骑在选区
|
|
30
|
+
* 包围盒右下角,悬停整体变蓝;编辑态/全选不画
|
|
31
|
+
*
|
|
32
|
+
* 覆盖层只在单选表格时由 EngineCanvas 附加(选区生命周期保证非选中表格
|
|
33
|
+
* 无单元格态),不参与场景渲染——parity 对比前 clearSelection 即随选区消失。
|
|
34
|
+
*/
|
|
35
|
+
import { multiply, transformPoint } from '../core/mat2d';
|
|
36
|
+
import { getContentBoundsForRange, rowColCoverage, TABLE_INDICATOR_OFFSET, TABLE_INDICATOR_RADIUS, TABLE_STRIP_EXTENT } from '../model/tableEdit';
|
|
37
|
+
import { BORDER_PX, HANDLE_SIZE_PX, lineQuad, SELECTION_BLUE } from './selectionOverlay';
|
|
38
|
+
const BLUE = SELECTION_BLUE;
|
|
39
|
+
const CELL_FILL = [BLUE[0], BLUE[1], BLUE[2], 0.14];
|
|
40
|
+
const WHITE = [1, 1, 1, 1];
|
|
41
|
+
/** 悬停边框线宽(屏幕 px;比选区边框略粗以区分) */
|
|
42
|
+
const BORDER_LINE_PX = 2;
|
|
43
|
+
/** 选择条常态/高亮(应用 renderTableSelect*Control 的 #eeeeee80 / #1890ff80) */
|
|
44
|
+
const STRIP_IDLE = [238 / 255, 238 / 255, 238 / 255, 128 / 255];
|
|
45
|
+
const STRIP_ACTIVE = [24 / 255, 144 / 255, 1, 128 / 255];
|
|
46
|
+
/** 指示器 sprite 画布尺寸(逻辑 px;圆半径 = TABLE_INDICATOR_RADIUS 与命中口径一致) */
|
|
47
|
+
const SPRITE_PX = 20;
|
|
48
|
+
/** 拖动把手 sprite 逻辑边长(本地 20×20 quad;2× 采样) */
|
|
49
|
+
const HANDLE_PX = 20;
|
|
50
|
+
let spriteCache = null;
|
|
51
|
+
/** 圆+十字 sprite(模块级缓存;jsdom 无 2D 上下文时退化为空图,单测只断言几何) */
|
|
52
|
+
const getIndicatorSprites = () => {
|
|
53
|
+
if (spriteCache)
|
|
54
|
+
return spriteCache;
|
|
55
|
+
const make = (hover) => {
|
|
56
|
+
const canvas = document.createElement('canvas');
|
|
57
|
+
canvas.width = SPRITE_PX;
|
|
58
|
+
canvas.height = SPRITE_PX;
|
|
59
|
+
const ctx = canvas.getContext('2d');
|
|
60
|
+
if (!ctx)
|
|
61
|
+
return canvas;
|
|
62
|
+
const center = SPRITE_PX / 2;
|
|
63
|
+
ctx.beginPath();
|
|
64
|
+
ctx.arc(center, center, TABLE_INDICATOR_RADIUS, 0, Math.PI * 2);
|
|
65
|
+
ctx.fillStyle = hover ? '#2f6fed' : '#ffffff';
|
|
66
|
+
ctx.fill();
|
|
67
|
+
ctx.lineWidth = 1.5;
|
|
68
|
+
ctx.strokeStyle = '#2f6fed';
|
|
69
|
+
ctx.stroke();
|
|
70
|
+
const arm = 4;
|
|
71
|
+
ctx.beginPath();
|
|
72
|
+
ctx.moveTo(center - arm, center);
|
|
73
|
+
ctx.lineTo(center + arm, center);
|
|
74
|
+
ctx.moveTo(center, center - arm);
|
|
75
|
+
ctx.lineTo(center, center + arm);
|
|
76
|
+
ctx.lineWidth = 1.5;
|
|
77
|
+
ctx.strokeStyle = hover ? '#ffffff' : '#2f6fed';
|
|
78
|
+
ctx.stroke();
|
|
79
|
+
return canvas;
|
|
80
|
+
};
|
|
81
|
+
spriteCache = { normal: make(false), hover: make(true) };
|
|
82
|
+
return spriteCache;
|
|
83
|
+
};
|
|
84
|
+
const contentWidthOf = (view) => view.columnWidths.reduce((s, w) => s + w, 0) + (view.cols - 1) * view.cellSpacing;
|
|
85
|
+
const contentHeightOf = (view) => view.rowHeights.reduce((s, h) => s + h, 0) + (view.rows - 1) * view.cellSpacing;
|
|
86
|
+
/** 行/列在 content 左上原点系的起点(前缀和,含 spacing) */
|
|
87
|
+
const spanStart = (sizes, spacing, index) => {
|
|
88
|
+
let pos = 0;
|
|
89
|
+
for (let i = 0; i < index; i++)
|
|
90
|
+
pos += sizes[i] + spacing;
|
|
91
|
+
return pos;
|
|
92
|
+
};
|
|
93
|
+
let handleSpriteCache = null;
|
|
94
|
+
/** 拖动把手 sprite(方块 + 三横线汉堡;2× 采样抗放大糊。应用 renderTableDragControl:
|
|
95
|
+
* 内缘留 1px 缝避开表格角、悬停底色 #1890ff20、线 #888888/#1890ff) */
|
|
96
|
+
const getHandleSprites = () => {
|
|
97
|
+
if (handleSpriteCache)
|
|
98
|
+
return handleSpriteCache;
|
|
99
|
+
const make = (hover) => {
|
|
100
|
+
const canvas = document.createElement('canvas');
|
|
101
|
+
canvas.width = HANDLE_PX * 2;
|
|
102
|
+
canvas.height = HANDLE_PX * 2;
|
|
103
|
+
const ctx = canvas.getContext('2d');
|
|
104
|
+
if (!ctx)
|
|
105
|
+
return canvas;
|
|
106
|
+
ctx.scale(2, 2);
|
|
107
|
+
// 方块 [0, 0, 19, 19]:右/下内缘留 1px 缝(应用 gap=1)
|
|
108
|
+
ctx.fillStyle = hover ? '#1890ff20' : '#eeeeee99';
|
|
109
|
+
ctx.fillRect(0, 0, HANDLE_PX - 1, HANDLE_PX - 1);
|
|
110
|
+
// 汉堡三横线居中(应用 lineHalfWidth=size*0.25 / lineGap=size*0.18 / lineWidth 1.5)
|
|
111
|
+
const cx = HANDLE_PX / 2 - 0.5;
|
|
112
|
+
const cy = HANDLE_PX / 2 - 0.5;
|
|
113
|
+
const half = HANDLE_PX * 0.25;
|
|
114
|
+
const gap = HANDLE_PX * 0.18;
|
|
115
|
+
ctx.strokeStyle = hover ? '#1890ff' : '#888888';
|
|
116
|
+
ctx.lineWidth = 1.5;
|
|
117
|
+
ctx.lineCap = 'round';
|
|
118
|
+
for (let i = -1; i <= 1; i++) {
|
|
119
|
+
ctx.beginPath();
|
|
120
|
+
ctx.moveTo(cx - half, cy + i * gap);
|
|
121
|
+
ctx.lineTo(cx + half, cy + i * gap);
|
|
122
|
+
ctx.stroke();
|
|
123
|
+
}
|
|
124
|
+
return canvas;
|
|
125
|
+
};
|
|
126
|
+
handleSpriteCache = { normal: make(false), hover: make(true) };
|
|
127
|
+
return handleSpriteCache;
|
|
128
|
+
};
|
|
129
|
+
/** 表格覆盖层:选中格填充/描边 + 悬停边框线 + 加号指示器 + 行/列选择条 + 拖动把手 */
|
|
130
|
+
export const buildTableOverlay = (node, zoom) => {
|
|
131
|
+
const quads = [];
|
|
132
|
+
const view = node.tableView;
|
|
133
|
+
const map = node.cellMap;
|
|
134
|
+
const m = node.matrix;
|
|
135
|
+
const scale = node.objectScale;
|
|
136
|
+
const halfW = contentWidthOf(view) / 2;
|
|
137
|
+
const halfH = contentHeightOf(view) / 2;
|
|
138
|
+
// 1) 选中格(主格按 span 范围取合并区域矩形;从格/被覆盖缺格 skip——
|
|
139
|
+
// map 已补全从格条目,主格一次画整个合并区域,从格再画会在区域中间出竖线)
|
|
140
|
+
const tX = BORDER_PX / zoom / Math.max(scale.x, 1e-6);
|
|
141
|
+
const tY = BORDER_PX / zoom / Math.max(scale.y, 1e-6);
|
|
142
|
+
for (const cell of node.selectedCells) {
|
|
143
|
+
const data = map.get(`${cell.row},${cell.col}`);
|
|
144
|
+
if (data?.isMerged)
|
|
145
|
+
continue;
|
|
146
|
+
const rowspan = data?.rowspan ?? 1;
|
|
147
|
+
const colspan = data?.colspan ?? 1;
|
|
148
|
+
const b = getContentBoundsForRange(view, { r1: cell.row, r2: cell.row + rowspan - 1, c1: cell.col, c2: cell.col + colspan - 1 });
|
|
149
|
+
const cx = b.left + b.width / 2;
|
|
150
|
+
const cy = b.top + b.height / 2;
|
|
151
|
+
quads.push({ matrix: multiply(m, [1, 0, 0, 1, cx, cy]), dims: { x: b.width, y: b.height }, color: CELL_FILL });
|
|
152
|
+
// 四边描边:水平边厚度走 y 轴、垂直边走 x 轴(各自按对象缩放补偿),角部延 tX/tY 补缝
|
|
153
|
+
quads.push({ matrix: multiply(m, [1, 0, 0, 1, cx, b.top]), dims: { x: b.width + 2 * tX, y: tY }, color: BLUE });
|
|
154
|
+
quads.push({ matrix: multiply(m, [1, 0, 0, 1, cx, b.top + b.height]), dims: { x: b.width + 2 * tX, y: tY }, color: BLUE });
|
|
155
|
+
quads.push({ matrix: multiply(m, [1, 0, 0, 1, b.left, cy]), dims: { x: tX, y: b.height + 2 * tY }, color: BLUE });
|
|
156
|
+
quads.push({ matrix: multiply(m, [1, 0, 0, 1, b.left + b.width, cy]), dims: { x: tX, y: b.height + 2 * tY }, color: BLUE });
|
|
157
|
+
}
|
|
158
|
+
// 2) 悬停/拖拽边框线(本地两端投场景系,屏幕恒定线宽)
|
|
159
|
+
if (node.hoveredBorder) {
|
|
160
|
+
const { type, position } = node.hoveredBorder;
|
|
161
|
+
const p1 = type === 'col' ? transformPoint(m, position, -halfH) : transformPoint(m, -halfW, position);
|
|
162
|
+
const p2 = type === 'col' ? transformPoint(m, position, halfH) : transformPoint(m, halfW, position);
|
|
163
|
+
quads.push(lineQuad(p1, p2, BORDER_LINE_PX / zoom, BLUE));
|
|
164
|
+
}
|
|
165
|
+
// 3) 行/列选择条(选中期间恒渲染;组盒含 cellStrokeWidth——应用 positionHandler 用 dim)。
|
|
166
|
+
// 外延 = 屏幕恒定 20px(本地 20/(zoom·|scale|),同指示器/手柄口径——缩放/zoom
|
|
167
|
+
// 下不随对象生长);行高/列宽方向随表格走(罩住整行/整列)
|
|
168
|
+
const left = -node.dims.x / 2;
|
|
169
|
+
const top = -node.dims.y / 2;
|
|
170
|
+
const extX = TABLE_STRIP_EXTENT / (zoom * Math.max(scale.x, 1e-6));
|
|
171
|
+
const extY = TABLE_STRIP_EXTENT / (zoom * Math.max(scale.y, 1e-6));
|
|
172
|
+
const coverage = rowColCoverage(map, node.selectedCells);
|
|
173
|
+
for (let r = 0; r < view.rows; r++) {
|
|
174
|
+
const y0 = spanStart(view.rowHeights, view.cellSpacing, r) - halfH;
|
|
175
|
+
const h = view.rowHeights[r];
|
|
176
|
+
const active = node.hoveredStrip?.kind === 'row' && node.hoveredStrip.index === r ? true : coverage.rows.has(r);
|
|
177
|
+
quads.push({ matrix: multiply(m, [1, 0, 0, 1, left - extX / 2, y0 + h / 2]), dims: { x: extX, y: h }, color: active ? STRIP_ACTIVE : STRIP_IDLE });
|
|
178
|
+
}
|
|
179
|
+
for (let c = 0; c < view.cols; c++) {
|
|
180
|
+
const x0 = spanStart(view.columnWidths, view.cellSpacing, c) - halfW;
|
|
181
|
+
const w = view.columnWidths[c];
|
|
182
|
+
const active = node.hoveredStrip?.kind === 'col' && node.hoveredStrip.index === c ? true : coverage.cols.has(c);
|
|
183
|
+
quads.push({ matrix: multiply(m, [1, 0, 0, 1, x0 + w / 2, top - extY / 2]), dims: { x: w, y: extY }, color: active ? STRIP_ACTIVE : STRIP_IDLE });
|
|
184
|
+
}
|
|
185
|
+
// 4) 左上角拖动把手(屏幕恒定 20×20——本地按轴换算;应用 createDragControl)
|
|
186
|
+
{
|
|
187
|
+
const sprites = getHandleSprites();
|
|
188
|
+
quads.push({
|
|
189
|
+
matrix: multiply(m, [1, 0, 0, 1, left - extX / 2, top - extY / 2]),
|
|
190
|
+
dims: { x: extX, y: extY },
|
|
191
|
+
color: WHITE,
|
|
192
|
+
texture: node.hoveredDragHandle ? sprites.hover : sprites.normal
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
// 5) 加号指示器——**只画悬停中的那一条**(应用 drawInsertIndicator:无悬停
|
|
196
|
+
// 即 return;悬停边框线或命中指示器圆都会出现——getBorderOrIndicatorAtPoint
|
|
197
|
+
// 两个分支同写 _hoveredBorder;边框拖拽中不画 _isDraggingBorder)。画在
|
|
198
|
+
// 条带/把手之上(drawControls 末尾层序,圆浮于条带)
|
|
199
|
+
const hoverBorder = node.hoveredIndicator ?? (node.borderDragging ? null : node.hoveredBorder);
|
|
200
|
+
if (hoverBorder) {
|
|
201
|
+
const sprites = getIndicatorSprites();
|
|
202
|
+
const isCol = hoverBorder.type === 'col';
|
|
203
|
+
quads.push({
|
|
204
|
+
matrix: multiply(m, [1, 0, 0, 1, isCol ? hoverBorder.position : -halfW - TABLE_INDICATOR_OFFSET, isCol ? -halfH - TABLE_INDICATOR_OFFSET : hoverBorder.position]),
|
|
205
|
+
dims: { x: SPRITE_PX / (zoom * Math.max(scale.x, 1e-6)), y: SPRITE_PX / (zoom * Math.max(scale.y, 1e-6)) },
|
|
206
|
+
color: WHITE,
|
|
207
|
+
texture: node.hoveredIndicator ? sprites.hover : sprites.normal
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
// 6) 选区右下角扩展柄(引擎侧增强,非应用同构——Excel 填充柄语义):拖动以
|
|
211
|
+
// 选区左上角为锚扩展矩形选区(pointer 的 table-range-drag),免 shift 按键。
|
|
212
|
+
// 骑在选区包围盒右下角(getContentBoundsForRange,cellRange 缺失按
|
|
213
|
+
// selectedCells 重算——TableNode.selectionBoundsRect),尺寸/结构与元素
|
|
214
|
+
// controls 手柄完全同构(用户 2026-09-24 反馈对齐):HANDLE_SIZE_PX 双层
|
|
215
|
+
// quad 外蓝内白(pushHandleQuads 同款——白衬底上纯白会隐身)、屏幕恒定、
|
|
216
|
+
// 命中半径同 HANDLE_HIT_PX 口径;悬停整体变蓝。编辑态/全选不画(编辑期
|
|
217
|
+
// 单元格 UI 由文本编辑接管;全选无扩展空间且柄与 br 缩放手柄同域——让位,
|
|
218
|
+
// 命中侧同条件)
|
|
219
|
+
if (node.selectedCells.length && !node.editingCell && !node.isFullCellSelection) {
|
|
220
|
+
const b = node.selectionBoundsRect;
|
|
221
|
+
if (b) {
|
|
222
|
+
const hx = b.left + b.width;
|
|
223
|
+
const hy = b.top + b.height;
|
|
224
|
+
const hsX = HANDLE_SIZE_PX / zoom / Math.max(scale.x, 1e-6);
|
|
225
|
+
const hsY = HANDLE_SIZE_PX / zoom / Math.max(scale.y, 1e-6);
|
|
226
|
+
const inX = (HANDLE_SIZE_PX - 2 * BORDER_PX) / zoom / Math.max(scale.x, 1e-6);
|
|
227
|
+
const inY = (HANDLE_SIZE_PX - 2 * BORDER_PX) / zoom / Math.max(scale.y, 1e-6);
|
|
228
|
+
quads.push({ matrix: multiply(m, [1, 0, 0, 1, hx, hy]), dims: { x: hsX, y: hsY }, color: BLUE });
|
|
229
|
+
quads.push({ matrix: multiply(m, [1, 0, 0, 1, hx, hy]), dims: { x: inX, y: inY }, color: node.hoveredRangeHandle ? BLUE : WHITE });
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return quads;
|
|
233
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文字划重点(批次62):应用定制 Textbox._renderHighlight(主仓
|
|
3
|
+
* extension/object/Textbox.ts 1466-1767)的引擎承接。
|
|
4
|
+
*
|
|
5
|
+
* 数据面:raw.texts = [{ text, highlight?: { type:'svg', svgInfo } }]——compat 面
|
|
6
|
+
* setTexts 直写已久(数据持久化供 fabric 模式往返),本模块补引擎渲染消费。
|
|
7
|
+
*
|
|
8
|
+
* 两段式:
|
|
9
|
+
* 1. highlightRuns / planTextHighlight —— 纯函数(jsdom 可测):段 → 视觉行/
|
|
10
|
+
* 字符盒区间切分(fabric 索引数学逐行复刻,含行尾虚拟游标盒)→ 本地系
|
|
11
|
+
* 绘制计划(变换矩阵 + 画笔参数 + 出血余量)。
|
|
12
|
+
* 2. bakeTextHighlight —— 浏览器面:按计划在 canvas2d 上 Path2D 绘制(fabric
|
|
13
|
+
* 同一光栅器语义,线帽/拐角不设值=canvas 缺省 butt/miter,fabric
|
|
14
|
+
* _renderHighlight 亦不设置——TextMark 配置里的 round 不生效是双栈共同 quirk)。
|
|
15
|
+
*
|
|
16
|
+
* 已知边界:
|
|
17
|
+
* - 竖排(raw.vertical)不承接——fabric 侧行/列 charBounds 语义存疑,登记缺口;
|
|
18
|
+
* - 阴影/PSD 特效剪影不含划重点墨迹(fabric _renderHighlight 在阴影域外,同构);
|
|
19
|
+
* - SVG 导出序列化面不消费 texts(双栈同侪)。
|
|
20
|
+
*/
|
|
21
|
+
import type { CharBox, TextLayout, TextLineLayout } from '../model/textLayout';
|
|
22
|
+
/** fabric highlight.svgInfo 子集(ElementMark getSvgInfo 写入形态) */
|
|
23
|
+
export interface HighlightSvgInfo {
|
|
24
|
+
stroke?: string;
|
|
25
|
+
fill?: string;
|
|
26
|
+
path?: string;
|
|
27
|
+
strokeWidth?: number;
|
|
28
|
+
isFill?: boolean;
|
|
29
|
+
isSingle?: boolean;
|
|
30
|
+
scale?: number;
|
|
31
|
+
alignVertical?: string;
|
|
32
|
+
}
|
|
33
|
+
/** raw.texts 段(兼容缺 highlight 的裸段;url 型高亮只做占位——切分按非 svg 跳过) */
|
|
34
|
+
export interface TextsSegmentLike {
|
|
35
|
+
text: string;
|
|
36
|
+
highlight?: {
|
|
37
|
+
type?: string;
|
|
38
|
+
url?: string;
|
|
39
|
+
svgInfo?: HighlightSvgInfo;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** 一段高亮落在某一视觉行上的区间(box 序为行内 grapheme 盒序) */
|
|
43
|
+
export interface HighlightRun {
|
|
44
|
+
lineIndex: number;
|
|
45
|
+
/** 起字盒序(含) */
|
|
46
|
+
start: number;
|
|
47
|
+
/** 止字盒序(不含)——行末段 = 末字盒序+1,可为 boxes.length(虚拟尾盒) */
|
|
48
|
+
end: number;
|
|
49
|
+
info: HighlightSvgInfo;
|
|
50
|
+
}
|
|
51
|
+
/** 一条 Path2D 绘制指令(本地中心系) */
|
|
52
|
+
export interface HighlightDrawOp {
|
|
53
|
+
d: string;
|
|
54
|
+
translateX: number;
|
|
55
|
+
translateY: number;
|
|
56
|
+
scaleX: number;
|
|
57
|
+
scaleY: number;
|
|
58
|
+
isFill: boolean;
|
|
59
|
+
fill: string;
|
|
60
|
+
stroke: string;
|
|
61
|
+
strokeWidth: number;
|
|
62
|
+
}
|
|
63
|
+
export interface HighlightPlan {
|
|
64
|
+
ops: HighlightDrawOp[];
|
|
65
|
+
/** 画布四向余量(本地像素)——墨迹溢出内容盒的量(isSingle scale>1 超出字盒/
|
|
66
|
+
* 描边出血/贴边段),fabric 无裁剪同构,烘焙画布须容下 */
|
|
67
|
+
padX: number;
|
|
68
|
+
padY: number;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 应用定制 _measureLine 的行尾游标盒(主仓 Textbox.ts 1319-1325):
|
|
72
|
+
* left = 末字盒 left+width、宽 0、height = 对象级 fontSize。fabric 整行段的
|
|
73
|
+
* width = curCharBoxs[end].left − startBox.left 依赖它(原生 fabric 无此盒,
|
|
74
|
+
* 越界抛错被 try/catch 吞成全跳——应用补盒后整行段是主路径)。
|
|
75
|
+
*/
|
|
76
|
+
export declare const trailingCharBox: (line: TextLineLayout, objectFontSize: number) => CharBox;
|
|
77
|
+
/**
|
|
78
|
+
* 段 → 视觉行/盒区间切分(fabric _renderHighlight 1480-1610 复刻)。
|
|
79
|
+
*
|
|
80
|
+
* 索引语义(与 fabric 同名变量一一对应):
|
|
81
|
+
* - indexLineMap / index2IndexOfLine:grapheme 平铺序 → (视觉行号, 行内盒序);
|
|
82
|
+
* - fullTextToLineIndexMap:text 的 **code unit** → grapheme 平铺序('\n' → -1;
|
|
83
|
+
* 计数器按 code unit 递增——代理对字符双耗 grapheme 槽位的漂移是 fabric
|
|
84
|
+
* 原 quirk,复刻不修)。
|
|
85
|
+
*
|
|
86
|
+
* 守卫同 fabric:Σ段长 ≠ text.length(code unit)整跳;非 svg highlight 跳段;
|
|
87
|
+
* '\n' 单独段只推 idx。fabric 对查表越界段有 start=0 兜底/no-end-index 跳过的
|
|
88
|
+
* 杂路(仅双重换行等病态段触达),此处统一按跳过处理(正常 UI 不会生成)。
|
|
89
|
+
*/
|
|
90
|
+
export declare const highlightRuns: (text: string, layout: TextLayout, texts: TextsSegmentLike[]) => HighlightRun[];
|
|
91
|
+
/**
|
|
92
|
+
* 绘制计划:runs → 本地中心系 op 列表 + 出血余量。
|
|
93
|
+
*
|
|
94
|
+
* 本地系与字形管线同构:lineLeft = −layout.width/2 + line.leftOffset、
|
|
95
|
+
* 行顶 y = contentTopY + line.top(contentTopY = −dims.y/2,可能深于
|
|
96
|
+
* −layout.height/2——盒被 mt/mb 抬高时内容块上移,计划不假设居中)。
|
|
97
|
+
*
|
|
98
|
+
* span 模式(fabric 1722-1762):整段拉伸——scaleX = 段宽/path宽、
|
|
99
|
+
* scaleY = 行字高/boxHeight(top/bottom 档按 pathBottom 参考高重算)、
|
|
100
|
+
* translate 使 path 盒对齐段矩形左上(alignVertical 三档)。
|
|
101
|
+
* isSingle 模式(fabric 1667-1719):首子路径逐字重复——uniformScale =
|
|
102
|
+
* min(字宽/path宽, 字高/pathHeight)×svgInfo.scale、水平居中、跳空白字;
|
|
103
|
+
* bottom 档走 fabric 特有的 cTop+cHeight−box.top×s 式(非 getAlignedTranslateY)。
|
|
104
|
+
*/
|
|
105
|
+
export declare const planTextHighlight: (text: string, layout: TextLayout, texts: TextsSegmentLike[], contentTopY: number, objectFontSize: number) => HighlightPlan | null;
|
|
106
|
+
export interface BakedHighlight {
|
|
107
|
+
canvas: HTMLCanvasElement;
|
|
108
|
+
logicalW: number;
|
|
109
|
+
logicalH: number;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* canvas2d 烘焙:计划 → 纹理源。画布覆盖本地矩形
|
|
113
|
+
* [−(layout.width/2+padX), +] × [contentTopY−padY, contentTopY+layout.height+padY]
|
|
114
|
+
* (y 向锚内容块顶——盒抬高时 quad 由调用方按 contentTopY 偏心推送)。
|
|
115
|
+
* scale = 分桶(同字形/虚线烘焙口径,超采样防放大糊)。
|
|
116
|
+
*/
|
|
117
|
+
export declare const bakeTextHighlight: (plan: HighlightPlan, layout: TextLayout, contentTopY: number, scale: number) => BakedHighlight | null;
|