wkit/src/constants.js

98 lines
2.1 KiB
JavaScript
Raw Normal View History

2023-03-06 12:25:54 +08:00
/**
* {}
* @author yutent<yutent.io@gmail.com>
* @date 2023/03/06 12:08:35
*/
2023-03-12 23:04:50 +08:00
const boolMap = Object.create(null)
;[
'autofocus',
'autoplay',
'async',
'allowTransparency',
'checked',
'controls',
'declare',
'disabled',
'defer',
'defaultChecked',
'defaultSelected',
'contentEditable',
'isMap',
'loop',
'multiple',
'noHref',
'noResize',
'noShade',
'open',
'readOnly',
'selected'
].forEach(function (name) {
boolMap[name.toLowerCase()] = name
})
export { boolMap }
2023-03-08 11:50:38 +08:00
export const WC_PART = Symbol('wc_path')
2023-03-08 15:14:02 +08:00
export const NO_CHANGE = Symbol('wc-noChange')
export const NOTHING = Symbol('wc-nothing')
export const __finalized__ = Symbol('finalized')
export const __update__ = Symbol('update')
export const __init__ = Symbol('init')
export const __props__ = Symbol('props')
export const __changed_props__ = Symbol('changed_props')
export const __mounted__ = Symbol('mounted')
2023-03-07 19:15:23 +08:00
2023-03-12 23:04:50 +08:00
export const RESET_CSS_STYLE = `* {box-sizing: border-box;margin: 0;padding: 0;}::before,::after {box-sizing: border-box;}`
2023-03-08 11:11:05 +08:00
export const DEFAULT_CONVERTER = {
toAttribute(value, type) {
switch (type) {
case Boolean:
// console.log(this, '>>>', value)
2023-03-08 11:11:05 +08:00
value = value ? '' : null
break
case Object:
case Array:
value = value == null ? value : JSON.stringify(value)
break
}
return value
},
fromAttribute(value, type) {
let fromValue = value
switch (type) {
case Boolean:
fromValue = value !== null
break
case Number:
fromValue = value === null ? null : Number(value)
break
case Object:
case Array:
try {
fromValue = JSON.parse(value)
} catch (e) {
fromValue = null
}
break
}
return fromValue
}
}
export function notEqual(value, old) {
return old !== value && (old === old || value === value)
}
export const DEFAULT_PROPERTY_DECLARATION = {
attribute: true,
type: String,
formater: DEFAULT_CONVERTER,
// converter: DEFAULT_CONVERTER,
2023-03-08 11:11:05 +08:00
reflect: false,
hasChanged: notEqual,
default: ''
2023-03-08 11:11:05 +08:00
}