使用说明
setup(props, ctx) 与 Vue 3 使用相同的参数顺序,并对普通 Component、Component Set 和普通图形节点统一有效。第一个参数是当前具体 FlamoInstance 的只读响应式输入;Component Set 继承脚本会收到当前 concrete INSTANCE 的有效 surface 与 Variant 参数。第二个参数负责状态、监听、节点访问、代理和公开方法。
节点的 x / y / fill / opacity / text 等视觉字段不会自动进入 props。普通图形不消费实例输入时使用 _props,通过 ctx.node().design() / current() 读取节点,通过语义 setter 或动画 API 修改节点。defineNodeScript<Props> 只增加 TypeScript 类型检查,不会创建 Artifact public surface。
export default defineNodeScript({ setup(props, ctx) { ctx.on('click', event => { ctx.emit('onClick', { targetNodeId: event.target, disabled: props.disabled }); }); },});普通图形脚本:
export default defineNodeScript({ setup(_props, ctx) { const shape = ctx.node(); if (!shape) return;
const initialOpacity = shape.design().compositing.opacity; ctx.on('pointerenter', () => shape.setOpacity(0.7)); ctx.on('pointerleave', () => shape.setOpacity(initialOpacity)); },});通过 ctx.on()、ctx.onNode()、ctx.delegate()、ctx.dispose() 登记的资源都属于当前 Instance 生命周期;脚本不需要自行管理 ECS、命中缓冲或 runtime clone。完整概念见脚本,事件工作流见事件、节点查询与动态代理。