web-component-gallery 2.3.16 → 2.3.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.umd.js +1 -1
- package/dist/js.umd.js +1 -1
- package/extensions/Rem.js +15 -17
- package/package.json +1 -1
- package/utils/Filter.js +7 -10
package/extensions/Rem.js
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 行内 px 转 rem 自定义指令
|
|
3
|
+
* 用途:在 JS 对象中定义样式时自动完成单位转换
|
|
4
|
+
*/
|
|
5
|
+
export const getRootValue = () => window.REM_BASE || 14
|
|
6
|
+
|
|
2
7
|
const handler = (el, binding) => {
|
|
3
|
-
|
|
4
|
-
const rootValue = 14
|
|
8
|
+
if (!binding.value) return
|
|
5
9
|
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
if (binding.value) {
|
|
14
|
-
Object.entries(binding.value).forEach(([key, val]) => {
|
|
15
|
-
el.style[key] = convert(val)
|
|
16
|
-
})
|
|
17
|
-
}
|
|
10
|
+
const base = getRootValue()
|
|
11
|
+
Object.entries(binding.value).forEach(([key, val]) => {
|
|
12
|
+
el.style[key] = typeof val === 'string' && val.includes('px')
|
|
13
|
+
? `${parseFloat(val) / base}rem`
|
|
14
|
+
: val
|
|
15
|
+
})
|
|
18
16
|
}
|
|
19
17
|
|
|
20
|
-
export default {
|
|
18
|
+
export default {
|
|
21
19
|
inserted: handler,
|
|
22
20
|
update: handler,
|
|
23
21
|
componentUpdated: handler
|
|
24
|
-
}
|
|
22
|
+
}
|
package/package.json
CHANGED
package/utils/Filter.js
CHANGED
|
@@ -589,21 +589,18 @@ function transferDataByMap(data, formatMap, options) {
|
|
|
589
589
|
* 查找字符串中第 n 次出现的位置
|
|
590
590
|
* @param {string} str - 源字符串
|
|
591
591
|
* @param {string} charToFind - 查找字符
|
|
592
|
-
* @param {number} n -
|
|
592
|
+
* @param {number} n - 第几次出现
|
|
593
593
|
* @returns {number} 位置索引,未找到返回 -1
|
|
594
594
|
*/
|
|
595
595
|
export function findNthOccurrence(str, charToFind, n) {
|
|
596
|
-
if (n < 1) return -1
|
|
597
|
-
|
|
598
|
-
let index = -1
|
|
599
596
|
let count = 0
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
597
|
+
let index = str.indexOf(charToFind)
|
|
598
|
+
|
|
599
|
+
while (count < n && index !== -1) {
|
|
600
|
+
index = str.indexOf(charToFind, index + 1)
|
|
601
|
+
count++
|
|
605
602
|
}
|
|
606
|
-
|
|
603
|
+
|
|
607
604
|
return index
|
|
608
605
|
}
|
|
609
606
|
|