From 3e9cc9466464e5446423031ebcc432e279d93492 Mon Sep 17 00:00:00 2001 From: 07akioni <07akioni2@gmail.com> Date: Wed, 4 Nov 2020 13:13:55 +0800 Subject: [PATCH] refactor(utils/css/format-length) --- src/_base/select-menu/src/SelectMenu.vue | 2 +- src/_base/selection/src/styles/themed-size.js | 6 ++-- src/_utils/composable/index.js | 10 ------- src/_utils/css/format-length.js | 30 +++++++++++++++++++ src/_utils/css/formatLength.js | 16 ---------- src/_utils/css/index.js | 2 +- src/_utils/vue/{src => }/call.js | 0 src/_utils/vue/{src => }/create-id.js | 0 src/_utils/vue/{src => }/flatten.js | 0 src/_utils/vue/{src => }/get-slot.js | 0 .../vue/{src => }/get-v-node-children.js | 0 src/_utils/vue/index.js | 16 +++++----- src/_utils/vue/{src => }/keep.js | 0 src/_utils/vue/{src => }/omit.js | 0 src/_utils/vue/{src => }/render.js | 0 src/anchor/src/BaseAnchor.vue | 7 +++-- src/avatar/src/styles/themed-size.cssr.js | 2 +- src/back-top/src/BackTop.vue | 3 +- src/button/src/styles/themed-size.cssr.js | 10 +++---- src/data-table/src/BaseTable.vue | 2 +- src/data-table/src/TableParts/Body.vue | 2 +- src/data-table/src/utils.js | 2 +- src/drawer/src/Drawer.vue | 3 +- src/form/src/styles/themed-size.cssr.js | 2 +- src/gradient-text/src/GradientText.vue | 12 ++++---- src/grid/src/Col.vue | 6 ++-- src/grid/src/Row.vue | 6 ++-- src/icon/src/Icon.js | 2 +- src/popover/src/PopoverBody.js | 2 +- src/popover/src/styles/themed-base.cssr.js | 2 +- src/progress/src/Progress.vue | 13 ++++---- src/steps/styles/light.js | 2 +- src/tabs/src/Tabs.vue | 10 +++---- 33 files changed, 88 insertions(+), 82 deletions(-) create mode 100644 src/_utils/css/format-length.js delete mode 100644 src/_utils/css/formatLength.js rename src/_utils/vue/{src => }/call.js (100%) rename src/_utils/vue/{src => }/create-id.js (100%) rename src/_utils/vue/{src => }/flatten.js (100%) rename src/_utils/vue/{src => }/get-slot.js (100%) rename src/_utils/vue/{src => }/get-v-node-children.js (100%) rename src/_utils/vue/{src => }/keep.js (100%) rename src/_utils/vue/{src => }/omit.js (100%) rename src/_utils/vue/{src => }/render.js (100%) diff --git a/src/_base/select-menu/src/SelectMenu.vue b/src/_base/select-menu/src/SelectMenu.vue index 594cdbe62..383991731 100644 --- a/src/_base/select-menu/src/SelectMenu.vue +++ b/src/_base/select-menu/src/SelectMenu.vue @@ -82,7 +82,7 @@ import NScrollbar from '../../../scrollbar' import NSelectOption from './SelectOption.js' import NSelectGroupHeader from './SelectGroupHeader.js' import NEmpty from '../../../empty' -import { depx, formatLength } from '../../../_utils/css' +import { depx, formatLength } from '../../../_utils' import { createKey } from '../../../_utils/cssr' import { usecssr } from '../../../_mixins' import styles from './styles' diff --git a/src/_base/selection/src/styles/themed-size.js b/src/_base/selection/src/styles/themed-size.js index 7fddfd817..996616912 100644 --- a/src/_base/selection/src/styles/themed-size.js +++ b/src/_base/selection/src/styles/themed-size.js @@ -1,5 +1,5 @@ import { cTB, c, cB, cE, cM } from '../../../../_utils/cssr' -import formatLength from '../../../../_utils/css/formatLength' +import { formatLength } from '../../../../_utils' export default c([ ({ props }) => { @@ -24,8 +24,8 @@ export default c([ minHeight: height }, [ cB('base-selection-input-tag', { - height: formatLength(height, 1, -6), - lineHeight: formatLength(height, 1, -6) + height: formatLength(height, { c: 1, offset: -6 }), + lineHeight: formatLength(height, { c: 1, offset: -6 }) }) ]) ]) diff --git a/src/_utils/composable/index.js b/src/_utils/composable/index.js index 8e76d1c16..0bfc22c96 100644 --- a/src/_utils/composable/index.js +++ b/src/_utils/composable/index.js @@ -14,16 +14,6 @@ export function useInjectionRef (injectionName, key, fallback) { return toRef(injection, key) } -export function onFontReady (callback) { - onMounted(() => { - const fontsReady = document.fonts.ready - const currentInstance = getCurrentInstance().proxy - fontsReady.then(() => { - callback(currentInstance) - }) - }) -} - export function useInjectionCollection (injectionName, collectionKey, valueRef) { const injection = inject(injectionName, null) if (injection === null) return diff --git a/src/_utils/css/format-length.js b/src/_utils/css/format-length.js new file mode 100644 index 000000000..ec590acf4 --- /dev/null +++ b/src/_utils/css/format-length.js @@ -0,0 +1,30 @@ +const pureNumberRegex = /^(\d|\.)+$/ +const numberRegex = /(\d|\.)+/ + +export default function formatLength (length, options = {}) { + const { + c = 1, + offset = 0, + attachPx = true + } = options + const type = typeof length + if (type === 'number') { + const result = (length + offset) * c + if (result === 0) return '0' + return `${result}px` + } else if (type === 'string') { + if (pureNumberRegex.test(length)) { + const result = (Number(length) + offset) * c + if (attachPx) { + if (result === 0) return '0' + return `${result}px` + } else { + return result + } + } else { + const result = numberRegex.exec(length) + if (!result) return length + return length.replace(numberRegex, '' + (Number(result[0]) + offset) * c) + } + } +} diff --git a/src/_utils/css/formatLength.js b/src/_utils/css/formatLength.js deleted file mode 100644 index 557ee6990..000000000 --- a/src/_utils/css/formatLength.js +++ /dev/null @@ -1,16 +0,0 @@ -const pureNumberRegex = /^(\d|\.)+$/ -const numberRegex = /(\d|\.)+/ - -export default function formatLength (length, weight = 1, offset = 0) { - if (typeof length === 'number') return '' + ((length + offset) && ((length + offset) * weight) + 'px') - if (typeof length === 'string') { - if (pureNumberRegex.test(length)) { - return ((Number(length) + offset) * weight) + 'px' - } else { - const result = numberRegex.exec(length) - if (!result) return length - return length.replace(numberRegex, '' + (Number(result[0]) + offset) * weight) - } - } - return length -} diff --git a/src/_utils/css/index.js b/src/_utils/css/index.js index ed4235b9a..2c79b0877 100644 --- a/src/_utils/css/index.js +++ b/src/_utils/css/index.js @@ -1,3 +1,3 @@ export { default as depx } from './depx' export { default as pxfy } from './pxfy' -export { default as formatLength } from './formatLength' +export { default as formatLength } from './format-length' diff --git a/src/_utils/vue/src/call.js b/src/_utils/vue/call.js similarity index 100% rename from src/_utils/vue/src/call.js rename to src/_utils/vue/call.js diff --git a/src/_utils/vue/src/create-id.js b/src/_utils/vue/create-id.js similarity index 100% rename from src/_utils/vue/src/create-id.js rename to src/_utils/vue/create-id.js diff --git a/src/_utils/vue/src/flatten.js b/src/_utils/vue/flatten.js similarity index 100% rename from src/_utils/vue/src/flatten.js rename to src/_utils/vue/flatten.js diff --git a/src/_utils/vue/src/get-slot.js b/src/_utils/vue/get-slot.js similarity index 100% rename from src/_utils/vue/src/get-slot.js rename to src/_utils/vue/get-slot.js diff --git a/src/_utils/vue/src/get-v-node-children.js b/src/_utils/vue/get-v-node-children.js similarity index 100% rename from src/_utils/vue/src/get-v-node-children.js rename to src/_utils/vue/get-v-node-children.js diff --git a/src/_utils/vue/index.js b/src/_utils/vue/index.js index bbca071f9..73a5d1ec4 100644 --- a/src/_utils/vue/index.js +++ b/src/_utils/vue/index.js @@ -1,8 +1,8 @@ -export { getSlot } from './src/get-slot' -export { getVNodeChildren } from './src/get-v-node-children' -export { createId } from './src/create-id' -export { keep } from './src/keep' -export { omit } from './src/omit' -export { flatten } from './src/flatten' -export { call } from './src/call' -export { render } from './src/render' +export { getSlot } from './get-slot' +export { getVNodeChildren } from './get-v-node-children' +export { createId } from './create-id' +export { keep } from './keep' +export { omit } from './omit' +export { flatten } from './flatten' +export { call } from './call' +export { render } from './render' diff --git a/src/_utils/vue/src/keep.js b/src/_utils/vue/keep.js similarity index 100% rename from src/_utils/vue/src/keep.js rename to src/_utils/vue/keep.js diff --git a/src/_utils/vue/src/omit.js b/src/_utils/vue/omit.js similarity index 100% rename from src/_utils/vue/src/omit.js rename to src/_utils/vue/omit.js diff --git a/src/_utils/vue/src/render.js b/src/_utils/vue/render.js similarity index 100% rename from src/_utils/vue/src/render.js rename to src/_utils/vue/render.js diff --git a/src/anchor/src/BaseAnchor.vue b/src/anchor/src/BaseAnchor.vue index 106b58259..44c42d619 100644 --- a/src/anchor/src/BaseAnchor.vue +++ b/src/anchor/src/BaseAnchor.vue @@ -24,14 +24,14 @@