import{ax as i,z as a,A as l,b5 as n}from"./chunks/framework.V2ssSR2R.js";const g=JSON.parse('{"title":"uiService方法","description":"","frontmatter":{},"headers":[],"relativePath":"api/editor/uiServiceMethods.md","filePath":"api/editor/uiServiceMethods.md"}'),e={name:"api/editor/uiServiceMethods.md"};function t(h,s,p,k,r,d){return l(),a("div",null,[...s[0]||(s[0]=[n(`

uiService方法

set

js
import { uiService } from '@tmagic/editor';

// 设置缩放比例
uiService.set('zoom', 1.5);

// 设置画布尺寸
uiService.set('stageRect', { width: 375, height: 667 });

// 显示/隐藏参考线
uiService.set('showGuides', true);

// 显示/隐藏标尺
uiService.set('showRule', true);

get

js
import { uiService } from '@tmagic/editor';

const zoom = uiService.get('zoom');
console.log('当前缩放:', zoom);

const stageRect = uiService.get('stageRect');
console.log('画布尺寸:', stageRect);

zoom

js
import { uiService } from '@tmagic/editor';

// 放大0.1倍
await uiService.zoom(0.1);

// 缩小0.1倍
await uiService.zoom(-0.1);

// 当前缩放如果是1.0,执行zoom(0.5)后变为1.5
await uiService.zoom(0.5);

calcZoom

js
import { uiService } from '@tmagic/editor';

const fitZoom = await uiService.calcZoom();
console.log('适应缩放:', fitZoom);

// 应用缩放以适应
uiService.set('zoom', fitZoom);

resetState

js
import { uiService } from '@tmagic/editor';

uiService.resetState();

destroy

js
import { uiService } from '@tmagic/editor';

uiService.destroy();

usePlugin

每个支持扩展的方法都支持定制before、after两个hook来干预原有方法的行为,before可以用于修改传入参数,after可以用于修改返回的值

js
import { uiService } from '@tmagic/editor';

uiService.usePlugin({
  beforeZoom(value) {
    console.log('缩放增量:', value);
    return [value];
  },
  
  afterCalcZoom(result) {
    console.log('计算的缩放:', result);
    // 可以修改返回值
    return result;
  },
});

removeAllPlugins

删掉当前设置的所有扩展

js
import { uiService } from '@tmagic/editor';

uiService.removeAllPlugins();
`,29)])])}const o=i(e,[["render",t]]);export{g as __pageData,o as default};