增加classMap和styleMap2个函数

pull/1/head 1.7.0
yutent 2023-03-27 16:13:46 +08:00
parent 7568e701cf
commit 8770c32e5b
3 changed files with 28 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@bd/core", "name": "@bd/core",
"version": "1.6.0", "version": "1.7.0",
"type": "module", "type": "module",
"description": "百搭UI组件库的核心", "description": "百搭UI组件库的核心",
"main": "dist/index.js", "main": "dist/index.js",

View File

@ -16,10 +16,31 @@ import {
} from './constants.js' } from './constants.js'
import { css, adoptStyles } from './css.js' import { css, adoptStyles } from './css.js'
import { render, html, svg } from './html.js' import { render, html, svg } from './html.js'
import { nextTick, fire, bind, unbind } from './utils.js' import { nextTick, fire, bind, unbind, hyphen } from './utils.js'
export { $, $$, offset, outsideClick, clearOutsideClick } from './utils.js' export { $, $$, offset, outsideClick, clearOutsideClick } from './utils.js'
export { html, css, svg, bind, unbind, nextTick } export { html, css, svg, bind, unbind, nextTick }
// 简单的类名解析
export function classMap(data = {}) {
let output = ''
for (let k in data) {
if (data[k]) {
output += ' ' + k
}
}
return output.slice(1)
}
// 简单的样式解析
export function styleMap(data = {}) {
let output = ''
for (let k in data) {
if (data[k]) {
output += hyphen(k) + ':' + data[k] + ';'
}
}
return output
}
export class Component extends HTMLElement { export class Component extends HTMLElement {
/** /**
* 声明可监听变化的属性列表 * 声明可监听变化的属性列表

View File

@ -42,6 +42,11 @@ export const nextTick = (function () {
} }
})() })()
//驼峰转换为连字符线风格
export function hyphen(target) {
return target.replace(/([a-z\d])([A-Z]+)/g, '$1-$2').toLowerCase()
}
//取得距离页面左上角的坐标 //取得距离页面左上角的坐标
export function offset(node) { export function offset(node) {
try { try {