@firetable/project-xiaochun 0.1.14 → 0.1.16

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/element.js CHANGED
@@ -1,10 +1,10 @@
1
- /*! @firetable/project-xiaochun v0.1.14 | MIT | https://github.com/FireTable/project-xiaochun */
1
+ /*! @firetable/project-xiaochun v0.1.16 | MIT | https://github.com/FireTable/project-xiaochun */
2
2
  import {
3
3
  XIAOCHUN_ELEMENT_TAG,
4
4
  defineXiaochunElement
5
- } from "./chunks/chunk-HLVD6HQM.js";
6
- import "./chunks/chunk-OLVSOJML.js";
7
- import "./chunks/chunk-DUU5PTKT.js";
5
+ } from "./chunks/chunk-HZ2ADKG7.js";
6
+ import "./chunks/chunk-UWL65W7D.js";
7
+ import "./chunks/chunk-RHQW4QZH.js";
8
8
 
9
9
  // src/element.ts
10
10
  defineXiaochunElement();
@@ -0,0 +1,72 @@
1
+ /**
2
+ * gesture-box.ts — iframe 手势 (xc.gesture-move / xc.gesture-resize) 在宿主侧的纯逻辑: 校验 + 几何限幅。零 DOM 依赖, 可单测。
3
+ *
4
+ * 宿主 SDK 对 iframe 发来的手势**不信任**: 载荷逐字段校验 (类型 / 有限数 / 量级 / 角名), 序号必须按规则递增 (GestureGate),
5
+ * 位置 / 尺寸全部在这里按"当前视口 + 最小 / 最大尺寸"夹紧, iframe 说多少就移多少是不可能的。
6
+ * 计算一律用 start 时的盒子 + 累计位移 (totalDx / totalDy), 不累加增量: 丢包 / 夹紧都不会让结果漂移。
7
+ */
8
+ import type { XcGestureCorner } from './protocol';
9
+ export interface Box {
10
+ left: number;
11
+ top: number;
12
+ width: number;
13
+ height: number;
14
+ }
15
+ export interface Viewport {
16
+ width: number;
17
+ height: number;
18
+ }
19
+ export interface ResizeLimits {
20
+ minWidth: number;
21
+ minHeight: number;
22
+ maxWidth: number;
23
+ maxHeight: number;
24
+ }
25
+ /** 默认限幅: 最小 120x180 (再小角色基本看不清), 最大只受视口限制。 */
26
+ export declare const DEFAULT_RESIZE_LIMITS: Readonly<ResizeLimits>;
27
+ export interface XiaochunResizeLimits {
28
+ /** 最小宽 (px), 默认 120。 */
29
+ minWidth?: number;
30
+ /** 最小高 (px), 默认 180。 */
31
+ minHeight?: number;
32
+ /** 最大宽 (px), 默认只受视口限制。 */
33
+ maxWidth?: number;
34
+ /** 最大高 (px), 默认只受视口限制。 */
35
+ maxHeight?: number;
36
+ }
37
+ /** `resizable` 选项 → 限幅; false / undefined → null (关闭); true → 默认限幅; 对象 → 逐项覆盖 (非法值用默认)。min 不会超过 max。 */
38
+ export declare function normalizeResizable(v: boolean | XiaochunResizeLimits | undefined): ResizeLimits | null;
39
+ /** 移动: 起点盒子 + 累计位移, 夹在视口内 (盒子比视口大时贴左上)。 */
40
+ export declare function moveBox(start: Box, totalDx: number, totalDy: number, vp: Viewport): Box;
41
+ /**
42
+ * 缩放: 被拖的角跟手, 对角固定; 宽高夹在 [min, min(max, 视口内还能伸展的空间)]。
43
+ * 例: 拖 SE 角 → 左上固定, 右 / 下边界不能越过视口; 拖 NW 角 → 右下固定, 左 / 上边界不能越过视口。
44
+ */
45
+ export declare function resizeBox(start: Box, corner: XcGestureCorner, totalDx: number, totalDy: number, limits: ResizeLimits, vp: Viewport): Box;
46
+ /** 窗口 / 视口变小后把盒子重新夹回视口 (尺寸也不超过视口)。 */
47
+ export declare function fitBox(b: Box, vp: Viewport): Box;
48
+ /** 单次累计位移的合理上限 (CSS px)。屏幕再大也到不了, 超过的一律当作伪造。 */
49
+ export declare const MAX_GESTURE_DELTA = 20000;
50
+ export interface ParsedGesture {
51
+ gesture: number;
52
+ seq: number;
53
+ phase: 'start' | 'move' | 'end';
54
+ totalDx: number;
55
+ totalDy: number;
56
+ corner?: XcGestureCorner;
57
+ }
58
+ /** 校验 iframe 发来的手势载荷; 不合法返回 null。kind='resize' 还要求合法的 corner。 */
59
+ export declare function parseGesturePayload(kind: 'move' | 'resize', raw: unknown): ParsedGesture | null;
60
+ /**
61
+ * 手势序号闸门: 只放行"合法的手势序列" —— start(gesture 比上一个大, seq=0) → move* (seq 严格递增) → end。
62
+ * 迟到 / 重放 / 乱序 / 没有 start 的消息一律拒绝。一个闸门对应一种手势 (move 或 resize)。
63
+ */
64
+ export declare class GestureGate {
65
+ private lastGesture;
66
+ private lastSeq;
67
+ private open;
68
+ get active(): boolean;
69
+ accept(p: Pick<ParsedGesture, 'gesture' | 'seq' | 'phase'>): boolean;
70
+ /** 宿主主动结束 (关闭手势 / 销毁): 之后同一手势的迟到消息被拒绝。 */
71
+ close(): void;
72
+ }