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)
|
2023-03-10 18:38:52 +08:00
|
|
|
|
|
|
|
;[
|
|
|
|
'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')
|
2023-03-10 18:38:52 +08:00
|
|
|
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:
|
2023-03-10 18:38:52 +08:00
|
|
|
// 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,
|
2023-03-10 18:38:52 +08:00
|
|
|
formater: DEFAULT_CONVERTER,
|
|
|
|
// converter: DEFAULT_CONVERTER,
|
2023-03-08 11:11:05 +08:00
|
|
|
reflect: false,
|
2023-03-10 18:38:52 +08:00
|
|
|
hasChanged: notEqual,
|
|
|
|
default: ''
|
2023-03-08 11:11:05 +08:00
|
|
|
}
|