@yft-design/engine 0.0.9 → 0.0.11
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/dist/EngineCanvas.d.ts +9 -0
- package/dist/EngineCanvas.js +11 -0
- package/dist/debug/seed.d.ts +2 -1
- package/dist/debug/seed.js +8 -5
- package/dist/engineFlag.d.ts +18 -0
- package/dist/engineFlag.js +18 -0
- package/dist/export/SceneExporter.d.ts +4 -0
- package/dist/export/SceneExporter.js +6 -0
- package/dist/export/glExport.d.ts +4 -0
- package/dist/export/svgExport.js +12 -9
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/interact/tableCellEditing.js +2 -1
- package/dist/model/scene.d.ts +1 -1
- package/dist/model/scene.js +4 -3
- package/dist/model/tableLayout.js +3 -2
- package/dist/model/textAlign.d.ts +37 -0
- package/dist/model/textAlign.js +36 -0
- package/dist/model/textLayout.d.ts +11 -4
- package/dist/model/textLayout.js +46 -26
- package/dist/render/QuadBatch.d.ts +15 -5
- package/dist/render/QuadBatch.js +80 -9
- package/dist/render/SceneRenderer.d.ts +23 -1
- package/dist/render/SceneRenderer.js +18 -3
- package/dist/render/TextRenderer.js +10 -4
- package/dist/render/bakeGate.d.ts +48 -0
- package/dist/render/bakeGate.js +32 -0
- package/dist/render/imageEffects.d.ts +3 -1
- package/dist/render/imageEffects.js +30 -5
- package/dist/render/lineDecorationSdf.d.ts +63 -0
- package/dist/render/lineDecorationSdf.js +188 -0
- package/dist/render/maskRender.d.ts +2 -1
- package/dist/render/maskRender.js +6 -7
- package/dist/render/psdEffectPainter.d.ts +13 -1
- package/dist/render/psdEffectPainter.js +37 -11
- package/dist/render/scrollText.js +8 -3
- package/dist/render/segmentTable.d.ts +53 -0
- package/dist/render/segmentTable.js +117 -0
- package/dist/render/shaders.d.ts +4 -2
- package/dist/render/shaders.js +142 -6
- package/dist/render/shadowPainter.d.ts +7 -1
- package/dist/render/shadowPainter.js +15 -2
- package/dist/render/strokeMiterOutline.d.ts +39 -0
- package/dist/render/strokeMiterOutline.js +224 -0
- package/dist/render/strokePainter.d.ts +20 -1
- package/dist/render/strokePainter.js +107 -15
- package/dist/render/strokeSdf.d.ts +41 -11
- package/dist/render/strokeSdf.js +198 -11
- package/package.json +1 -1
package/dist/EngineCanvas.d.ts
CHANGED
|
@@ -80,6 +80,9 @@ export declare class EngineCanvas implements PointerHost, TextEditingHost, Sourc
|
|
|
80
80
|
/** 渲染产物统一失效纪元(批次 374 方向一):GlyphAtlas.reset/纹理淘汰经
|
|
81
81
|
* bump 汇入,保留式帧门链单点消费(RetainedFrameHost.renderEpoch) */
|
|
82
82
|
readonly renderEpoch: RenderEpoch;
|
|
83
|
+
/** 烘焙 k 复用下限(批次 377 §5.1):SceneExporter 预览捕获档按
|
|
84
|
+
* ExportRegion.bakeScaleTolerance 置位/还原;屏幕帧恒 0(精确匹配) */
|
|
85
|
+
bakeKReuseFloor: number;
|
|
83
86
|
/** 源加载与图案/蒙版纹理(loadObjects 编排;渲染侧 SceneRenderer 读) */
|
|
84
87
|
private readonly sources;
|
|
85
88
|
/** 文本渲染管线(字形/背景/装饰/虚线/变形文本烘焙) */
|
|
@@ -286,6 +289,12 @@ export declare class EngineCanvas implements PointerHost, TextEditingHost, Sourc
|
|
|
286
289
|
/** 光标锚定缩放(fabric zoomToPoint 语义的 vpt 直写版) */
|
|
287
290
|
zoomAt(cssX: number, cssY: number, factor: number): void;
|
|
288
291
|
pan(dx: number, dy: number): void;
|
|
292
|
+
/** 覆盖层拖拽会话交互标记(批次 386,蒙版工具栏把手拖图「不跟手」刀一):
|
|
293
|
+
* DOM 层把手拖拽(蒙版中心/旋转/缩放把手族)每个拖拽事件调用——k 档
|
|
294
|
+
* settle 补帧在此期间保持 stale 让路(SceneRenderer.noteExternalInteraction
|
|
295
|
+
* 头注的实测数据与语义)。不写 vpt、不触 hit 带、不请求渲染(调用方属性
|
|
296
|
+
* 写自带);settle 定时器停手 160ms 后自动补一帧收尾 */
|
|
297
|
+
noteExternalGesture(): void;
|
|
289
298
|
/** rAF 合并渲染请求(fabric requestRenderAll 同语义)+ rAF 饥饿超时兜底。
|
|
290
299
|
* 批次 44:失焦/被遮挡的内嵌浏览器窗格(IAB webview)实测 visibility 仍报
|
|
291
300
|
* 'visible' 但 rAF 永不回调——字体迟到自愈等「排帧后无人再触发」的补帧会
|
package/dist/EngineCanvas.js
CHANGED
|
@@ -85,6 +85,9 @@ export class EngineCanvas {
|
|
|
85
85
|
/** 渲染产物统一失效纪元(批次 374 方向一):GlyphAtlas.reset/纹理淘汰经
|
|
86
86
|
* bump 汇入,保留式帧门链单点消费(RetainedFrameHost.renderEpoch) */
|
|
87
87
|
renderEpoch = new RenderEpoch();
|
|
88
|
+
/** 烘焙 k 复用下限(批次 377 §5.1):SceneExporter 预览捕获档按
|
|
89
|
+
* ExportRegion.bakeScaleTolerance 置位/还原;屏幕帧恒 0(精确匹配) */
|
|
90
|
+
bakeKReuseFloor = 0;
|
|
88
91
|
/** 源加载与图案/蒙版纹理(loadObjects 编排;渲染侧 SceneRenderer 读) */
|
|
89
92
|
sources;
|
|
90
93
|
/** 文本渲染管线(字形/背景/装饰/虚线/变形文本烘焙) */
|
|
@@ -440,6 +443,14 @@ export class EngineCanvas {
|
|
|
440
443
|
this.renderer.noteVptChange();
|
|
441
444
|
this.requestRenderAll();
|
|
442
445
|
}
|
|
446
|
+
/** 覆盖层拖拽会话交互标记(批次 386,蒙版工具栏把手拖图「不跟手」刀一):
|
|
447
|
+
* DOM 层把手拖拽(蒙版中心/旋转/缩放把手族)每个拖拽事件调用——k 档
|
|
448
|
+
* settle 补帧在此期间保持 stale 让路(SceneRenderer.noteExternalInteraction
|
|
449
|
+
* 头注的实测数据与语义)。不写 vpt、不触 hit 带、不请求渲染(调用方属性
|
|
450
|
+
* 写自带);settle 定时器停手 160ms 后自动补一帧收尾 */
|
|
451
|
+
noteExternalGesture() {
|
|
452
|
+
this.renderer.noteExternalInteraction();
|
|
453
|
+
}
|
|
443
454
|
/** rAF 合并渲染请求(fabric requestRenderAll 同语义)+ rAF 饥饿超时兜底。
|
|
444
455
|
* 批次 44:失焦/被遮挡的内嵌浏览器窗格(IAB webview)实测 visibility 仍报
|
|
445
456
|
* 'visible' 但 rAF 永不回调——字体迟到自愈等「排帧后无人再触发」的补帧会
|
package/dist/debug/seed.d.ts
CHANGED
|
@@ -78,7 +78,8 @@ export declare const makeFilterImageScene: () => SerializedNode[];
|
|
|
78
78
|
* 随字号增大而稀释)。覆盖:硬换行、自动换行、center/right、charSpacing、
|
|
79
79
|
* 多行 lineHeight、无换行 text 类型;P2-2 增补:逐字 fontSize/fontFamily
|
|
80
80
|
* 混排(t7 换行度量 + t8 无换行);justify 增补:t9 纯 justify 多行拉伸
|
|
81
|
-
*
|
|
81
|
+
* (段末行照拉、末行豁免——产品 fork 口径,末行为单词行两侧都拉不动)、
|
|
82
|
+
* t10 justify-center 段末行居中收尾 + CJK 行不拉伸(变体恒空格粒度)。
|
|
82
83
|
*/
|
|
83
84
|
export declare const makeTextScene: () => SerializedNode[];
|
|
84
85
|
/**
|
package/dist/debug/seed.js
CHANGED
|
@@ -410,7 +410,8 @@ export const makeFilterImageScene = () => {
|
|
|
410
410
|
* 随字号增大而稀释)。覆盖:硬换行、自动换行、center/right、charSpacing、
|
|
411
411
|
* 多行 lineHeight、无换行 text 类型;P2-2 增补:逐字 fontSize/fontFamily
|
|
412
412
|
* 混排(t7 换行度量 + t8 无换行);justify 增补:t9 纯 justify 多行拉伸
|
|
413
|
-
*
|
|
413
|
+
* (段末行照拉、末行豁免——产品 fork 口径,末行为单词行两侧都拉不动)、
|
|
414
|
+
* t10 justify-center 段末行居中收尾 + CJK 行不拉伸(变体恒空格粒度)。
|
|
414
415
|
*/
|
|
415
416
|
export const makeTextScene = () => {
|
|
416
417
|
const base = {
|
|
@@ -600,10 +601,12 @@ export const makeTextScene = () => {
|
|
|
600
601
|
left: 80,
|
|
601
602
|
top: 760,
|
|
602
603
|
width: 400,
|
|
603
|
-
// 两端对齐(fabric enlargeSpaces
|
|
604
|
-
//
|
|
605
|
-
//
|
|
606
|
-
|
|
604
|
+
// 两端对齐(fabric enlargeSpaces 同源 + 产品 fork 口径 2026-10-14):多行
|
|
605
|
+
// 词隙拉伸、段末行照拉、纯 justify 只豁免最后一行(编辑器 fork;fabric
|
|
606
|
+
// 上游含末行全拉——两侧在此分道)。末行故意用单词行(无空格可拉)+ 硬换行
|
|
607
|
+
// 隔出段末行,两档豁免/照拉在台面上一眼可辨;fabric 对拍面已退役(批次
|
|
608
|
+
// 275),语义由 textLayout.spec 注入度量锁
|
|
609
|
+
text: 'The quick brown fox jumps over the lazy dog\nwrapword.',
|
|
607
610
|
fontFamily: 'serif',
|
|
608
611
|
fontSize: 40,
|
|
609
612
|
lineHeight: 1.25,
|
package/dist/engineFlag.d.ts
CHANGED
|
@@ -58,6 +58,24 @@ export declare const isEngineRasterExportEnabled: () => boolean;
|
|
|
58
58
|
export declare const isRetainedFrameEnabled: () => boolean;
|
|
59
59
|
/** 保留式诊断日志(?retainedDebug=1):快照收录/门链回退理由/图集 reset 取证 */
|
|
60
60
|
export declare const isRetainedDebugEnabled: () => boolean;
|
|
61
|
+
/** dash 描边 SDF 直绘(方向三第一刀,2026-10-13):两段 pattern 的 butt 帽
|
|
62
|
+
* rect/line 虚线走解析式弧长门(shaders.ts strokeCoverage),消灭虚线族的
|
|
63
|
+
* 烘焙回落链(零重烘零纹理预算——批次 376 病理探针形态整族消失)。
|
|
64
|
+
* **默认开**;一键退 = ?sdfDash=0 / localStorage('engine.sdfDash'='0')——
|
|
65
|
+
* 虚线 SDF vs 烘焙回落的同状态运行时 A/B 开关(像素三连拍 parity 用) */
|
|
66
|
+
export declare const isStrokeSdfDashEnabled: () => boolean;
|
|
67
|
+
/** polygon 族描边 SDF 直绘(方向三第二刀,批次 383):polygon/polyline/triangle
|
|
68
|
+
* 的描边走段表数据纹理 + 着色器段循环(join 语义 CPU 化进段数据),消灭
|
|
69
|
+
* 多边形族的烘焙回落链(零重烘零纹理预算,分辨率无关)。
|
|
70
|
+
* **默认开**;一键退 = ?sdfPolygon=0 / localStorage('engine.sdfPolygon'='0')——
|
|
71
|
+
* 段表 SDF vs 烘焙回落的同状态运行时 A/B 开关(像素三连拍 parity 用) */
|
|
72
|
+
export declare const isStrokeSdfPolygonEnabled: () => boolean;
|
|
73
|
+
/** 线族装饰 SDF 直绘(方向三,批次 388):Arrow(杆线+三角头段表填充)与
|
|
74
|
+
* Dimension(主线+端刻,文本标签桶化小烘焙)从整元素连续 k 烘焙拆解为解析式
|
|
75
|
+
* 分片——缩放零重烘(Dimension 文本仅桶边界重烘)。
|
|
76
|
+
* **默认开**;一键退 = ?sdfLineDeco=0 / localStorage('engine.sdfLineDeco'='0')——
|
|
77
|
+
* 与烘焙回落的同状态运行时 A/B 开关(像素三连拍 parity 用) */
|
|
78
|
+
export declare const isStrokeSdfLineDecorationEnabled: () => boolean;
|
|
61
79
|
/** SVG 纯数据导出(P6-5,批次 19 第一片 + 批次 24 收官):svg 导出页与素材
|
|
62
80
|
* 口径(exportMaterialSVG)走引擎序列化器(store JSON → SVG 字符串,不经
|
|
63
81
|
* 渲染器)替代 FabricStatic 2D 路径。**默认开**(2026-09-23 批次 24 切——
|
package/dist/engineFlag.js
CHANGED
|
@@ -72,6 +72,24 @@ export const isEngineRasterExportEnabled = () => isOperatorFlagEnabled('export',
|
|
|
72
72
|
export const isRetainedFrameEnabled = () => isOperatorFlagEnabled('retained', true);
|
|
73
73
|
/** 保留式诊断日志(?retainedDebug=1):快照收录/门链回退理由/图集 reset 取证 */
|
|
74
74
|
export const isRetainedDebugEnabled = () => isOperatorFlagEnabled('retainedDebug', false);
|
|
75
|
+
/** dash 描边 SDF 直绘(方向三第一刀,2026-10-13):两段 pattern 的 butt 帽
|
|
76
|
+
* rect/line 虚线走解析式弧长门(shaders.ts strokeCoverage),消灭虚线族的
|
|
77
|
+
* 烘焙回落链(零重烘零纹理预算——批次 376 病理探针形态整族消失)。
|
|
78
|
+
* **默认开**;一键退 = ?sdfDash=0 / localStorage('engine.sdfDash'='0')——
|
|
79
|
+
* 虚线 SDF vs 烘焙回落的同状态运行时 A/B 开关(像素三连拍 parity 用) */
|
|
80
|
+
export const isStrokeSdfDashEnabled = () => isOperatorFlagEnabled('sdfDash', true);
|
|
81
|
+
/** polygon 族描边 SDF 直绘(方向三第二刀,批次 383):polygon/polyline/triangle
|
|
82
|
+
* 的描边走段表数据纹理 + 着色器段循环(join 语义 CPU 化进段数据),消灭
|
|
83
|
+
* 多边形族的烘焙回落链(零重烘零纹理预算,分辨率无关)。
|
|
84
|
+
* **默认开**;一键退 = ?sdfPolygon=0 / localStorage('engine.sdfPolygon'='0')——
|
|
85
|
+
* 段表 SDF vs 烘焙回落的同状态运行时 A/B 开关(像素三连拍 parity 用) */
|
|
86
|
+
export const isStrokeSdfPolygonEnabled = () => isOperatorFlagEnabled('sdfPolygon', true);
|
|
87
|
+
/** 线族装饰 SDF 直绘(方向三,批次 388):Arrow(杆线+三角头段表填充)与
|
|
88
|
+
* Dimension(主线+端刻,文本标签桶化小烘焙)从整元素连续 k 烘焙拆解为解析式
|
|
89
|
+
* 分片——缩放零重烘(Dimension 文本仅桶边界重烘)。
|
|
90
|
+
* **默认开**;一键退 = ?sdfLineDeco=0 / localStorage('engine.sdfLineDeco'='0')——
|
|
91
|
+
* 与烘焙回落的同状态运行时 A/B 开关(像素三连拍 parity 用) */
|
|
92
|
+
export const isStrokeSdfLineDecorationEnabled = () => isOperatorFlagEnabled('sdfLineDeco', true);
|
|
75
93
|
/** SVG 纯数据导出(P6-5,批次 19 第一片 + 批次 24 收官):svg 导出页与素材
|
|
76
94
|
* 口径(exportMaterialSVG)走引擎序列化器(store JSON → SVG 字符串,不经
|
|
77
95
|
* 渲染器)替代 FabricStatic 2D 路径。**默认开**(2026-09-23 批次 24 切——
|
|
@@ -41,6 +41,10 @@ export interface SceneExportHost {
|
|
|
41
41
|
* applyExportViewport 之后=导出 vpt 倍率(烘焙分桶 k 同源语义) */
|
|
42
42
|
readonly zoom: number;
|
|
43
43
|
readonly dpr: number;
|
|
44
|
+
/** 烘焙 k 复用下限(批次 377 §5.1):renderAndStage 按 ExportRegion.
|
|
45
|
+
* bakeScaleTolerance 置位(预览捕获档>0 允许复用更密/相近档缓存烘焙,
|
|
46
|
+
* 消灭导出 k 与屏幕 k 错档的一次性重烘+回屏乒乓),渲染完还原 0 */
|
|
47
|
+
bakeKReuseFloor: number;
|
|
44
48
|
requestRenderAll(): void;
|
|
45
49
|
}
|
|
46
50
|
export declare class SceneExporter {
|
|
@@ -136,6 +136,11 @@ export class SceneExporter {
|
|
|
136
136
|
const { outWidth, outHeight } = plan;
|
|
137
137
|
const background = region.background ?? [0, 0, 0, 0];
|
|
138
138
|
const byteLength = outWidth * outHeight * 4;
|
|
139
|
+
// 烘焙 k 复用下限(批次 377 §5.1):预览捕获档(region.bakeScaleTolerance>0)
|
|
140
|
+
// 允许烘焙缓存复用更密/相近档(仅缩方向+相近),消灭导出 k 与屏幕 k 错档的
|
|
141
|
+
// 一次性重烘与回屏乒乓;finally 还原(排水 await 窗口不持导出态口径同守)
|
|
142
|
+
const prevBakeFloor = this.host.bakeKReuseFloor;
|
|
143
|
+
this.host.bakeKReuseFloor = region.bakeScaleTolerance ?? 0;
|
|
139
144
|
// GL 状态快照(批渲染每帧自建 viewport/clear/program,但纹理/FBO/像素缓冲
|
|
140
145
|
// 绑定与混合方程是跨帧持久的——导出完必须原样归还,零侵入主渲染循环)
|
|
141
146
|
const snap = {
|
|
@@ -223,6 +228,7 @@ export class SceneExporter {
|
|
|
223
228
|
gl.deleteSync(staged.fence);
|
|
224
229
|
}
|
|
225
230
|
// 导出视口态(vpt 换档)已还原,但烘焙缓存按导出倍率重烘过:补一帧回到屏幕口径
|
|
231
|
+
this.host.bakeKReuseFloor = prevBakeFloor;
|
|
226
232
|
this.host.requestRenderAll();
|
|
227
233
|
}
|
|
228
234
|
if (staged)
|
|
@@ -22,6 +22,10 @@ export interface ExportRegion {
|
|
|
22
22
|
height: number;
|
|
23
23
|
/** 输出分辨率倍率(1 = 场景单位:像素 1:1);≤0 按 1 处理 */
|
|
24
24
|
multiplier?: number;
|
|
25
|
+
/** 预览捕获档的烘焙 k 复用下限(批次 377 §5.1 收口):cachedK/currentK ≥ 此值
|
|
26
|
+
* 时烘焙缓存按命中复用(仅「缓存更密/相近」方向——放大部分至多 1/floor×
|
|
27
|
+
* 上采样,缩略档不可感);0/缺省 = 精确匹配(真导出勿传,保持逐档新鲜) */
|
|
28
|
+
bakeScaleTolerance?: number;
|
|
25
29
|
/** 清屏色(默认全透明,与 fabric toDataURL 空底一致;jpeg 由调用方传白) */
|
|
26
30
|
background?: [number, number, number, number];
|
|
27
31
|
}
|
package/dist/export/svgExport.js
CHANGED
|
@@ -45,6 +45,7 @@ import { arcTextKind, computeArcTextLayout } from '../model/arcLayout';
|
|
|
45
45
|
import { imageCropRect, textBitmapFillAlpha, WORKSPACE_IDS } from '../model/scene';
|
|
46
46
|
import { ElementTypes, typeKeyOf, IMAGE_LIKE_TYPES, TEXT_TYPES, SOLID_TYPES, LINE_TYPES, MASK_TYPES } from '../model/elementTypes';
|
|
47
47
|
import { charJitterY, layoutTextbox, verticalAnchorShiftX, verticalAnchorShiftY, verticalCharClass, verticalRenderAdvance } from '../model/textLayout';
|
|
48
|
+
import { TextAlignValues, isJustifyFamilyAlign } from '../model/textAlign';
|
|
48
49
|
import { planTextHighlight } from '../render/textHighlight';
|
|
49
50
|
// ---- 类型集(小写键口径,批次 360:家族集合复用 model/elementTypes,细分
|
|
50
51
|
// 子集本地小写化;比较位的 type 一律 typeKeyOf(raw) 派生,双形态就地坍缩) ----
|
|
@@ -385,7 +386,7 @@ const baseTextStyle = (raw) => ({
|
|
|
385
386
|
fontStyle: raw.fontStyle ?? undefined,
|
|
386
387
|
lineHeight: raw.lineHeight ?? 1.16,
|
|
387
388
|
charSpacing: raw.charSpacing ?? 0,
|
|
388
|
-
textAlign: raw.textAlign ??
|
|
389
|
+
textAlign: raw.textAlign ?? TextAlignValues.LEFT
|
|
389
390
|
});
|
|
390
391
|
/** 逐字覆写合成(render/arcText.glyphStyleOf 同源逻辑——export 不引 render 域,内联):
|
|
391
392
|
* 字体四件套覆写 + fill 覆写,其余取对象级 */
|
|
@@ -440,21 +441,23 @@ const stylesArrayToMap = (text, styles) => {
|
|
|
440
441
|
}
|
|
441
442
|
return Object.keys(map).length > 0 ? map : undefined;
|
|
442
443
|
};
|
|
443
|
-
/** 行左偏移(fabric _getLineLeftOffset:justify 非段末行恒 0——fabric
|
|
444
|
-
|
|
445
|
-
|
|
444
|
+
/** 行左偏移(fabric _getLineLeftOffset:justify 非段末行恒 0——fabric 口径;
|
|
445
|
+
* 纯 justify 末行豁免拉伸后也恒 0(左收尾,产品 fork 口径);disperse 全行
|
|
446
|
+
* 含末行都拉恒 0——拉伸本体在 layoutGlyphAnchors 消费的 boxes 里;
|
|
447
|
+
* 谓词显式枚举——值域外怪值不入族按 left 收尾) */ const lineLeftOffset = (align, boxWidth, lineWidth, isEndOfWrapping) => {
|
|
448
|
+
const a = align ?? TextAlignValues.LEFT;
|
|
449
|
+
if (isJustifyFamilyAlign(a)) {
|
|
446
450
|
if (!isEndOfWrapping)
|
|
447
451
|
return 0;
|
|
448
|
-
|
|
449
|
-
if (tail === '-center')
|
|
452
|
+
if (a === TextAlignValues.JUSTIFY_CENTER)
|
|
450
453
|
return (boxWidth - lineWidth) / 2;
|
|
451
|
-
if (
|
|
454
|
+
if (a === TextAlignValues.JUSTIFY_RIGHT)
|
|
452
455
|
return boxWidth - lineWidth;
|
|
453
456
|
return 0;
|
|
454
457
|
}
|
|
455
|
-
if (a ===
|
|
458
|
+
if (a === TextAlignValues.CENTER)
|
|
456
459
|
return (boxWidth - lineWidth) / 2;
|
|
457
|
-
if (a ===
|
|
460
|
+
if (a === TextAlignValues.RIGHT)
|
|
458
461
|
return boxWidth - lineWidth;
|
|
459
462
|
return 0;
|
|
460
463
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -30,6 +30,10 @@ export { EngineDocument, type EngineDocumentEvents, type IndexedItem, type Selec
|
|
|
30
30
|
* 主仓 @/types/elements 的 ElementNames 即本导出的别名(引擎=渲染权限守门人,
|
|
31
31
|
* 类型词汇的单一事实源在引擎,新增元素类型须先在此登记可渲染) */
|
|
32
32
|
export { ElementTypes, typeKeyOf, TEXT_TYPES, SHAPE_TYPES, LINE_TYPES, PUZZLE_TYPES, GIF_TYPES, VIDEO_TYPES, type ElementTypeKey } from './model/elementTypes';
|
|
33
|
+
/** 文本对齐值域(ElementTypes 同款词汇表架构,批次 390 后记):引擎=渲染守门人,
|
|
34
|
+
* 对齐值域/谓词的单一事实源在引擎,主仓/其他项目 re-export 消费(类型面随发版
|
|
35
|
+
* 升版对齐——「引擎改签名未发版」窗口内主仓 vue-tsc 吃 dist .d.ts 尚不可见) */
|
|
36
|
+
export { TextAlignValues, TEXT_ALIGN_VALUES, isJustifyFamilyAlign, isJustifyVariantAlign, isStretchAlign, type TextAlignValue } from './model/textAlign';
|
|
33
37
|
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';
|
|
34
38
|
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';
|
|
35
39
|
export { parsePathData, getBoundsOfPath, type PathCommand } from './core/pathData';
|
package/dist/index.js
CHANGED
|
@@ -34,6 +34,10 @@ export { EngineDocument } from './model/document';
|
|
|
34
34
|
* 主仓 @/types/elements 的 ElementNames 即本导出的别名(引擎=渲染权限守门人,
|
|
35
35
|
* 类型词汇的单一事实源在引擎,新增元素类型须先在此登记可渲染) */
|
|
36
36
|
export { ElementTypes, typeKeyOf, TEXT_TYPES, SHAPE_TYPES, LINE_TYPES, PUZZLE_TYPES, GIF_TYPES, VIDEO_TYPES } from './model/elementTypes';
|
|
37
|
+
/** 文本对齐值域(ElementTypes 同款词汇表架构,批次 390 后记):引擎=渲染守门人,
|
|
38
|
+
* 对齐值域/谓词的单一事实源在引擎,主仓/其他项目 re-export 消费(类型面随发版
|
|
39
|
+
* 升版对齐——「引擎改签名未发版」窗口内主仓 vue-tsc 吃 dist .d.ts 尚不可见) */
|
|
40
|
+
export { TextAlignValues, TEXT_ALIGN_VALUES, isJustifyFamilyAlign, isJustifyVariantAlign, isStretchAlign } from './model/textAlign';
|
|
37
41
|
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';
|
|
38
42
|
export { SvgExporter, serializePageToSvg, buildTextGlyphPathData } from './export/svgExport';
|
|
39
43
|
export { parsePathData, getBoundsOfPath } from './core/pathData';
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
*/
|
|
23
23
|
import { TextNode } from '../model/scene';
|
|
24
24
|
import { getCellData, masterPosition } from '../model/tableEdit';
|
|
25
|
+
import { TextAlignValues } from '../model/textAlign';
|
|
25
26
|
/** 应用 TableDefaultOptions.fontSize(tableLayout 的 CONSTRUCTOR_FONT_SIZE 同源) */
|
|
26
27
|
const DEFAULT_FONT_SIZE = 14;
|
|
27
28
|
/** 应用 Table.defaults.fontFamily(fromObject 不透传——表格级恒为应用默认) */
|
|
@@ -106,7 +107,7 @@ export class TableCellEditingController {
|
|
|
106
107
|
fontWeight: data?.fontWeight,
|
|
107
108
|
fontStyle: data?.fontStyle,
|
|
108
109
|
fontFamily: data?.fontFamily || tableFontFamilyOf(raw),
|
|
109
|
-
textAlign: data?.textAlign ??
|
|
110
|
+
textAlign: data?.textAlign ?? TextAlignValues.CENTER,
|
|
110
111
|
lineHeight: 1.16,
|
|
111
112
|
splitByGrapheme: true,
|
|
112
113
|
opacity: 1,
|
package/dist/model/scene.d.ts
CHANGED
|
@@ -322,7 +322,7 @@ export declare class TextNode extends SceneNode {
|
|
|
322
322
|
setScrollOffset(offset: number): void;
|
|
323
323
|
/**
|
|
324
324
|
* 文本整块宽(应用 calcTextWidth 口径——ScrollText.calcTextTotalWidth 消费):
|
|
325
|
-
* 横排 = max(__lineWidths) 最长自然行宽(justify 拉伸不进,line.width 双口径);
|
|
325
|
+
* 横排 = max(__lineWidths) 最长自然行宽(justify/disperse 拉伸不进,line.width 双口径);
|
|
326
326
|
* 竖排 = 应用 Textbox 覆写分支(逐字累加的双重 spacing quirk + cursorWidth(2),
|
|
327
327
|
* 与盒宽无关——boxWidth 存在时布局盒宽不走该式而本值仍须用它)。
|
|
328
328
|
* 滚动循环距离 = 本值 + 视口宽(getScrollTextDuration 同式)。
|
package/dist/model/scene.js
CHANGED
|
@@ -54,6 +54,7 @@ export const WORKSPACE_IDS = new Set(['WorkSpaceDrawType', 'WorkSpaceClipType',
|
|
|
54
54
|
* 与家族语义见该模块。此处 re-export 维持既有消费面导入路径不变 */
|
|
55
55
|
export { ElementTypes, typeKeyOf, TEXT_TYPES, IMAGE_LIKE_TYPES, SOLID_TYPES, SHAPE_TYPES, LINE_TYPES, MASK_TYPES, PUZZLE_TYPES, GIF_TYPES, VIDEO_TYPES } from './elementTypes';
|
|
56
56
|
import { ElementTypes, GIF_TYPES, VIDEO_TYPES, typeKeyOf, TEXT_TYPES, IMAGE_LIKE_TYPES, SOLID_TYPES, SHAPE_TYPES, LINE_TYPES, MASK_TYPES, PUZZLE_TYPES } from './elementTypes';
|
|
57
|
+
import { TextAlignValues } from './textAlign';
|
|
57
58
|
/** 批次 314 图片文字:TextImage 位图态判定(raw.renderSrc 在场)——渲染/命中/
|
|
58
59
|
* 手柄/组语义全按图片口径(缩放手势走 scale、不做文本烘焙);转正(renderSrc
|
|
59
60
|
* 删除)后按文本口径(盒宽/字号烘焙、组改宽回流) */
|
|
@@ -669,7 +670,7 @@ export class TextNode extends SceneNode {
|
|
|
669
670
|
fontStyle: raw.fontStyle,
|
|
670
671
|
lineHeight: raw.lineHeight ?? 1.16,
|
|
671
672
|
charSpacing: raw.charSpacing ?? 0,
|
|
672
|
-
textAlign: raw.textAlign ??
|
|
673
|
+
textAlign: raw.textAlign ?? TextAlignValues.LEFT
|
|
673
674
|
};
|
|
674
675
|
}
|
|
675
676
|
/**
|
|
@@ -743,7 +744,7 @@ export class TextNode extends SceneNode {
|
|
|
743
744
|
}
|
|
744
745
|
/**
|
|
745
746
|
* 文本整块宽(应用 calcTextWidth 口径——ScrollText.calcTextTotalWidth 消费):
|
|
746
|
-
* 横排 = max(__lineWidths) 最长自然行宽(justify 拉伸不进,line.width 双口径);
|
|
747
|
+
* 横排 = max(__lineWidths) 最长自然行宽(justify/disperse 拉伸不进,line.width 双口径);
|
|
747
748
|
* 竖排 = 应用 Textbox 覆写分支(逐字累加的双重 spacing quirk + cursorWidth(2),
|
|
748
749
|
* 与盒宽无关——boxWidth 存在时布局盒宽不走该式而本值仍须用它)。
|
|
749
750
|
* 滚动循环距离 = 本值 + 视口宽(getScrollTextDuration 同式)。
|
|
@@ -904,7 +905,7 @@ export class TextNode extends SceneNode {
|
|
|
904
905
|
}
|
|
905
906
|
}
|
|
906
907
|
const line = layout.lines[target];
|
|
907
|
-
// 行末端点用哨兵盒口径(末盒 left+width,含行尾 charSpacing、justify 拉伸
|
|
908
|
+
// 行末端点用哨兵盒口径(末盒 left+width,含行尾 charSpacing、justify/disperse 拉伸
|
|
908
909
|
// 末端)——fabric _measureLine 行末哨兵盒同语义,勿用 line.width(自然行宽)
|
|
909
910
|
const x = -layout.width / 2 + line.leftOffset + (charInLine < line.boxes.length ? line.boxes[charInLine].left : lineEndOffset(line));
|
|
910
911
|
// 坐标系统一为中心系(与字形/选区高亮的矩阵消费一致):历史上这里返回
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
*/
|
|
25
25
|
import { FONT_SIZE_MULT, layoutTextbox } from './textLayout';
|
|
26
26
|
import { buildCellMap } from './tableEdit';
|
|
27
|
+
import { TextAlignValues } from './textAlign';
|
|
27
28
|
/** 应用 TableDefaultOptions.fontSize——fromObject 不透传 fontSize,构造期空单元格
|
|
28
29
|
* 以它度量行高(摆位 quirk 的 h0 依赖;应用默认值变更时须同步此处) */
|
|
29
30
|
const CONSTRUCTOR_FONT_SIZE = 14;
|
|
@@ -84,7 +85,7 @@ export const computeTableLayout = (raw, measure, opts) => {
|
|
|
84
85
|
fontStyle: data.fontStyle,
|
|
85
86
|
lineHeight: 1.16,
|
|
86
87
|
charSpacing: 0,
|
|
87
|
-
textAlign: data.textAlign ??
|
|
88
|
+
textAlign: data.textAlign ?? TextAlignValues.CENTER
|
|
88
89
|
}, { boxWidth: textWidth, splitByGrapheme: true, measure }),
|
|
89
90
|
data
|
|
90
91
|
});
|
|
@@ -167,7 +168,7 @@ export const computeTableLayout = (raw, measure, opts) => {
|
|
|
167
168
|
fontSize: data?.fontSize ?? CONSTRUCTOR_FONT_SIZE,
|
|
168
169
|
fontWeight: data?.fontWeight,
|
|
169
170
|
fontStyle: data?.fontStyle,
|
|
170
|
-
textAlign: data?.textAlign ??
|
|
171
|
+
textAlign: data?.textAlign ?? TextAlignValues.CENTER,
|
|
171
172
|
lineHeight: 1.16,
|
|
172
173
|
splitByGrapheme: true,
|
|
173
174
|
originX: 'center',
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文本对齐值域(vocabulary——ElementTypes 同款架构:引擎=渲染守门人,值域在
|
|
3
|
+
* 引擎定义、主仓/其他项目 re-export 消费,批次 390 后记)。判断位(===/
|
|
4
|
+
* startsWith/includes/switch)一律走本模块常量与谓词,不得新增裸字符串判断;
|
|
5
|
+
* 数据层兜底(?? 默认值)同源用常量。**排除域**:2D canvas 的 `ctx.textAlign`
|
|
6
|
+
* 是 DOM API 自有枚举(同值不同域,ElementNames 排除域同款纪律),不在此列。
|
|
7
|
+
*
|
|
8
|
+
* 值域八值:left/center/right + justify 全家(纯 justify=只豁末行、justify-left/
|
|
9
|
+
* center/right 变体=段末豁免+行偏移收尾)+ disperse 分散对齐(全行含末行都拉)。
|
|
10
|
+
* 语义矩阵见 textLayout stretch 块头注;分布粒度(CJK 逐字/拉丁空格)见
|
|
11
|
+
* CJK_LINE_RE。谓词为**显式枚举**(非前缀匹配)——值域外的怪值(如 'justify-foo')
|
|
12
|
+
* 不入族、按 left 渲染,词汇表语义即从严。
|
|
13
|
+
*/
|
|
14
|
+
/** 文本对齐值域常量(judgment 用;值即序列化存储形) */
|
|
15
|
+
export declare const TextAlignValues: {
|
|
16
|
+
readonly LEFT: "left";
|
|
17
|
+
readonly CENTER: "center";
|
|
18
|
+
readonly RIGHT: "right";
|
|
19
|
+
readonly JUSTIFY: "justify";
|
|
20
|
+
readonly JUSTIFY_LEFT: "justify-left";
|
|
21
|
+
readonly JUSTIFY_CENTER: "justify-center";
|
|
22
|
+
readonly JUSTIFY_RIGHT: "justify-right";
|
|
23
|
+
readonly DISPERSE: "disperse";
|
|
24
|
+
};
|
|
25
|
+
export type TextAlignValue = (typeof TextAlignValues)[keyof typeof TextAlignValues];
|
|
26
|
+
/**
|
|
27
|
+
* 白名单清单(面板/chat 合法枚举的消费面;chat 面板按后端口径取其中五值子集)。
|
|
28
|
+
* string[] 而非 const 值域数组——后者在 includes(string) 入参处触发不变性拒绝
|
|
29
|
+
* (ElementTypes 同坑,主仓 AGENTS「Known pits」在案)。
|
|
30
|
+
*/
|
|
31
|
+
export declare const TEXT_ALIGN_VALUES: string[];
|
|
32
|
+
/** justify 家族(纯 justify + 三变体)——空格加宽与段末行豁免机制的适用域 */
|
|
33
|
+
export declare const isJustifyFamilyAlign: (a: unknown) => a is TextAlignValue;
|
|
34
|
+
/** justify-left/center/right 变体——段末行+末行豁免,left/center/right 行偏移收尾 */
|
|
35
|
+
export declare const isJustifyVariantAlign: (a: unknown) => a is TextAlignValue;
|
|
36
|
+
/** 纯拉伸档(纯 justify | disperse)——CJK 行逐字分布适用 + fork 末行豁免矩阵 */
|
|
37
|
+
export declare const isStretchAlign: (a: unknown) => boolean;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文本对齐值域(vocabulary——ElementTypes 同款架构:引擎=渲染守门人,值域在
|
|
3
|
+
* 引擎定义、主仓/其他项目 re-export 消费,批次 390 后记)。判断位(===/
|
|
4
|
+
* startsWith/includes/switch)一律走本模块常量与谓词,不得新增裸字符串判断;
|
|
5
|
+
* 数据层兜底(?? 默认值)同源用常量。**排除域**:2D canvas 的 `ctx.textAlign`
|
|
6
|
+
* 是 DOM API 自有枚举(同值不同域,ElementNames 排除域同款纪律),不在此列。
|
|
7
|
+
*
|
|
8
|
+
* 值域八值:left/center/right + justify 全家(纯 justify=只豁末行、justify-left/
|
|
9
|
+
* center/right 变体=段末豁免+行偏移收尾)+ disperse 分散对齐(全行含末行都拉)。
|
|
10
|
+
* 语义矩阵见 textLayout stretch 块头注;分布粒度(CJK 逐字/拉丁空格)见
|
|
11
|
+
* CJK_LINE_RE。谓词为**显式枚举**(非前缀匹配)——值域外的怪值(如 'justify-foo')
|
|
12
|
+
* 不入族、按 left 渲染,词汇表语义即从严。
|
|
13
|
+
*/
|
|
14
|
+
/** 文本对齐值域常量(judgment 用;值即序列化存储形) */
|
|
15
|
+
export const TextAlignValues = {
|
|
16
|
+
LEFT: 'left',
|
|
17
|
+
CENTER: 'center',
|
|
18
|
+
RIGHT: 'right',
|
|
19
|
+
JUSTIFY: 'justify',
|
|
20
|
+
JUSTIFY_LEFT: 'justify-left',
|
|
21
|
+
JUSTIFY_CENTER: 'justify-center',
|
|
22
|
+
JUSTIFY_RIGHT: 'justify-right',
|
|
23
|
+
DISPERSE: 'disperse'
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* 白名单清单(面板/chat 合法枚举的消费面;chat 面板按后端口径取其中五值子集)。
|
|
27
|
+
* string[] 而非 const 值域数组——后者在 includes(string) 入参处触发不变性拒绝
|
|
28
|
+
* (ElementTypes 同坑,主仓 AGENTS「Known pits」在案)。
|
|
29
|
+
*/
|
|
30
|
+
export const TEXT_ALIGN_VALUES = Object.values(TextAlignValues);
|
|
31
|
+
/** justify 家族(纯 justify + 三变体)——空格加宽与段末行豁免机制的适用域 */
|
|
32
|
+
export const isJustifyFamilyAlign = (a) => a === TextAlignValues.JUSTIFY || a === TextAlignValues.JUSTIFY_LEFT || a === TextAlignValues.JUSTIFY_CENTER || a === TextAlignValues.JUSTIFY_RIGHT;
|
|
33
|
+
/** justify-left/center/right 变体——段末行+末行豁免,left/center/right 行偏移收尾 */
|
|
34
|
+
export const isJustifyVariantAlign = (a) => a === TextAlignValues.JUSTIFY_LEFT || a === TextAlignValues.JUSTIFY_CENTER || a === TextAlignValues.JUSTIFY_RIGHT;
|
|
35
|
+
/** 纯拉伸档(纯 justify | disperse)——CJK 行逐字分布适用 + fork 末行豁免矩阵 */
|
|
36
|
+
export const isStretchAlign = (a) => a === TextAlignValues.JUSTIFY || a === TextAlignValues.DISPERSE;
|
|
@@ -25,10 +25,12 @@
|
|
|
25
25
|
* 装饰线(P2-4):underline/overline/linethrough 不进度量,渲染侧由
|
|
26
26
|
* lineDecorationRuns 按 fabric _renderTextDecoration 的 run 状态机产出线段 quad;
|
|
27
27
|
* 颜色逐字跟 fill(fabric ctx.fillStyle = getValueOfPropertyAt(FILL) 同语义)。
|
|
28
|
-
* Phase 2a 范围注记:ltr 子集(rtl 反向对齐不做);justify
|
|
29
|
-
*
|
|
30
|
-
* justify-left/center/right
|
|
31
|
-
*
|
|
28
|
+
* Phase 2a 范围注记:ltr 子集(rtl 反向对齐不做);justify 全家 + disperse
|
|
29
|
+
* 分散对齐已实现(enlargeSpaces 移植 + 编辑器 fork 口径:空格均摊加宽 +
|
|
30
|
+
* 字符盒平移,纯 justify 只豁免末行、justify-left/center/right 变体段末行
|
|
31
|
+
* 豁免并按对应方式收尾、disperse 全行含末行都拉、CJK 行逐字分布——详见
|
|
32
|
+
* stretch 块头注),grapheme 切分用码点级(CJK/拉丁与 fabric 一致,
|
|
33
|
+
* emoji 簇差异已知,后续对齐)。
|
|
32
34
|
* splitByGrapheme(P4-4 表格单元格模式):LayoutOptions.splitByGrapheme ——
|
|
33
35
|
* 词=单字素、无 infix 空格、样式映射不吃空格(fabric 三处守卫逐条对齐)。
|
|
34
36
|
* 竖排(P4-5c):LayoutOptions.vertical —— 应用 Textbox vertical:true 的
|
|
@@ -203,6 +205,11 @@ export interface TextStrokeDecl {
|
|
|
203
205
|
export declare const resolveStrokeDecl: (base: TextStrokeDecl | null, o?: CharStyleOverride) => TextStrokeDecl | null;
|
|
204
206
|
/** 装饰线三类型(fabric _renderTextDecoration 的三趟 pass) */
|
|
205
207
|
export type TextDecorationType = 'underline' | 'overline' | 'linethrough';
|
|
208
|
+
/** 行内 CJK 判定(编辑器 Textbox.enlargeSpaces fork 的 cjkRegex 原样:Han 统一
|
|
209
|
+
* 表意 + 平假名 + 片假名 + 谚文音节;扩展区/兼容区不在此列——fork 口径原样保留)。
|
|
210
|
+
* 纯 justify/disperse 的 CJK 行按逐字分布拉伸;渲染侧 run 断段(dash 描边/
|
|
211
|
+
* scrollText)同源判定逐字断段。 */
|
|
212
|
+
export declare const CJK_LINE_RE: RegExp;
|
|
206
213
|
/**
|
|
207
214
|
* 行末 x(相对行首):fabric `_measureLine` 的**行末哨兵盒**口径 =
|
|
208
215
|
* 末字符盒 left + width(width 含行尾 charSpacing)。justify 拉伸行的空格
|
package/dist/model/textLayout.js
CHANGED
|
@@ -25,10 +25,12 @@
|
|
|
25
25
|
* 装饰线(P2-4):underline/overline/linethrough 不进度量,渲染侧由
|
|
26
26
|
* lineDecorationRuns 按 fabric _renderTextDecoration 的 run 状态机产出线段 quad;
|
|
27
27
|
* 颜色逐字跟 fill(fabric ctx.fillStyle = getValueOfPropertyAt(FILL) 同语义)。
|
|
28
|
-
* Phase 2a 范围注记:ltr 子集(rtl 反向对齐不做);justify
|
|
29
|
-
*
|
|
30
|
-
* justify-left/center/right
|
|
31
|
-
*
|
|
28
|
+
* Phase 2a 范围注记:ltr 子集(rtl 反向对齐不做);justify 全家 + disperse
|
|
29
|
+
* 分散对齐已实现(enlargeSpaces 移植 + 编辑器 fork 口径:空格均摊加宽 +
|
|
30
|
+
* 字符盒平移,纯 justify 只豁免末行、justify-left/center/right 变体段末行
|
|
31
|
+
* 豁免并按对应方式收尾、disperse 全行含末行都拉、CJK 行逐字分布——详见
|
|
32
|
+
* stretch 块头注),grapheme 切分用码点级(CJK/拉丁与 fabric 一致,
|
|
33
|
+
* emoji 簇差异已知,后续对齐)。
|
|
32
34
|
* splitByGrapheme(P4-4 表格单元格模式):LayoutOptions.splitByGrapheme ——
|
|
33
35
|
* 词=单字素、无 infix 空格、样式映射不吃空格(fabric 三处守卫逐条对齐)。
|
|
34
36
|
* 竖排(P4-5c):LayoutOptions.vertical —— 应用 Textbox vertical:true 的
|
|
@@ -39,6 +41,7 @@
|
|
|
39
41
|
* 加 space;换行判定轴不覆写(fabric 原样近似)。
|
|
40
42
|
* 布局级 parity 由 e2e 直接对比 fabric Textbox 的 _textLines/__lineWidths/height。
|
|
41
43
|
*/
|
|
44
|
+
import { TextAlignValues, isJustifyFamilyAlign, isJustifyVariantAlign } from './textAlign';
|
|
42
45
|
/** fabric CACHE_FONT_SIZE:所有字体度量在固定字号下做缓存 */
|
|
43
46
|
export const CACHE_FONT_SIZE = 400;
|
|
44
47
|
/** fabric _fontSizeMult:行高实现值 = max(fontSize) × 1.13 */
|
|
@@ -292,6 +295,11 @@ export const resolveStrokeDecl = (base, o) => {
|
|
|
292
295
|
lineCap: base?.lineCap
|
|
293
296
|
};
|
|
294
297
|
};
|
|
298
|
+
/** 行内 CJK 判定(编辑器 Textbox.enlargeSpaces fork 的 cjkRegex 原样:Han 统一
|
|
299
|
+
* 表意 + 平假名 + 片假名 + 谚文音节;扩展区/兼容区不在此列——fork 口径原样保留)。
|
|
300
|
+
* 纯 justify/disperse 的 CJK 行按逐字分布拉伸;渲染侧 run 断段(dash 描边/
|
|
301
|
+
* scrollText)同源判定逐字断段。 */
|
|
302
|
+
export const CJK_LINE_RE = /[\u4e00-\u9fa5\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af]/;
|
|
295
303
|
/**
|
|
296
304
|
* 行末 x(相对行首):fabric `_measureLine` 的**行末哨兵盒**口径 =
|
|
297
305
|
* 末字符盒 left + width(width 含行尾 charSpacing)。justify 拉伸行的空格
|
|
@@ -743,7 +751,7 @@ export const layoutTextbox = (text, style, options = {}) => {
|
|
|
743
751
|
};
|
|
744
752
|
const verticalWidth = options.vertical ? verticalCalcWidth() : undefined;
|
|
745
753
|
const boxW = options.boxWidth != null ? expandedBoxWidth : options.vertical ? verticalWidth : Math.max(0, ...lines.map((l) => l.width));
|
|
746
|
-
const align = style.textAlign ??
|
|
754
|
+
const align = style.textAlign ?? TextAlignValues.LEFT;
|
|
747
755
|
// 段末行判定(fabric Textbox.isEndOfWrapping:下一视觉行已属新原始行即段末;
|
|
748
756
|
// text/itext 无自动换行,fabric Text.isEndOfWrapping 只认最后一行)
|
|
749
757
|
const isEndOfWrapping = (i) => {
|
|
@@ -753,8 +761,8 @@ export const layoutTextbox = (text, style, options = {}) => {
|
|
|
753
761
|
return !next || next.line !== lines[i].styleMap.line;
|
|
754
762
|
};
|
|
755
763
|
for (let i = 0; i < lines.length; i++) {
|
|
756
|
-
const centerish = align ===
|
|
757
|
-
const rightish = align ===
|
|
764
|
+
const centerish = align === TextAlignValues.CENTER || (align === TextAlignValues.JUSTIFY_CENTER && isEndOfWrapping(i));
|
|
765
|
+
const rightish = align === TextAlignValues.RIGHT || (align === TextAlignValues.JUSTIFY_RIGHT && isEndOfWrapping(i));
|
|
758
766
|
// P4-5c 补丁(2026-09-20,仅 webgl2 引擎侧——登记为有意偏差):竖排
|
|
759
767
|
// center/right 的对齐量改按渲染链墨迹口径(verticalLineInkRun)。应用侧
|
|
760
768
|
// fabric 以度量列长收边(_measureLine 竖排 CJK=盒高、不含 charSpacing),
|
|
@@ -775,38 +783,50 @@ export const layoutTextbox = (text, style, options = {}) => {
|
|
|
775
783
|
lines[i].leftOffset = diff;
|
|
776
784
|
}
|
|
777
785
|
}
|
|
778
|
-
//
|
|
779
|
-
//
|
|
780
|
-
// __charBounds
|
|
781
|
-
// line.width 保持自然行宽(fabric
|
|
782
|
-
//
|
|
783
|
-
//
|
|
784
|
-
//
|
|
785
|
-
//
|
|
786
|
-
//
|
|
787
|
-
|
|
786
|
+
// 两端/分散对齐(fabric enlargeSpaces 移植 + 编辑器 fork 口径 a7e9b58cd):
|
|
787
|
+
// 把 (盒宽 − 自然行宽) 均摊进行内可拉单元的 width/kernedWidth 并平移后续
|
|
788
|
+
// 字符盒 left——fabric 在度量后直接改 __charBounds,渲染/光标/选区/装饰线
|
|
789
|
+
// 全部随盒生效,引擎同口径改 boxes。line.width 保持自然行宽(fabric
|
|
790
|
+
// __lineWidths 不被 enlargeSpaces 触碰,布局对拍口径);行末端点(光标/
|
|
791
|
+
// 选区)用 lineEndOffset 的哨兵盒口径,末盒被同步平移/加宽后即落在拉伸末端。
|
|
792
|
+
// 行豁免矩阵(编辑器 Textbox.enlargeSpaces fork;2026-10-14 引擎从「fabric
|
|
793
|
+
// 上游含末行全拉」对齐到产品口径——产品编辑器的纯 justify 从不拉末行):
|
|
794
|
+
// - 纯 'justify':只豁免最后一行(段末行照拉)
|
|
795
|
+
// - 'justify-left/center/right' 变体:跳过段末行+末行,由上面的行偏移收尾
|
|
796
|
+
// - 'disperse'(分散对齐):全部行含末行都拉(fork 无豁免)
|
|
797
|
+
// 分布粒度(纯 justify/disperse 共用,fork 的 cjkRegex 分路;变体恒空格
|
|
798
|
+
// 粒度——fork 变体走 super.enlargeSpaces):行内含 CJK(CJK_LINE_RE)→
|
|
799
|
+
// 逐字分布,slack 均摊进 (n−1) 个字间隙,每字加宽、末字只平移不加宽(首尾
|
|
800
|
+
// 两缘恰好贴盒;fork 按 UTF-16 split('') 计数,引擎按 grapheme 计数,代理
|
|
801
|
+
// 对行的计数更准,属登记偏差);无 CJK → 只加宽空格(fabric 原生,行内
|
|
802
|
+
// 无空格或行宽已达盒宽不拉伸)。竖排不拉伸(编辑器 verticaltext mixin
|
|
803
|
+
// 从不消费对齐拉伸;竖排 left/center/right 行偏移不受影响)。
|
|
804
|
+
const disperse = align === TextAlignValues.DISPERSE;
|
|
805
|
+
if ((isJustifyFamilyAlign(align) || disperse) && !options.vertical) {
|
|
788
806
|
for (let i = 0; i < lines.length; i++) {
|
|
789
807
|
const line = lines[i];
|
|
790
|
-
|
|
808
|
+
const variant = isJustifyVariantAlign(align);
|
|
809
|
+
if (variant && (i === lines.length - 1 || isEndOfWrapping(i)))
|
|
810
|
+
continue;
|
|
811
|
+
if (!variant && !disperse && i === lines.length - 1)
|
|
791
812
|
continue;
|
|
792
813
|
if (line.width >= boxW)
|
|
793
814
|
continue;
|
|
794
|
-
const
|
|
795
|
-
|
|
815
|
+
const charWise = !variant && line.graphemes.some((g) => CJK_LINE_RE.test(g));
|
|
816
|
+
const slots = charWise ? line.graphemes.length - 1 : line.graphemes.reduce((n, g) => (/[ \t\r]/.test(g) ? n + 1 : n), 0);
|
|
817
|
+
if (slots <= 0)
|
|
796
818
|
continue;
|
|
797
|
-
const diffSpace = (boxW - line.width) /
|
|
819
|
+
const diffSpace = (boxW - line.width) / slots;
|
|
798
820
|
let accumulated = 0;
|
|
799
821
|
for (let j = 0; j < line.graphemes.length; j++) {
|
|
800
822
|
const box = line.boxes[j];
|
|
801
|
-
|
|
823
|
+
const stretchThis = charWise ? j < line.graphemes.length - 1 : /[ \t\r]/.test(line.graphemes[j]);
|
|
824
|
+
box.left += accumulated;
|
|
825
|
+
if (stretchThis) {
|
|
802
826
|
box.width += diffSpace;
|
|
803
827
|
box.kernedWidth += diffSpace;
|
|
804
|
-
box.left += accumulated;
|
|
805
828
|
accumulated += diffSpace;
|
|
806
829
|
}
|
|
807
|
-
else {
|
|
808
|
-
box.left += accumulated;
|
|
809
|
-
}
|
|
810
830
|
}
|
|
811
831
|
}
|
|
812
832
|
}
|