@yft-design/engine 0.0.12 → 0.0.14
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 +87 -4
- package/dist/EngineCanvas.js +269 -15
- package/dist/core/events.d.ts +22 -0
- package/dist/core/events.js +28 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/interact/canvasInteractions.d.ts +18 -2
- package/dist/interact/canvasInteractions.js +52 -28
- package/dist/interact/dblClick.d.ts +18 -1
- package/dist/interact/dblClick.js +16 -2
- package/dist/interact/pageTransfer.d.ts +22 -0
- package/dist/interact/pageTransfer.js +56 -0
- package/dist/interact/pointer.d.ts +7 -1
- package/dist/interact/pointer.js +63 -7
- package/dist/interact/pointerTypes.d.ts +23 -0
- package/dist/interact/tableCellEditing.d.ts +4 -1
- package/dist/interact/tableCellEditing.js +17 -10
- package/dist/interact/tableInteraction.d.ts +4 -1
- package/dist/interact/tableInteraction.js +13 -6
- package/dist/interact/textEditing.d.ts +4 -1
- package/dist/interact/textEditing.js +19 -12
- package/dist/interact/wheelScroll.d.ts +21 -0
- package/dist/interact/wheelScroll.js +29 -1
- package/dist/render/SceneRenderer.js +2 -1
- package/dist/render/SourceManager.d.ts +7 -0
- package/dist/render/SourceManager.js +18 -0
- package/dist/render/clipMaskPainter.js +5 -3
- package/dist/render/fontInvalidationController.d.ts +4 -0
- package/dist/render/fontInvalidationController.js +6 -1
- package/dist/render/framePipeline.d.ts +3 -0
- package/dist/render/framePipeline.js +1 -1
- package/dist/render/multiPage.d.ts +190 -0
- package/dist/render/multiPage.js +403 -0
- package/dist/render/renderViewport.d.ts +7 -0
- package/dist/render/renderViewport.js +18 -0
- package/dist/render/strokePainter.js +3 -2
- package/dist/render/workspaceBackdrop.d.ts +25 -18
- package/dist/render/workspaceBackdrop.js +35 -46
- package/dist/render/workspaceGlow.d.ts +23 -12
- package/dist/render/workspaceGlow.js +42 -15
- package/package.json +2 -2
package/dist/core/events.js
CHANGED
|
@@ -50,3 +50,31 @@ export class EventBus {
|
|
|
50
50
|
this._handlers.clear();
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* doc bus 订阅束(批次 410 D-4):构造期订阅 + 切页重订。多页态活动页切换时
|
|
55
|
+
* 各交互控制器(textEditing/canvasInteractions/tableCellEditing/tableInteraction)
|
|
56
|
+
* 原构造期订死的初始页 bus 收不到他页事件(D-3 真机显影:非初始页双击
|
|
57
|
+
* editingNode 正确但 textarea 未挂载)——束持有当前 bus,retarget 旧退新订;
|
|
58
|
+
* 同 bus 直通幂等。订阅体由调用方注入(各控制器事件面不同)。
|
|
59
|
+
*/
|
|
60
|
+
export class DocBusBinder {
|
|
61
|
+
subscribe;
|
|
62
|
+
off;
|
|
63
|
+
current;
|
|
64
|
+
constructor(bus, subscribe) {
|
|
65
|
+
this.subscribe = subscribe;
|
|
66
|
+
this.current = bus;
|
|
67
|
+
this.off = subscribe(bus);
|
|
68
|
+
}
|
|
69
|
+
/** 切页重订(同 bus 幂等直通) */
|
|
70
|
+
retarget(bus) {
|
|
71
|
+
if (bus === this.current)
|
|
72
|
+
return;
|
|
73
|
+
this.off();
|
|
74
|
+
this.current = bus;
|
|
75
|
+
this.off = this.subscribe(bus);
|
|
76
|
+
}
|
|
77
|
+
dispose() {
|
|
78
|
+
this.off();
|
|
79
|
+
}
|
|
80
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ export { isCanvasPerfEnabled, markCanvasPerfCounter, recordCanvasPerfDuration }
|
|
|
26
26
|
export { rectCornerRadii } from './core/roundedRect';
|
|
27
27
|
export { parsePsdEffects } from './core/psdEffects';
|
|
28
28
|
export { EngineDocument, type EngineDocumentEvents, type IndexedItem, type SelectionFrame } from './model/document';
|
|
29
|
+
export { PAGE_GAP_CSS_PX, type PageRect, type PageLayoutRow } from './render/multiPage';
|
|
30
|
+
export type { PageTransfer, PageTransferItem } from './interact/pageTransfer';
|
|
29
31
|
/** 元素类型规范词表(批次 361 主仓同源):小写键 + typeKeyOf 坍缩 + 家族集合——
|
|
30
32
|
* 主仓 @/types/elements 的 ElementNames 即本导出的别名(引擎=渲染权限守门人,
|
|
31
33
|
* 类型词汇的单一事实源在引擎,新增元素类型须先在此登记可渲染) */
|
package/dist/index.js
CHANGED
|
@@ -30,6 +30,7 @@ export { isCanvasPerfEnabled, markCanvasPerfCounter, recordCanvasPerfDuration }
|
|
|
30
30
|
export { rectCornerRadii } from './core/roundedRect';
|
|
31
31
|
export { parsePsdEffects } from './core/psdEffects';
|
|
32
32
|
export { EngineDocument } from './model/document';
|
|
33
|
+
export { PAGE_GAP_CSS_PX } from './render/multiPage';
|
|
33
34
|
/** 元素类型规范词表(批次 361 主仓同源):小写键 + typeKeyOf 坍缩 + 家族集合——
|
|
34
35
|
* 主仓 @/types/elements 的 ElementNames 即本导出的别名(引擎=渲染权限守门人,
|
|
35
36
|
* 类型词汇的单一事实源在引擎,新增元素类型须先在此登记可渲染) */
|
|
@@ -9,7 +9,13 @@
|
|
|
9
9
|
* object:removed → 动画源释放)也在此接线。EngineCanvas 只留构造一行与
|
|
10
10
|
* dispose 一行;宿主面 = 既有四个 host 接口之并(panning 让位判定走
|
|
11
11
|
* PointerHost 公共面)。
|
|
12
|
+
*
|
|
13
|
+
* 静态模式(interactive=false,EngineCanvasOptions.interactive——VideoPlay
|
|
14
|
+
* 播放预览等纯展示面):指针/双击/中键平移/滚轮/Esc 五类交互监听整体不挂
|
|
15
|
+
* (画布 CSS pointer-events 拦不住 window 级 pointermove,悬停命中须源头
|
|
16
|
+
* 不挂才断根);字体迟到失效与文档事件接线保持(渲染正确性面,与交互无关)。
|
|
12
17
|
*/
|
|
18
|
+
import type { EngineDocument } from '../model/document';
|
|
13
19
|
import { type PointerHost } from './pointer';
|
|
14
20
|
import { type DblClickHost } from './dblClick';
|
|
15
21
|
import { type TableInteractionHost } from './tableInteraction';
|
|
@@ -31,6 +37,9 @@ export declare class CanvasInteractionsController {
|
|
|
31
37
|
private readonly host;
|
|
32
38
|
private readonly snapGuide;
|
|
33
39
|
private readonly sources;
|
|
40
|
+
/** 交互/静态模式(EngineCanvasOptions.interactive,默认 true=交互):
|
|
41
|
+
* 静态时下传 Pointer/DoubleClick 不挂监听,本级 wheel/中键平移/Esc 同免 */
|
|
42
|
+
private readonly interactive;
|
|
34
43
|
/** 左键交互(选择/移动/缩放/旋转/框选);宿主自身实现 PointerHost */
|
|
35
44
|
private readonly pointer;
|
|
36
45
|
/** 表格键盘交互 + 单元格态生命周期(P4-4b) */
|
|
@@ -38,13 +47,20 @@ export declare class CanvasInteractionsController {
|
|
|
38
47
|
/** 双击派发(P5-7):表格格/拼图蒙版/文本编辑三会话 + 图片族智能对象/替换图事件边界 */
|
|
39
48
|
private readonly dblClick;
|
|
40
49
|
private detachListeners;
|
|
41
|
-
|
|
50
|
+
/** doc bus 订阅束(批次 410 D-4):切页 retarget(级联 tableInteraction) */
|
|
51
|
+
private docBus;
|
|
42
52
|
private lastPanPointer;
|
|
43
|
-
constructor(host: CanvasInteractionsHost, snapGuide: SnapGuideController, sources: SourceManager
|
|
53
|
+
constructor(host: CanvasInteractionsHost, snapGuide: SnapGuideController, sources: SourceManager,
|
|
54
|
+
/** 交互/静态模式(EngineCanvasOptions.interactive,默认 true=交互):
|
|
55
|
+
* 静态时下传 Pointer/DoubleClick 不挂监听,本级 wheel/中键平移/Esc 同免 */
|
|
56
|
+
interactive?: boolean);
|
|
44
57
|
/** 指针手势进行中(移动/缩放/框选/表格拖选/参考线等全部手势族;纯点击按下
|
|
45
58
|
* 未 move 也算——pointerup 才清)。只读面:宿主只作判据(如 compat
|
|
46
59
|
* `_currentTransform` 兼容位 → 快照防抖拖动期顺延),不得驱动行为分支 */
|
|
47
60
|
get pointerActive(): boolean;
|
|
48
61
|
/** 监听摘除 + 子控制器销毁(EngineCanvas.dispose 首位;顺序与拆分前一致) */
|
|
62
|
+
/** 切页重订(批次 410 D-4):本级 doc 事件束 + 级联 tableInteraction;
|
|
63
|
+
* pointer/dblClick 无 doc bus 订阅免迁 */
|
|
64
|
+
retargetDoc(doc: EngineDocument): void;
|
|
49
65
|
dispose(): void;
|
|
50
66
|
}
|
|
@@ -9,8 +9,14 @@
|
|
|
9
9
|
* object:removed → 动画源释放)也在此接线。EngineCanvas 只留构造一行与
|
|
10
10
|
* dispose 一行;宿主面 = 既有四个 host 接口之并(panning 让位判定走
|
|
11
11
|
* PointerHost 公共面)。
|
|
12
|
+
*
|
|
13
|
+
* 静态模式(interactive=false,EngineCanvasOptions.interactive——VideoPlay
|
|
14
|
+
* 播放预览等纯展示面):指针/双击/中键平移/滚轮/Esc 五类交互监听整体不挂
|
|
15
|
+
* (画布 CSS pointer-events 拦不住 window 级 pointermove,悬停命中须源头
|
|
16
|
+
* 不挂才断根);字体迟到失效与文档事件接线保持(渲染正确性面,与交互无关)。
|
|
12
17
|
*/
|
|
13
18
|
import { AnimatedNode, PuzzleNode } from '../model/scene';
|
|
19
|
+
import { DocBusBinder } from '../core/events';
|
|
14
20
|
import { PointerController } from './pointer';
|
|
15
21
|
import { DoubleClickController } from './dblClick';
|
|
16
22
|
import { TableInteractionController } from './tableInteraction';
|
|
@@ -19,6 +25,7 @@ export class CanvasInteractionsController {
|
|
|
19
25
|
host;
|
|
20
26
|
snapGuide;
|
|
21
27
|
sources;
|
|
28
|
+
interactive;
|
|
22
29
|
/** 左键交互(选择/移动/缩放/旋转/框选);宿主自身实现 PointerHost */
|
|
23
30
|
pointer;
|
|
24
31
|
/** 表格键盘交互 + 单元格态生命周期(P4-4b) */
|
|
@@ -26,14 +33,19 @@ export class CanvasInteractionsController {
|
|
|
26
33
|
/** 双击派发(P5-7):表格格/拼图蒙版/文本编辑三会话 + 图片族智能对象/替换图事件边界 */
|
|
27
34
|
dblClick;
|
|
28
35
|
detachListeners = null;
|
|
29
|
-
|
|
36
|
+
/** doc bus 订阅束(批次 410 D-4):切页 retarget(级联 tableInteraction) */
|
|
37
|
+
docBus = null;
|
|
30
38
|
lastPanPointer = null;
|
|
31
|
-
constructor(host, snapGuide, sources
|
|
39
|
+
constructor(host, snapGuide, sources,
|
|
40
|
+
/** 交互/静态模式(EngineCanvasOptions.interactive,默认 true=交互):
|
|
41
|
+
* 静态时下传 Pointer/DoubleClick 不挂监听,本级 wheel/中键平移/Esc 同免 */
|
|
42
|
+
interactive = true) {
|
|
32
43
|
this.host = host;
|
|
33
44
|
this.snapGuide = snapGuide;
|
|
34
45
|
this.sources = sources;
|
|
46
|
+
this.interactive = interactive;
|
|
35
47
|
const el = host.canvasEl;
|
|
36
|
-
this.pointer = new PointerController(el, host);
|
|
48
|
+
this.pointer = new PointerController(el, host, this.interactive);
|
|
37
49
|
this.tableInteraction = new TableInteractionController(host);
|
|
38
50
|
// Esc 退出蒙版编辑会话(P4-5b(3/3);表格单元格态的 Esc 在
|
|
39
51
|
// TableInteractionController,两处按键不冲突——会话态互斥)。
|
|
@@ -48,28 +60,32 @@ export class CanvasInteractionsController {
|
|
|
48
60
|
host.requestRenderAll();
|
|
49
61
|
}
|
|
50
62
|
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
63
|
+
if (this.interactive)
|
|
64
|
+
window.addEventListener('keydown', onMaskSessionEsc);
|
|
65
|
+
// 文档事件(选区/变换)→ 重渲染;文本编辑事件由 TextEditingController 自订。
|
|
66
|
+
// 批次 410 D-4:DocBusBinder 束化(切页 retarget——多页态选区/吸附/源释放
|
|
67
|
+
// 事件随活动页走)
|
|
68
|
+
this.docBus = new DocBusBinder(host.document.events, (docBus) => {
|
|
69
|
+
const rerender = () => host.requestRenderAll();
|
|
70
|
+
const offs = [
|
|
71
|
+
docBus.on('selection:created', rerender),
|
|
72
|
+
docBus.on('selection:updated', rerender),
|
|
73
|
+
docBus.on('selection:cleared', rerender),
|
|
74
|
+
docBus.on('object:modified', rerender),
|
|
75
|
+
// 拖拽吸附登记(P5-2 帧率化):moving 事件只登记,render 入口统一结算一次;
|
|
76
|
+
// flag 逐帧读取(SnapGuideController 内部短路),关态零开销
|
|
77
|
+
docBus.on('object:moving', (target) => this.snapGuide.registerMove(target)),
|
|
78
|
+
// 动画源随节点删除释放(视频断流/纹理归还;场景级重建走 loadObjects 前置释放)
|
|
79
|
+
docBus.on('object:removed', (node) => {
|
|
80
|
+
if (node instanceof AnimatedNode)
|
|
81
|
+
this.sources.releaseAnimatedNode(node);
|
|
82
|
+
})
|
|
83
|
+
];
|
|
84
|
+
return () => offs.forEach((off) => off());
|
|
85
|
+
});
|
|
70
86
|
// 双击派发(P5-7 拆出至 DoubleClickController):表格格/拼图蒙版/文本编辑
|
|
71
87
|
// 三会话 + 图片族 smartobject:open-requested / image:replace-requested 事件边界
|
|
72
|
-
this.dblClick = new DoubleClickController(host);
|
|
88
|
+
this.dblClick = new DoubleClickController(host, this.interactive);
|
|
73
89
|
// 中键平移 + 滚轮手势(批次 73:普通滚=垂直平移/shift=水平/ctrl·cmd·alt=缩放,
|
|
74
90
|
// fabric FabricScroll 逐式——逻辑在 interact/wheelScroll,host 由装配层实现)
|
|
75
91
|
const onWheel = (e) => {
|
|
@@ -120,10 +136,12 @@ export class CanvasInteractionsController {
|
|
|
120
136
|
// 宿主/旧 jsdom 可能缺失,可选链守卫
|
|
121
137
|
const onFontsLoaded = (e) => host.handleFontsLoaded(e.fontfaces ?? []);
|
|
122
138
|
document.fonts?.addEventListener?.('loadingdone', onFontsLoaded);
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
139
|
+
if (this.interactive) {
|
|
140
|
+
el.addEventListener('wheel', onWheel, { passive: false });
|
|
141
|
+
el.addEventListener('pointerdown', onPointerDown);
|
|
142
|
+
window.addEventListener('pointermove', onPointerMove);
|
|
143
|
+
window.addEventListener('pointerup', onPointerUp);
|
|
144
|
+
}
|
|
127
145
|
this.detachListeners = () => {
|
|
128
146
|
document.fonts?.removeEventListener?.('loadingdone', onFontsLoaded);
|
|
129
147
|
el.removeEventListener('wheel', onWheel);
|
|
@@ -140,9 +158,15 @@ export class CanvasInteractionsController {
|
|
|
140
158
|
return this.pointer.active;
|
|
141
159
|
}
|
|
142
160
|
/** 监听摘除 + 子控制器销毁(EngineCanvas.dispose 首位;顺序与拆分前一致) */
|
|
161
|
+
/** 切页重订(批次 410 D-4):本级 doc 事件束 + 级联 tableInteraction;
|
|
162
|
+
* pointer/dblClick 无 doc bus 订阅免迁 */
|
|
163
|
+
retargetDoc(doc) {
|
|
164
|
+
this.docBus?.retarget(doc.events);
|
|
165
|
+
this.tableInteraction.retargetDoc(doc);
|
|
166
|
+
}
|
|
143
167
|
dispose() {
|
|
144
168
|
this.detachListeners?.();
|
|
145
|
-
this.
|
|
169
|
+
this.docBus?.dispose();
|
|
146
170
|
this.pointer.dispose();
|
|
147
171
|
this.dblClick.dispose();
|
|
148
172
|
this.tableInteraction.dispose();
|
|
@@ -39,12 +39,29 @@ export interface DblClickHost {
|
|
|
39
39
|
enterTextEditingAtClick: (node: TextNode, x: number, y: number) => void;
|
|
40
40
|
/** 外部绘制会话挂起位(PointerHost 同名同义;可选=单测桩宿主免实现) */
|
|
41
41
|
interactionSuspended?: boolean;
|
|
42
|
+
/** 多页路由三面(批次 409 D-3,PointerHost 同名同义;可选=单页回退):
|
|
43
|
+
* css→绝对坐标 / 绝对点→目标页(null=gap)/ 命中非活动页时激活 */
|
|
44
|
+
toSceneAbs?: (cssX: number, cssY: number) => {
|
|
45
|
+
x: number;
|
|
46
|
+
y: number;
|
|
47
|
+
};
|
|
48
|
+
resolvePointerTarget?: (sceneAbsX: number, sceneAbsY: number) => {
|
|
49
|
+
doc: EngineDocument;
|
|
50
|
+
local: {
|
|
51
|
+
x: number;
|
|
52
|
+
y: number;
|
|
53
|
+
};
|
|
54
|
+
routed: boolean;
|
|
55
|
+
} | null;
|
|
56
|
+
activateRoutedDocument?: (doc: EngineDocument) => void;
|
|
42
57
|
}
|
|
43
58
|
export declare class DoubleClickController {
|
|
44
59
|
private readonly host;
|
|
45
60
|
private readonly onDblClick;
|
|
46
61
|
private disposed;
|
|
47
|
-
|
|
62
|
+
/** 交互/静态模式(静态画布监听不挂;dispose 的 remove 对未挂监听安全) */
|
|
63
|
+
private readonly interactive;
|
|
64
|
+
constructor(host: DblClickHost, interactive?: boolean);
|
|
48
65
|
/** 命中后派发;监听只做坐标换算与命中,分支语义的单测直入口 */
|
|
49
66
|
dispatch(target: SceneNode | null, sceneX: number, sceneY: number): void;
|
|
50
67
|
dispose(): void;
|
|
@@ -39,13 +39,26 @@ export class DoubleClickController {
|
|
|
39
39
|
host;
|
|
40
40
|
onDblClick;
|
|
41
41
|
disposed = false;
|
|
42
|
-
|
|
42
|
+
/** 交互/静态模式(静态画布监听不挂;dispose 的 remove 对未挂监听安全) */
|
|
43
|
+
interactive;
|
|
44
|
+
constructor(host, interactive = true) {
|
|
43
45
|
this.host = host;
|
|
46
|
+
this.interactive = interactive;
|
|
44
47
|
this.onDblClick = (e) => {
|
|
45
48
|
// 外部绘制会话(compat 绘制桥)挂起期不派发——绘制中双击不得进编辑会话
|
|
46
49
|
if (host.interactionSuspended)
|
|
47
50
|
return;
|
|
48
51
|
const rect = host.canvasEl.getBoundingClientRect();
|
|
52
|
+
// 多页路由(批次 409 D-3):命中页自动激活(同 pointer down 口径),
|
|
53
|
+
// gap 不派发;单页态(宿主无路由面)回退原坐标
|
|
54
|
+
if (host.resolvePointerTarget) {
|
|
55
|
+
const abs = host.toSceneAbs ? host.toSceneAbs(e.clientX - rect.left, e.clientY - rect.top) : host.toScene(e.clientX - rect.left, e.clientY - rect.top);
|
|
56
|
+
const entry = host.resolvePointerTarget(abs.x, abs.y);
|
|
57
|
+
if (!entry)
|
|
58
|
+
return;
|
|
59
|
+
if (entry.doc !== host.document)
|
|
60
|
+
host.activateRoutedDocument?.(entry.doc);
|
|
61
|
+
}
|
|
49
62
|
const p = host.toScene(e.clientX - rect.left, e.clientY - rect.top);
|
|
50
63
|
// 组穿透下钻(P5-1 组交互片):见文件头注释——多层组合双击落组内子元素
|
|
51
64
|
let target = host.document.findTarget(p.x, p.y);
|
|
@@ -56,7 +69,8 @@ export class DoubleClickController {
|
|
|
56
69
|
}
|
|
57
70
|
this.dispatch(target, p.x, p.y);
|
|
58
71
|
};
|
|
59
|
-
|
|
72
|
+
if (this.interactive)
|
|
73
|
+
host.canvasEl.addEventListener('dblclick', this.onDblClick);
|
|
60
74
|
}
|
|
61
75
|
/** 命中后派发;监听只做坐标换算与命中,分支语义的单测直入口 */
|
|
62
76
|
dispatch(target, sceneX, sceneY) {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { EngineDocument } from '../model/document';
|
|
2
|
+
import { type SceneNode, type SerializedNode } from '../model/scene';
|
|
3
|
+
import type { MultiPageController } from '../render/multiPage';
|
|
4
|
+
export interface PageTransferItem {
|
|
5
|
+
/** Source z order, excluding derived decoration nodes. */
|
|
6
|
+
index: number;
|
|
7
|
+
before: SerializedNode;
|
|
8
|
+
after: SerializedNode;
|
|
9
|
+
}
|
|
10
|
+
export interface PageTransfer {
|
|
11
|
+
sourceIndex: number;
|
|
12
|
+
targetIndex: number;
|
|
13
|
+
source: EngineDocument;
|
|
14
|
+
target: EngineDocument;
|
|
15
|
+
nodes: SceneNode[];
|
|
16
|
+
items: PageTransferItem[];
|
|
17
|
+
}
|
|
18
|
+
/** Commit a completed root-object drag. Append in document order, never selection order. */
|
|
19
|
+
export declare function transferPageNodes(pages: MultiPageController, candidates: readonly SceneNode[], before: ReadonlyMap<SceneNode, SerializedNode> | undefined, point: {
|
|
20
|
+
x: number;
|
|
21
|
+
y: number;
|
|
22
|
+
}, ensureBuilt: (index: number) => void): PageTransfer | null;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { GroupNode, WORKSPACE_IDS } from '../model/scene';
|
|
2
|
+
/** Commit a completed root-object drag. Append in document order, never selection order. */
|
|
3
|
+
export function transferPageNodes(pages, candidates, before, point, ensureBuilt) {
|
|
4
|
+
if (pages.pageCount < 2)
|
|
5
|
+
return null;
|
|
6
|
+
const hit = pages.route(point.x, point.y);
|
|
7
|
+
const sourceIndex = pages.activeIndex;
|
|
8
|
+
if (!hit || hit.index === sourceIndex)
|
|
9
|
+
return null;
|
|
10
|
+
const source = pages.activeDoc;
|
|
11
|
+
const selected = new Set(candidates);
|
|
12
|
+
const roots = source.nodes.filter((node) => selected.has(node) && !node.syntheticOwner && !WORKSPACE_IDS.has(node.id));
|
|
13
|
+
if (!roots.length || roots.length !== selected.size)
|
|
14
|
+
return null;
|
|
15
|
+
ensureBuilt(hit.index);
|
|
16
|
+
const target = hit.doc;
|
|
17
|
+
const sourceOrigin = pages.originAt(sourceIndex);
|
|
18
|
+
const targetOrigin = pages.originAt(hit.index);
|
|
19
|
+
const sourceOrder = source.nodes.filter((node) => !node.syntheticOwner);
|
|
20
|
+
const items = roots.map((node) => ({ index: sourceOrder.indexOf(node), before: before?.get(node) ?? node.toObject(), after: node.toObject() }));
|
|
21
|
+
// Copied pages may share IDs. Re-key collisions (including group children) without
|
|
22
|
+
// changing node identity/assets, so selecting/deleting the imported object is unambiguous.
|
|
23
|
+
const ids = new Set();
|
|
24
|
+
const visit = (node, fn) => {
|
|
25
|
+
fn(node);
|
|
26
|
+
if (node instanceof GroupNode)
|
|
27
|
+
for (const child of node.children)
|
|
28
|
+
visit(child, fn);
|
|
29
|
+
};
|
|
30
|
+
for (const node of target.nodes)
|
|
31
|
+
visit(node, (child) => {
|
|
32
|
+
if (child.id)
|
|
33
|
+
ids.add(child.id);
|
|
34
|
+
});
|
|
35
|
+
for (const node of roots) {
|
|
36
|
+
source.remove(node);
|
|
37
|
+
visit(node, (child) => {
|
|
38
|
+
if (child.id && ids.has(child.id)) {
|
|
39
|
+
const base = child.id;
|
|
40
|
+
let suffix = 1;
|
|
41
|
+
while (ids.has(`${base}-transfer-${suffix}`))
|
|
42
|
+
suffix++;
|
|
43
|
+
child.set({ id: `${base}-transfer-${suffix}` });
|
|
44
|
+
}
|
|
45
|
+
if (child.id)
|
|
46
|
+
ids.add(child.id);
|
|
47
|
+
});
|
|
48
|
+
node.set({ left: Number(node.raw.left ?? 0) + sourceOrigin.x - targetOrigin.x, top: Number(node.raw.top ?? 0) + sourceOrigin.y - targetOrigin.y });
|
|
49
|
+
target.add(node);
|
|
50
|
+
}
|
|
51
|
+
source.clearSelection();
|
|
52
|
+
roots.forEach((node, i) => {
|
|
53
|
+
items[i].after = node.toObject();
|
|
54
|
+
});
|
|
55
|
+
return { sourceIndex, targetIndex: hit.index, source, target, nodes: roots, items };
|
|
56
|
+
}
|
|
@@ -39,6 +39,9 @@ export declare class PointerController {
|
|
|
39
39
|
private performed;
|
|
40
40
|
/** 悬停中的表格(P4-4b 悬停态生命周期:换目标/离场时清旧态并重绘) */
|
|
41
41
|
private hoveredTable;
|
|
42
|
+
/** 悬停路由页(批次 409 D-3):hover 逐点路由可落非活动页——跨页时清旧页
|
|
43
|
+
* hovered 防陈旧边框(该页再激活时复活);离场清理同源 */
|
|
44
|
+
private lastHoverDoc;
|
|
42
45
|
/** 多选成员点击的延迟切换目标(ActiveSelection 态点成员,应用 fabric 时代
|
|
43
46
|
* _deferredClickThroughTarget 的同源时机原则——docs/2026-04-28 组点击穿透:
|
|
44
47
|
* mousedown 先保持当前选中态便于拖动/框选,mouseup 确认是 click 才切换):
|
|
@@ -47,7 +50,10 @@ export declare class PointerController {
|
|
|
47
50
|
* 统一清;表格单元格手势转 move(拖动意图明确)时提前作废 */
|
|
48
51
|
private deferredClickSwitch;
|
|
49
52
|
private detach;
|
|
50
|
-
|
|
53
|
+
/** 交互/静态模式(静态画布监听整体不挂——CSS pointer-events 拦不住
|
|
54
|
+
* window 级 pointermove 的悬停命中,须源头不挂才断根;dispose 恒安全) */
|
|
55
|
+
private readonly interactive;
|
|
56
|
+
constructor(el: HTMLElement, host: PointerHost, interactive?: boolean);
|
|
51
57
|
get active(): boolean;
|
|
52
58
|
/** 当前命中的缩放/旋转手柄(屏幕空间半径内),供宿主设光标。手柄集与渲染
|
|
53
59
|
* 同源走 getAdaptiveSelectionHandles——小对象被裁剪的手柄不可命中(app
|
package/dist/interact/pointer.js
CHANGED
|
@@ -153,6 +153,9 @@ export class PointerController {
|
|
|
153
153
|
performed = false;
|
|
154
154
|
/** 悬停中的表格(P4-4b 悬停态生命周期:换目标/离场时清旧态并重绘) */
|
|
155
155
|
hoveredTable = null;
|
|
156
|
+
/** 悬停路由页(批次 409 D-3):hover 逐点路由可落非活动页——跨页时清旧页
|
|
157
|
+
* hovered 防陈旧边框(该页再激活时复活);离场清理同源 */
|
|
158
|
+
lastHoverDoc = null;
|
|
156
159
|
/** 多选成员点击的延迟切换目标(ActiveSelection 态点成员,应用 fabric 时代
|
|
157
160
|
* _deferredClickThroughTarget 的同源时机原则——docs/2026-04-28 组点击穿透:
|
|
158
161
|
* mousedown 先保持当前选中态便于拖动/框选,mouseup 确认是 click 才切换):
|
|
@@ -161,9 +164,13 @@ export class PointerController {
|
|
|
161
164
|
* 统一清;表格单元格手势转 move(拖动意图明确)时提前作废 */
|
|
162
165
|
deferredClickSwitch = null;
|
|
163
166
|
detach = null;
|
|
164
|
-
|
|
167
|
+
/** 交互/静态模式(静态画布监听整体不挂——CSS pointer-events 拦不住
|
|
168
|
+
* window 级 pointermove 的悬停命中,须源头不挂才断根;dispose 恒安全) */
|
|
169
|
+
interactive;
|
|
170
|
+
constructor(el, host, interactive = true) {
|
|
165
171
|
this.el = el;
|
|
166
172
|
this.host = host;
|
|
173
|
+
this.interactive = interactive;
|
|
167
174
|
this.attach();
|
|
168
175
|
}
|
|
169
176
|
get active() {
|
|
@@ -287,8 +294,7 @@ export class PointerController {
|
|
|
287
294
|
}
|
|
288
295
|
/** 空闲态悬停光标:表外指示器 → 行/列选择条与拖动把手 → 手柄 → 表格边框/指示器 → 对象 move;空白默认。
|
|
289
296
|
* 手柄光标单选/多选都生效(与 onPointerDown 手柄命中同口径;多选角度恒 0) */
|
|
290
|
-
hoverCursor(cssX, cssY, p) {
|
|
291
|
-
const doc = this.host.document;
|
|
297
|
+
hoverCursor(cssX, cssY, p, doc = this.host.document) {
|
|
292
298
|
// 标尺带(批次 72):带内 ns/ew-resize(app FabricRuler.mouseMove
|
|
293
299
|
// getPointHover 同判序同光标——上带产横线 ns-resize / 左带产竖线 ew-resize)
|
|
294
300
|
if (this.host.rulerVisible) {
|
|
@@ -473,8 +479,14 @@ export class PointerController {
|
|
|
473
479
|
* 批次 305 补③:蒙版会话态(选中了格)行杠照常——编辑块自身的柄位让位
|
|
474
480
|
* (0.7 命中域),其余缝照出(gap 全域被行杠带覆盖,会话期点 gap 不再退
|
|
475
481
|
* 出——与柄点击同款无操作,退出走点外/Esc) */
|
|
476
|
-
updateHover(cssX, cssY, p) {
|
|
477
|
-
|
|
482
|
+
updateHover(cssX, cssY, p, doc = this.host.document) {
|
|
483
|
+
// 跨页清旧(批次 409 D-3):hover 路由页切换时清旧页 hovered + 表格悬停态
|
|
484
|
+
if (doc !== this.lastHoverDoc) {
|
|
485
|
+
this.lastHoverDoc?.setHovered(null);
|
|
486
|
+
this.hoveredTable = null;
|
|
487
|
+
this.lastHoverDoc = doc;
|
|
488
|
+
this.host.requestRenderAll();
|
|
489
|
+
}
|
|
478
490
|
let next = null;
|
|
479
491
|
let seamNext = null;
|
|
480
492
|
// 会话整体取代选区 UI——悬停边框不参与(app isCropping 同语义域;
|
|
@@ -529,6 +541,9 @@ export class PointerController {
|
|
|
529
541
|
this.host.requestRenderAll();
|
|
530
542
|
}
|
|
531
543
|
attach() {
|
|
544
|
+
// 静态画布:监听整体不挂(手势/悬停命中全让位);dispose 的 detach 空置安全
|
|
545
|
+
if (!this.interactive)
|
|
546
|
+
return;
|
|
532
547
|
const el = this.el;
|
|
533
548
|
const onDown = (e) => {
|
|
534
549
|
if (e.button !== 0)
|
|
@@ -568,6 +583,10 @@ export class PointerController {
|
|
|
568
583
|
const doc = this.host.document;
|
|
569
584
|
const prev = doc.hovered;
|
|
570
585
|
doc.setHovered(null);
|
|
586
|
+
// 多页:hover 可能落在非活动页(批次 409 D-3 路由)——离场一并清
|
|
587
|
+
if (this.lastHoverDoc && this.lastHoverDoc !== doc)
|
|
588
|
+
this.lastHoverDoc.setHovered(null);
|
|
589
|
+
this.lastHoverDoc = null;
|
|
571
590
|
this.el.style.cursor = '';
|
|
572
591
|
if (doc.hovered !== prev)
|
|
573
592
|
this.host.requestRenderAll();
|
|
@@ -584,6 +603,22 @@ export class PointerController {
|
|
|
584
603
|
};
|
|
585
604
|
}
|
|
586
605
|
onPointerDown(cssX, cssY, shift) {
|
|
606
|
+
// 多页路由(批次 409 D-3):命中页自动激活(Canva 点哪页哪页激活——吸附
|
|
607
|
+
// 候选/会话发现/选区/overlay 经 document 天然落手势页;激活后 toScene 即
|
|
608
|
+
// 手势页页内坐标,手势全程活动页冻结)。页间 gap = 点空收尾(清选区、
|
|
609
|
+
// 不框选不拖拽)。单页态(宿主无路由面)行为逐位不变。吞没性会话期宿主
|
|
610
|
+
// 自锁活动页(resolvePointerTarget 的会话模态形态——点外退出语义保持)
|
|
611
|
+
if (this.host.resolvePointerTarget) {
|
|
612
|
+
const abs = this.host.toSceneAbs ? this.host.toSceneAbs(cssX, cssY) : this.host.toScene(cssX, cssY);
|
|
613
|
+
const entry = this.host.resolvePointerTarget(abs.x, abs.y);
|
|
614
|
+
if (!entry) {
|
|
615
|
+
this.host.document.clearSelection();
|
|
616
|
+
this.host.requestRenderAll();
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
if (entry.doc !== this.host.document)
|
|
620
|
+
this.host.activateRoutedDocument?.(entry.doc);
|
|
621
|
+
}
|
|
587
622
|
const doc = this.host.document;
|
|
588
623
|
const p = this.host.toScene(cssX, cssY);
|
|
589
624
|
this.performed = false;
|
|
@@ -1230,7 +1265,25 @@ export class PointerController {
|
|
|
1230
1265
|
const p = this.host.toScene(cssX, cssY);
|
|
1231
1266
|
const g = this.gesture;
|
|
1232
1267
|
if (g.type === 'none') {
|
|
1233
|
-
// 空闲态更新光标提示 + 悬停边框(P5-3
|
|
1268
|
+
// 空闲态更新光标提示 + 悬停边框(P5-3)。多页路由(批次 409 D-3):
|
|
1269
|
+
// hover 逐点路由到指针所在页(不激活——切页只在 down),页内坐标喂
|
|
1270
|
+
// 命中/边框;gap = 清悬停默认光标。单页态回退原行为
|
|
1271
|
+
if (this.host.resolvePointerTarget) {
|
|
1272
|
+
const abs = this.host.toSceneAbs ? this.host.toSceneAbs(cssX, cssY) : this.host.toScene(cssX, cssY);
|
|
1273
|
+
const entry = this.host.resolvePointerTarget(abs.x, abs.y);
|
|
1274
|
+
if (!entry) {
|
|
1275
|
+
if (this.lastHoverDoc) {
|
|
1276
|
+
this.lastHoverDoc.setHovered(null);
|
|
1277
|
+
this.lastHoverDoc = null;
|
|
1278
|
+
this.host.requestRenderAll();
|
|
1279
|
+
}
|
|
1280
|
+
this.el.style.cursor = 'default';
|
|
1281
|
+
return;
|
|
1282
|
+
}
|
|
1283
|
+
this.el.style.cursor = this.hoverCursor(cssX, cssY, entry.local, entry.doc);
|
|
1284
|
+
this.updateHover(cssX, cssY, entry.local, entry.doc);
|
|
1285
|
+
return;
|
|
1286
|
+
}
|
|
1234
1287
|
this.el.style.cursor = this.hoverCursor(cssX, cssY, p);
|
|
1235
1288
|
this.updateHover(cssX, cssY, p);
|
|
1236
1289
|
return;
|
|
@@ -1485,7 +1538,10 @@ export class PointerController {
|
|
|
1485
1538
|
doc.applyTransform(targets, () => ({}), 'modified', { action: 'drag', before: g.historyBefore });
|
|
1486
1539
|
}
|
|
1487
1540
|
else {
|
|
1488
|
-
|
|
1541
|
+
const nodes = [...g.snapshot.keys()];
|
|
1542
|
+
if (!this.host.transferDraggedNodes?.(nodes, g.historyBefore, cssX, cssY)) {
|
|
1543
|
+
doc.applyTransform(nodes, () => ({}), 'modified', { action: 'drag', before: g.historyBefore });
|
|
1544
|
+
}
|
|
1489
1545
|
}
|
|
1490
1546
|
}
|
|
1491
1547
|
else if (this.deferredClickSwitch) {
|
|
@@ -102,6 +102,29 @@ export interface PointerHost {
|
|
|
102
102
|
* EngineCanvasOptions.mobileControls 直通)。可选=单测桩宿主免实现
|
|
103
103
|
* (缺省无移动控件交互,桌面行为零变化) */
|
|
104
104
|
mobileControls?: boolean;
|
|
105
|
+
/** 多页路由(批次 409 D-3):css → 画布绝对场景坐标(布局系,未减页偏移)。
|
|
106
|
+
* 可选=单测桩/单页宿主免实现(回退 toScene) */
|
|
107
|
+
toSceneAbs?: (cssX: number, cssY: number) => {
|
|
108
|
+
x: number;
|
|
109
|
+
y: number;
|
|
110
|
+
};
|
|
111
|
+
/** 多页路由(批次 409 D-3):绝对场景点 → 指针目标页。null = 页间 gap
|
|
112
|
+
* (空带无页可交互);吞没性编辑会话期宿主自锁活动页(会话模态)。
|
|
113
|
+
* 可选=单页回退(active doc + 原坐标,行为逐位不变) */
|
|
114
|
+
resolvePointerTarget?: (sceneAbsX: number, sceneAbsY: number) => {
|
|
115
|
+
doc: EngineDocument;
|
|
116
|
+
local: {
|
|
117
|
+
x: number;
|
|
118
|
+
y: number;
|
|
119
|
+
};
|
|
120
|
+
routed: boolean;
|
|
121
|
+
} | null;
|
|
122
|
+
/** 多页路由(批次 409 D-3):down/双击命中非活动页时激活该页(Canva 点哪页
|
|
123
|
+
* 哪页激活——吸附候选/会话发现/选区/overlay 经 document 天然落手势页)。
|
|
124
|
+
* 可选=单页回退(无操作) */
|
|
125
|
+
activateRoutedDocument?: (doc: EngineDocument) => void;
|
|
126
|
+
/** Completed root drag: transfer ownership to the page under the release point. */
|
|
127
|
+
transferDraggedNodes?: (nodes: SceneNode[], before: Map<SceneNode, SerializedNode> | undefined, cssX: number, cssY: number) => boolean;
|
|
105
128
|
}
|
|
106
129
|
/** B3 扩图会话在 pointer 侧的消费面(ExpandSessionController 实现) */
|
|
107
130
|
export interface ExpandSessionHandle {
|
|
@@ -31,9 +31,12 @@ export interface TableCellEditingHost {
|
|
|
31
31
|
export declare class TableCellEditingController {
|
|
32
32
|
private readonly host;
|
|
33
33
|
private session;
|
|
34
|
-
|
|
34
|
+
/** doc bus 订阅束(批次 410 D-4):切页 retarget */
|
|
35
|
+
private readonly docBus;
|
|
35
36
|
private disposed;
|
|
36
37
|
constructor(host: TableCellEditingHost);
|
|
38
|
+
/** 切页重订(批次 410 D-4;同 bus 幂等) */
|
|
39
|
+
retargetDoc(doc: EngineDocument): void;
|
|
37
40
|
dispose(): void;
|
|
38
41
|
get active(): boolean;
|
|
39
42
|
/** 编辑 overlay 判定(EngineCanvas 渲染层抑制边框用) */
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
* - typover(initialText):overlay 以按键字符创建、光标置其末(应用
|
|
21
21
|
* pendingPrintableKey 注入的同步等价物——引擎 overlay 预置文本无需回注)。
|
|
22
22
|
*/
|
|
23
|
+
import { DocBusBinder } from '../core/events';
|
|
23
24
|
import { TextNode } from '../model/scene';
|
|
24
25
|
import { getCellData, masterPosition } from '../model/tableEdit';
|
|
25
26
|
import { TextAlignValues } from '../model/textAlign';
|
|
@@ -30,24 +31,30 @@ const tableFontFamilyOf = (raw) => raw.fontFamily || '仓耳小丸子';
|
|
|
30
31
|
export class TableCellEditingController {
|
|
31
32
|
host;
|
|
32
33
|
session = null;
|
|
33
|
-
|
|
34
|
+
/** doc bus 订阅束(批次 410 D-4):切页 retarget */
|
|
35
|
+
docBus;
|
|
34
36
|
disposed = false;
|
|
35
37
|
constructor(host) {
|
|
36
38
|
this.host = host;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
this.docBus = new DocBusBinder(host.document.events, (bus) => {
|
|
40
|
+
const offs = [
|
|
41
|
+
bus.on('text:changed', (node) => this.onTextChanged(node)),
|
|
42
|
+
bus.on('text:editing:exited', () => this.finish()),
|
|
43
|
+
// overlay 被外部移除(非本控制器收口):静默清态不提交
|
|
44
|
+
bus.on('object:removed', (node) => this.onOverlayRemoved(node))
|
|
45
|
+
];
|
|
46
|
+
return () => offs.forEach((off) => off());
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/** 切页重订(批次 410 D-4;同 bus 幂等) */
|
|
50
|
+
retargetDoc(doc) {
|
|
51
|
+
this.docBus.retarget(doc.events);
|
|
45
52
|
}
|
|
46
53
|
dispose() {
|
|
47
54
|
if (this.disposed)
|
|
48
55
|
return;
|
|
49
56
|
this.disposed = true;
|
|
50
|
-
this.
|
|
57
|
+
this.docBus.dispose();
|
|
51
58
|
}
|
|
52
59
|
get active() {
|
|
53
60
|
return this.session !== null;
|
|
@@ -33,9 +33,12 @@ export interface TableInteractionHost {
|
|
|
33
33
|
export declare class TableInteractionController {
|
|
34
34
|
private readonly host;
|
|
35
35
|
private readonly onKeydown;
|
|
36
|
-
|
|
36
|
+
/** doc bus 订阅束(批次 410 D-4):切页 retarget */
|
|
37
|
+
private readonly docBus;
|
|
37
38
|
private disposed;
|
|
38
39
|
constructor(host: TableInteractionHost);
|
|
40
|
+
/** 切页重订(批次 410 D-4;同 bus 幂等) */
|
|
41
|
+
retargetDoc(doc: EngineDocument): void;
|
|
39
42
|
dispose(): void;
|
|
40
43
|
/** 选区外的表格清单元格态(选中态自身保留——点击画布空白/换选时旧高亮不残留) */
|
|
41
44
|
private pruneCellState;
|