You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
3.9 KiB

{"ast":null,"code":"import { ref, onMounted, nextTick } from 'vue';\nimport { useEventListener } from '@vueuse/core';\nconst useLifecycle = (props, initData, resetSize) => {\n const sliderWrapper = ref();\n onMounted(async () => {\n if (props.range) {\n if (Array.isArray(props.modelValue)) {\n initData.firstValue = Math.max(props.min, props.modelValue[0]);\n initData.secondValue = Math.min(props.max, props.modelValue[1]);\n } else {\n initData.firstValue = props.min;\n initData.secondValue = props.max;\n }\n initData.oldValue = [initData.firstValue, initData.secondValue];\n } else {\n if (typeof props.modelValue !== \"number\" || Number.isNaN(props.modelValue)) {\n initData.firstValue = props.min;\n } else {\n initData.firstValue = Math.min(props.max, Math.max(props.min, props.modelValue));\n }\n initData.oldValue = initData.firstValue;\n }\n useEventListener(window, \"resize\", resetSize);\n await nextTick();\n resetSize();\n });\n return {\n sliderWrapper\n };\n};\nexport { useLifecycle };","map":{"version":3,"names":["useLifecycle","props","initData","resetSize","sliderWrapper","ref","onMounted","range","Array","isArray","modelValue","firstValue","Math","max","min","secondValue","oldValue","Number","isNaN","useEventListener","window","nextTick"],"sources":["../../../../../../../packages/components/slider/src/composables/use-lifecycle.ts"],"sourcesContent":["import { nextTick, onMounted, ref } from 'vue'\nimport { useEventListener } from '@vueuse/core'\nimport type { SliderInitData, SliderProps } from '../slider'\n\nexport const useLifecycle = (\n props: SliderProps,\n initData: SliderInitData,\n resetSize: () => void\n) => {\n const sliderWrapper = ref<HTMLElement>()\n\n onMounted(async () => {\n if (props.range) {\n if (Array.isArray(props.modelValue)) {\n initData.firstValue = Math.max(props.min, props.modelValue[0])\n initData.secondValue = Math.min(props.max, props.modelValue[1])\n } else {\n initData.firstValue = props.min\n initData.secondValue = props.max\n }\n initData.oldValue = [initData.firstValue, initData.secondValue]\n } else {\n if (\n typeof props.modelValue !== 'number' ||\n Number.isNaN(props.modelValue)\n ) {\n initData.firstValue = props.min\n } else {\n initData.firstValue = Math.min(\n props.max,\n Math.max(props.min, props.modelValue)\n )\n }\n initData.oldValue = initData.firstValue\n }\n\n useEventListener(window, 'resize', resetSize)\n\n await nextTick()\n resetSize()\n })\n\n return {\n sliderWrapper,\n }\n}\n"],"mappings":";;AAEY,MAACA,YAAY,GAAGA,CAACC,KAAK,EAAEC,QAAQ,EAAEC,SAAS,KAAK;EAC1D,MAAMC,aAAa,GAAGC,GAAG,EAAE;EAC3BC,SAAS,CAAC,YAAY;IACpB,IAAIL,KAAK,CAACM,KAAK,EAAE;MACf,IAAIC,KAAK,CAACC,OAAO,CAACR,KAAK,CAACS,UAAU,CAAC,EAAE;QACnCR,QAAQ,CAACS,UAAU,GAAGC,IAAI,CAACC,GAAG,CAACZ,KAAK,CAACa,GAAG,EAAEb,KAAK,CAACS,UAAU,CAAC,CAAC,CAAC,CAAC;QAC9DR,QAAQ,CAACa,WAAW,GAAGH,IAAI,CAACE,GAAG,CAACb,KAAK,CAACY,GAAG,EAAEZ,KAAK,CAACS,UAAU,CAAC,CAAC,CAAC,CAAC;MACvE,CAAO,MAAM;QACLR,QAAQ,CAACS,UAAU,GAAGV,KAAK,CAACa,GAAG;QAC/BZ,QAAQ,CAACa,WAAW,GAAGd,KAAK,CAACY,GAAG;MACxC;MACMX,QAAQ,CAACc,QAAQ,GAAG,CAACd,QAAQ,CAACS,UAAU,EAAET,QAAQ,CAACa,WAAW,CAAC;IACrE,CAAK,MAAM;MACL,IAAI,OAAOd,KAAK,CAACS,UAAU,KAAK,QAAQ,IAAIO,MAAM,CAACC,KAAK,CAACjB,KAAK,CAACS,UAAU,CAAC,EAAE;QAC1ER,QAAQ,CAACS,UAAU,GAAGV,KAAK,CAACa,GAAG;MACvC,CAAO,MAAM;QACLZ,QAAQ,CAACS,UAAU,GAAGC,IAAI,CAACE,GAAG,CAACb,KAAK,CAACY,GAAG,EAAED,IAAI,CAACC,GAAG,CAACZ,KAAK,CAACa,GAAG,EAAEb,KAAK,CAACS,UAAU,CAAC,C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