import{ax as i,z as a,A as l,b5 as t}from"./chunks/framework.V2ssSR2R.js";const d=JSON.parse('{"title":"工具函数","description":"","frontmatter":{},"headers":[],"relativePath":"runtime-api/core/utils.md","filePath":"runtime-api/core/utils.md"}'),n={name:"runtime-api/core/utils.md"};function e(h,s,p,r,k,o){return l(),a("div",null,[...s[0]||(s[0]=[t(`
@tmagic/core 导出的工具函数。
参数:
{string} style CSS 样式字符串返回:
{object} 样式对象详情:
将 CSS 样式字符串转换为对象格式。若入参不是字符串,则原样返回。
示例:
import { style2Obj } from '@tmagic/core';
const styleObj = style2Obj('width: 100px; height: 200px;');
console.log(styleObj); // { width: '100px', height: '200px' }参数:
{string} value 背景图片 URL返回:
{string} 完整的 CSS 背景图片值详情:
填充背景图片 URL 为完整的 CSS 格式。
示例:
import { fillBackgroundImage } from '@tmagic/core';
const bg = fillBackgroundImage('https://example.com/image.png');
console.log(bg); // 'url(https://example.com/image.png)'参数:
{Record<string, string> | string} value transform 配置(对象或 CSS 字符串){JsEngine} jsEngine JS 引擎类型返回:
{string | Record<string, string>[]} CSS transform 字符串;当 jsEngine === 'hippy' 时返回数组格式详情:
根据配置生成 CSS transform。当 jsEngine === 'hippy' 时,会将 "rotate(90deg) scale(1.5)" 这样的字符串解析成 [{ rotate: '90deg' }, { scale: '1.5' }] 形式以适配 Hippy;其它情况下返回标准 CSS transform 字符串。
参数:
{Record<string, any> | string} style 样式对象或 CSS 字符串{JsEngine} jsEngine JS 引擎类型返回:
{object} 转换后的样式对象详情:
转换样式对象,将数值转换为 rem 单位(移动端适配)。当 style 为字符串时,会先用 style2Obj 解析为对象再处理。
示例:
import { transformStyle } from '@tmagic/core';
const style = transformStyle({ width: 100, height: 200 }, 'browser');
console.log(style); // { width: '1rem', height: '2rem' }值: 'magic:common:events:'
详情:
通用事件前缀。
值: 'magic:common:actions:'
详情:
通用方法前缀。
示例:
import { COMMON_EVENT_PREFIX, COMMON_METHOD_PREFIX } from '@tmagic/core';
const eventKey = \`\${COMMON_EVENT_PREFIX}click\`;
const methodKey = \`\${COMMON_METHOD_PREFIX}show\`;