本地模块组件
first = page.add(card("A"), target=page.top_left, offset=(8 mm, 29 mm))page.add(card("B"), target=first.top_right, offset=(13 mm, 0 mm))# Gallery: containers / module-importimport { card } from "./card-component.lay"page = canvas(name="Imported component", size=(120 mm, 80 mm), background="#f7f9fc")font = "DejaVu Sans"heading = text(content="Imported component", font_family=font, font_size=14 pt, color="#203864")page.add(heading, target=page.top_left, offset=(7 mm, 5 mm))# BEGIN DEMOfirst = page.add(card("A"), target=page.top_left, offset=(8 mm, 29 mm))page.add(card("B"), target=first.top_right, offset=(13 mm, 0 mm))# END DEMO## @lang zh-CN## 创建圆角卡片,并将标题放在中央。## @param {string} label - 标题文字;支持行内公式。## @returns {group} 可重复放置的卡片,宽 42mm、高 31mm。## @example## item = card("结果")## @lang en## Create a rounded card with a centered caption.## @param {string} label - Caption text; supports inline mathematics.## @returns {group} Reusable card material, 42mm wide and 31mm high.## @example## item = card("Result")export function card(label) { item = group() plate = item.add(rect(size=(42 mm, 31 mm), border_radius=3 mm, fill="#d8f0ec", border_color="#087f8c", border_width=0.5 mm), target=item.top_left) item.add(text(content=label, font_family="DejaVu Sans", font_size=11 pt, color="#203864"), anchor=center, target=plate.center) return item}预览
背景
依赖文件
examples/gallery/containers/card-component.layexamples/gallery/containers/module-import.lay
复现
laymesh validate examples/gallery/containers/module-import.laylaymesh render examples/gallery/containers/module-import.lay -o figure.svglaymesh render examples/gallery/containers/module-import.lay -o figure.pdflaymesh render examples/gallery/containers/module-import.lay -o figure.png --dpi 300