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/extensions/Rem.js CHANGED
@@ -1,24 +1,22 @@
1
- // /** 行内px转rem自定义指令 */
1
+ /**
2
+ * 行内 px 转 rem 自定义指令
3
+ * 用途:在 JS 对象中定义样式时自动完成单位转换
4
+ */
5
+ export const getRootValue = () => window.REM_BASE || 14
6
+
2
7
  const handler = (el, binding) => {
3
- /** 与postcss-pxtorem内rootValue配置一致 */
4
- const rootValue = 14
8
+ if (!binding.value) return
5
9
 
6
- const convert = (value) => {
7
- if (typeof value === 'string' && value.includes('px')) {
8
- return `${parseFloat(value) / rootValue}rem`
9
- }
10
- return value
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-component-gallery",
3
- "version": "2.3.16",
3
+ "version": "2.3.17",
4
4
  "description": "基础vue、antdvue、less实现的私有组件库",
5
5
  "main": "dist/index.umd.js",
6
6
  "files": [
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 - 第几次出现(从 1 开始)
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
- while (count < n) {
602
- index = str.indexOf(charToFind, index + 1)
603
- if (index === -1) return -1
604
- count++
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