必须套索之后才能调用该接口,否则会调用失败。
说明
rotationDegree仅对笔划、几何图形和五角星生效,其他元素不会旋转- 在套索数据中,带文本框的元素不支持拉伸缩放,例如文本框标题、链接类文本元素(包括文字链接和通过文本框设置的链接);其他元素均支持拉伸缩放
- 当不需要旋转时,直接省略
rotationDegree
APIResponse<boolean>:result === true表示调整成功
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
调整套索框矩形大小。
static resizeLassoRect(
rect: Rect,
rotationDegree?: number
): Promise<APIResponse<boolean>>;
| 参数 | 类型 | 说明 |
|---|---|---|
rect | Rect | 套索框矩形(像素坐标) |
rotationDegree | number | 可选旋转角度,整数。省略时不旋转;传入后按该角度旋转当前套索中支持旋转的元素 |
rotationDegree 仅对笔划、几何图形和五角星生效,其他元素不会旋转rotationDegreeAPIResponse<boolean>:
result === true 表示调整成功import { PluginCommAPI, type Rect } from 'sn-plugin-lib';
/**
* 按等比例缩放调整套索框矩形,并可选旋转支持元素的示例。
*/
export async function exampleResizeLassoRect(rotationDegree?: number) {
const current = await PluginCommAPI.getLassoRect();
if (!current.success) {
throw new Error(current.error?.message ?? 'getLassoRect 调用失败');
}
const rect = current.result as Rect;
const w = rect.right - rect.left;
const h = rect.bottom - rect.top;
const cx = rect.left + w / 2;
const cy = rect.top + h / 2;
const scale = 1.2;
const nextRect: Rect = {
left: cx - (w * scale) / 2,
top: cy - (h * scale) / 2,
right: cx + (w * scale) / 2,
bottom: cy + (h * scale) / 2,
};
console.log('resizeLassoRect nextRect:', nextRect, 'rotationDegree:', rotationDegree);
const res = await PluginCommAPI.resizeLassoRect(nextRect, rotationDegree);
if (!res.success) {
throw new Error(res.error?.message ?? 'resizeLassoRect 调用失败');
}
console.log('resizeLassoRect result:', res.result);
return res.result;
}