完全跑通1.0版本

This commit is contained in:
2026-05-26 12:56:03 +08:00
parent 2ece5174a7
commit 93c714a93b
11557 changed files with 1648225 additions and 36 deletions

View File

@@ -0,0 +1,8 @@
import { SFCWithInstall } from "../../utils/vue/typescript.js";
import { CountdownEmits, CountdownInstance, CountdownProps, CountdownPropsPublic, countdownEmits, countdownProps } from "./src/countdown.js";
import _default from "./src/countdown.vue.js";
//#region ../../packages/components/countdown/index.d.ts
declare const ElCountdown: SFCWithInstall<typeof _default>;
//#endregion
export { CountdownEmits, CountdownInstance, CountdownProps, CountdownPropsPublic, ElCountdown, ElCountdown as default, countdownEmits, countdownProps };

View File

@@ -0,0 +1,9 @@
import { withInstall } from "../../utils/vue/install.mjs";
import { countdownEmits, countdownProps } from "./src/countdown.mjs";
import countdown_default from "./src/countdown2.mjs";
//#region ../../packages/components/countdown/index.ts
const ElCountdown = withInstall(countdown_default);
//#endregion
export { ElCountdown, ElCountdown as default, countdownEmits, countdownProps };
//# sourceMappingURL=index.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.mjs","names":["Countdown"],"sources":["../../../../../packages/components/countdown/index.ts"],"sourcesContent":["import { withInstall } from '@element-plus/utils'\nimport Countdown from './src/countdown.vue'\n\nimport type { SFCWithInstall } from '@element-plus/utils'\n\nexport const ElCountdown: SFCWithInstall<typeof Countdown> =\n withInstall(Countdown)\nexport default ElCountdown\n\nexport * from './src/countdown'\n"],"mappings":";;;;AAKA,MAAa,cACX,YAAYA,kBAAU"}

View File

@@ -0,0 +1,56 @@
import { EpPropFinalized } from "../../../utils/vue/props/types.js";
import _default from "./countdown.vue.js";
import * as _$vue from "vue";
import { ExtractPublicPropTypes, StyleValue } from "vue";
import { Dayjs } from "dayjs";
//#region ../../packages/components/countdown/src/countdown.d.ts
interface CountdownProps {
/**
* @description Formatting the countdown display
*/
format?: string;
/**
* @description Sets the prefix of a countdown
*/
prefix?: string;
/**
* @description Sets the suffix of a countdown
*/
suffix?: string;
/**
* @description countdown titles
*/
title?: string;
/**
* @description target time
*/
value?: number | Dayjs;
/**
* @description Styles countdown values
*/
valueStyle?: StyleValue;
}
/**
* @deprecated Removed after 3.0.0, Use `CountdownProps` instead.
*/
declare const countdownProps: {
readonly format: EpPropFinalized<StringConstructor, unknown, unknown, "HH:mm:ss", boolean>;
readonly prefix: StringConstructor;
readonly suffix: StringConstructor;
readonly title: StringConstructor;
readonly value: EpPropFinalized<(new (...args: any[]) => number | Dayjs) | (() => number | Dayjs) | (((new (...args: any[]) => number | Dayjs) | (() => number | Dayjs)) | null)[], unknown, unknown, 0, boolean>;
readonly valueStyle: EpPropFinalized<(new (...args: any[]) => string | false | _$vue.CSSProperties | StyleValue[]) | (() => StyleValue) | (((new (...args: any[]) => string | false | _$vue.CSSProperties | StyleValue[]) | (() => StyleValue)) | null)[], unknown, unknown, undefined, boolean>;
};
/**
* @deprecated Removed after 3.0.0, Use `CountdownProps` instead.
*/
type CountdownPropsPublic = ExtractPublicPropTypes<typeof countdownProps>;
declare const countdownEmits: {
finish: () => boolean;
change: (value: number) => boolean;
};
type CountdownEmits = typeof countdownEmits;
type CountdownInstance = InstanceType<typeof _default> & unknown;
//#endregion
export { CountdownEmits, CountdownInstance, CountdownProps, CountdownPropsPublic, countdownEmits, countdownProps };

View File

@@ -0,0 +1,55 @@
import { CHANGE_EVENT } from "../../../constants/event.mjs";
import { isNumber } from "../../../utils/types.mjs";
import { buildProps, definePropType } from "../../../utils/vue/props/runtime.mjs";
//#region ../../packages/components/countdown/src/countdown.ts
/**
* @deprecated Removed after 3.0.0, Use `CountdownProps` instead.
*/
const countdownProps = buildProps({
/**
* @description Formatting the countdown display
*/
format: {
type: String,
default: "HH:mm:ss"
},
/**
* @description Sets the prefix of a countdown
*/
prefix: String,
/**
* @description Sets the suffix of a countdown
*/
suffix: String,
/**
* @description countdown titles
*/
title: String,
/**
* @description target time
*/
value: {
type: definePropType([Number, Object]),
default: 0
},
/**
* @description Styles countdown values
*/
valueStyle: {
type: definePropType([
String,
Object,
Array,
Boolean
]),
default: void 0
}
});
const countdownEmits = {
finish: () => true,
[CHANGE_EVENT]: (value) => isNumber(value)
};
//#endregion
export { countdownEmits, countdownProps };
//# sourceMappingURL=countdown.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"countdown.mjs","names":[],"sources":["../../../../../../packages/components/countdown/src/countdown.ts"],"sourcesContent":["import { buildProps, definePropType, isNumber } from '@element-plus/utils'\nimport { CHANGE_EVENT } from '@element-plus/constants'\n\nimport type { ExtractPublicPropTypes, StyleValue } from 'vue'\nimport type { Dayjs } from 'dayjs'\nimport type Countdown from './countdown.vue'\n\nexport interface CountdownProps {\n /**\n * @description Formatting the countdown display\n */\n format?: string\n /**\n * @description Sets the prefix of a countdown\n */\n prefix?: string\n /**\n * @description Sets the suffix of a countdown\n */\n suffix?: string\n /**\n * @description countdown titles\n */\n title?: string\n /**\n * @description target time\n */\n value?: number | Dayjs\n /**\n * @description Styles countdown values\n */\n valueStyle?: StyleValue\n}\n\n/**\n * @deprecated Removed after 3.0.0, Use `CountdownProps` instead.\n */\nexport const countdownProps = buildProps({\n /**\n * @description Formatting the countdown display\n */\n format: {\n type: String,\n default: 'HH:mm:ss',\n },\n /**\n * @description Sets the prefix of a countdown\n */\n prefix: String,\n /**\n * @description Sets the suffix of a countdown\n */\n suffix: String,\n /**\n * @description countdown titles\n */\n title: String,\n /**\n * @description target time\n */\n value: {\n type: definePropType<number | Dayjs>([Number, Object]),\n default: 0,\n },\n /**\n * @description Styles countdown values\n */\n valueStyle: {\n type: definePropType<StyleValue>([String, Object, Array, Boolean]),\n default: undefined,\n },\n} as const)\n\n/**\n * @deprecated Removed after 3.0.0, Use `CountdownProps` instead.\n */\nexport type CountdownPropsPublic = ExtractPublicPropTypes<typeof countdownProps>\n\nexport const countdownEmits = {\n finish: () => true,\n [CHANGE_EVENT]: (value: number) => isNumber(value),\n}\nexport type CountdownEmits = typeof countdownEmits\n\nexport type CountdownInstance = InstanceType<typeof Countdown> & unknown\n"],"mappings":";;;;;;;AAqCA,MAAa,iBAAiB,WAAW;;;;CAIvC,QAAQ;EACN,MAAM;EACN,SAAS;EACV;;;;CAID,QAAQ;;;;CAIR,QAAQ;;;;CAIR,OAAO;;;;CAIP,OAAO;EACL,MAAM,eAA+B,CAAC,QAAQ,OAAO,CAAC;EACtD,SAAS;EACV;;;;CAID,YAAY;EACV,MAAM,eAA2B;GAAC;GAAQ;GAAQ;GAAO;GAAQ,CAAC;EAClE,SAAS,KAAA;EACV;CACF,CAAU;AAOX,MAAa,iBAAiB;CAC5B,cAAc;EACb,gBAAgB,UAAkB,SAAS,MAAM;CACnD"}

View File

@@ -0,0 +1,32 @@
import { CountdownProps } from "./countdown.js";
import * as _$vue from "vue";
import * as _$dayjs from "dayjs";
//#region ../../packages/components/countdown/src/countdown.vue.d.ts
declare var __VLS_10: string, __VLS_11: {};
type __VLS_Slots = {} & { [K in NonNullable<typeof __VLS_10>]?: (props: typeof __VLS_11) => any };
declare const __VLS_base: _$vue.DefineComponent<CountdownProps, {
/**
* @description current display value
*/
displayValue: _$vue.ComputedRef<string>;
}, {}, {}, {}, _$vue.ComponentOptionsMixin, _$vue.ComponentOptionsMixin, {
finish: () => void;
change: (value: number) => void;
}, string, _$vue.PublicProps, Readonly<CountdownProps> & Readonly<{
onFinish?: (() => any) | undefined;
onChange?: ((value: number) => any) | undefined;
}>, {
value: number | _$dayjs.Dayjs;
format: string;
valueStyle: string | false | _$vue.CSSProperties | _$vue.StyleValue[] | null;
}, {}, {}, {}, string, _$vue.ComponentProvideOptions, false, {}, any>;
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
declare const _default: typeof __VLS_export;
type __VLS_WithSlots<T, S> = T & {
new (): {
$slots: S;
};
};
//#endregion
export { _default as default };

View File

@@ -0,0 +1,81 @@
import { CHANGE_EVENT } from "../../../constants/event.mjs";
import { cAF, rAF } from "../../../utils/raf.mjs";
import { countdownEmits, countdownProps } from "./countdown.mjs";
import { ElStatistic } from "../../statistic/index.mjs";
import { formatTime, getTime } from "./utils.mjs";
import { computed, createBlock, createSlots, defineComponent, onBeforeUnmount, onMounted, openBlock, ref, renderList, renderSlot, unref, watch, withCtx } from "vue";
//#region ../../packages/components/countdown/src/countdown.vue?vue&type=script&setup=true&lang.ts
var countdown_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
name: "ElCountdown",
__name: "countdown",
props: countdownProps,
emits: countdownEmits,
setup(__props, { expose: __expose, emit: __emit }) {
const props = __props;
const emit = __emit;
let timer;
const rawValue = ref(0);
const displayValue = computed(() => formatTime(rawValue.value, props.format));
const formatter = (val) => formatTime(val, props.format);
const stopTimer = () => {
if (timer) {
cAF(timer);
timer = void 0;
}
};
const startTimer = () => {
const timestamp = getTime(props.value);
const frameFunc = () => {
let diff = timestamp - Date.now();
emit(CHANGE_EVENT, diff);
if (diff <= 0) {
diff = 0;
stopTimer();
emit("finish");
} else timer = rAF(frameFunc);
rawValue.value = diff;
};
timer = rAF(frameFunc);
};
onMounted(() => {
rawValue.value = getTime(props.value) - Date.now();
watch(() => [props.value, props.format], () => {
stopTimer();
startTimer();
}, { immediate: true });
});
onBeforeUnmount(() => {
stopTimer();
});
__expose({
/**
* @description current display value
*/
displayValue });
return (_ctx, _cache) => {
return openBlock(), createBlock(unref(ElStatistic), {
value: rawValue.value,
title: __props.title,
prefix: __props.prefix,
suffix: __props.suffix,
"value-style": __props.valueStyle,
formatter
}, createSlots({ _: 2 }, [renderList(_ctx.$slots, (_, name) => {
return {
name,
fn: withCtx(() => [renderSlot(_ctx.$slots, name)])
};
})]), 1032, [
"value",
"title",
"prefix",
"suffix",
"value-style"
]);
};
}
});
//#endregion
export { countdown_vue_vue_type_script_setup_true_lang_default as default };
//# sourceMappingURL=countdown.vue_vue_type_script_setup_true_lang.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"countdown.vue_vue_type_script_setup_true_lang.mjs","names":["$slots"],"sources":["../../../../../../packages/components/countdown/src/countdown.vue"],"sourcesContent":["<template>\n <el-statistic\n :value=\"rawValue\"\n :title=\"title\"\n :prefix=\"prefix\"\n :suffix=\"suffix\"\n :value-style=\"valueStyle\"\n :formatter=\"formatter\"\n >\n <template v-for=\"(_, name) in $slots\" #[name]>\n <slot :name=\"name\" />\n </template>\n </el-statistic>\n</template>\n\n<script lang=\"ts\" setup>\nimport { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'\nimport { ElStatistic } from '@element-plus/components/statistic'\nimport { cAF, rAF } from '@element-plus/utils'\nimport { CHANGE_EVENT } from '@element-plus/constants'\nimport { countdownEmits } from './countdown'\nimport { formatTime, getTime } from './utils'\n\nimport type { CountdownProps } from './countdown'\n\ndefineOptions({\n name: 'ElCountdown',\n})\nconst props = withDefaults(defineProps<CountdownProps>(), {\n format: 'HH:mm:ss',\n value: 0,\n valueStyle: undefined,\n})\nconst emit = defineEmits(countdownEmits)\n\nlet timer: ReturnType<typeof rAF> | undefined\nconst rawValue = ref<number>(0)\nconst displayValue = computed(() => formatTime(rawValue.value, props.format))\n\nconst formatter = (val: number) => formatTime(val, props.format)\n\nconst stopTimer = () => {\n if (timer) {\n cAF(timer)\n timer = undefined\n }\n}\n\nconst startTimer = () => {\n const timestamp = getTime(props.value)\n const frameFunc = () => {\n let diff = timestamp - Date.now()\n emit(CHANGE_EVENT, diff)\n if (diff <= 0) {\n diff = 0\n stopTimer()\n emit('finish')\n } else {\n timer = rAF(frameFunc)\n }\n rawValue.value = diff\n }\n timer = rAF(frameFunc)\n}\n\nonMounted(() => {\n rawValue.value = getTime(props.value) - Date.now()\n\n watch(\n () => [props.value, props.format],\n () => {\n stopTimer()\n startTimer()\n },\n {\n immediate: true,\n }\n )\n})\n\nonBeforeUnmount(() => {\n stopTimer()\n})\n\ndefineExpose({\n /**\n * @description current display value\n */\n displayValue,\n})\n</script>\n"],"mappings":";;;;;;;;;;;;;EA4BA,MAAM,QAAQ;EAKd,MAAM,OAAO;EAEb,IAAI;EACJ,MAAM,WAAW,IAAY,EAAC;EAC9B,MAAM,eAAe,eAAe,WAAW,SAAS,OAAO,MAAM,OAAO,CAAA;EAE5E,MAAM,aAAa,QAAgB,WAAW,KAAK,MAAM,OAAM;EAE/D,MAAM,kBAAkB;GACtB,IAAI,OAAO;IACT,IAAI,MAAK;IACT,QAAQ,KAAA;;;EAIZ,MAAM,mBAAmB;GACvB,MAAM,YAAY,QAAQ,MAAM,MAAK;GACrC,MAAM,kBAAkB;IACtB,IAAI,OAAO,YAAY,KAAK,KAAI;IAChC,KAAK,cAAc,KAAI;IACvB,IAAI,QAAQ,GAAG;KACb,OAAO;KACP,WAAU;KACV,KAAK,SAAQ;WAEb,QAAQ,IAAI,UAAS;IAEvB,SAAS,QAAQ;;GAEnB,QAAQ,IAAI,UAAS;;EAGvB,gBAAgB;GACd,SAAS,QAAQ,QAAQ,MAAM,MAAM,GAAG,KAAK,KAAI;GAEjD,YACQ,CAAC,MAAM,OAAO,MAAM,OAAO,QAC3B;IACJ,WAAU;IACV,YAAW;MAEb,EACE,WAAW,MACb,CACF;IACD;EAED,sBAAsB;GACpB,WAAU;IACX;EAED,SAAa;;;;AAIX,cACD,CAAA;;uBAxFC,YAWe,MAAA,YAAA,EAAA;IAVZ,OAAO,SAAA;IACP,OAAO,QAAA;IACP,QAAQ,QAAA;IACR,QAAQ,QAAA;IACR,eAAa,QAAA;IACF;wCAEkBA,KAAAA,SAAZ,GAAG,SAAI;;KAAc;uBAChB,CAArB,WAAqB,KAAA,QAAR,KAAI,CAAA,CAAA"}

View File

@@ -0,0 +1,7 @@
import countdown_vue_vue_type_script_setup_true_lang_default from "./countdown.vue_vue_type_script_setup_true_lang.mjs";
//#region ../../packages/components/countdown/src/countdown.vue
var countdown_default = countdown_vue_vue_type_script_setup_true_lang_default;
//#endregion
export { countdown_default as default };
//# sourceMappingURL=countdown2.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"countdown2.mjs","names":[],"sources":["../../../../../../packages/components/countdown/src/countdown.vue"],"sourcesContent":["<template>\n <el-statistic\n :value=\"rawValue\"\n :title=\"title\"\n :prefix=\"prefix\"\n :suffix=\"suffix\"\n :value-style=\"valueStyle\"\n :formatter=\"formatter\"\n >\n <template v-for=\"(_, name) in $slots\" #[name]>\n <slot :name=\"name\" />\n </template>\n </el-statistic>\n</template>\n\n<script lang=\"ts\" setup>\nimport { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'\nimport { ElStatistic } from '@element-plus/components/statistic'\nimport { cAF, rAF } from '@element-plus/utils'\nimport { CHANGE_EVENT } from '@element-plus/constants'\nimport { countdownEmits } from './countdown'\nimport { formatTime, getTime } from './utils'\n\nimport type { CountdownProps } from './countdown'\n\ndefineOptions({\n name: 'ElCountdown',\n})\nconst props = withDefaults(defineProps<CountdownProps>(), {\n format: 'HH:mm:ss',\n value: 0,\n valueStyle: undefined,\n})\nconst emit = defineEmits(countdownEmits)\n\nlet timer: ReturnType<typeof rAF> | undefined\nconst rawValue = ref<number>(0)\nconst displayValue = computed(() => formatTime(rawValue.value, props.format))\n\nconst formatter = (val: number) => formatTime(val, props.format)\n\nconst stopTimer = () => {\n if (timer) {\n cAF(timer)\n timer = undefined\n }\n}\n\nconst startTimer = () => {\n const timestamp = getTime(props.value)\n const frameFunc = () => {\n let diff = timestamp - Date.now()\n emit(CHANGE_EVENT, diff)\n if (diff <= 0) {\n diff = 0\n stopTimer()\n emit('finish')\n } else {\n timer = rAF(frameFunc)\n }\n rawValue.value = diff\n }\n timer = rAF(frameFunc)\n}\n\nonMounted(() => {\n rawValue.value = getTime(props.value) - Date.now()\n\n watch(\n () => [props.value, props.format],\n () => {\n stopTimer()\n startTimer()\n },\n {\n immediate: true,\n }\n )\n})\n\nonBeforeUnmount(() => {\n stopTimer()\n})\n\ndefineExpose({\n /**\n * @description current display value\n */\n displayValue,\n})\n</script>\n"],"mappings":""}

View File

@@ -0,0 +1,7 @@
import { Dayjs } from "dayjs";
//#region ../../packages/components/countdown/src/utils.d.ts
declare const getTime: (value: number | Dayjs) => number;
declare const formatTime: (timestamp: number, format: string) => string;
//#endregion
export { formatTime, getTime };

View File

@@ -0,0 +1,30 @@
import { isNumber } from "../../../utils/types.mjs";
//#region ../../packages/components/countdown/src/utils.ts
const timeUnits = [
["Y", 1e3 * 60 * 60 * 24 * 365],
["M", 1e3 * 60 * 60 * 24 * 30],
["D", 1e3 * 60 * 60 * 24],
["H", 1e3 * 60 * 60],
["m", 1e3 * 60],
["s", 1e3],
["S", 1]
];
const getTime = (value) => {
return isNumber(value) ? new Date(value).getTime() : value.valueOf();
};
const formatTime = (timestamp, format) => {
let timeLeft = timestamp;
return timeUnits.reduce((current, [name, unit]) => {
const replaceRegex = new RegExp(`${name}+(?![^\\[\\]]*\\])`, "g");
if (replaceRegex.test(current)) {
const value = Math.floor(timeLeft / unit);
timeLeft -= value * unit;
return current.replace(replaceRegex, (match) => String(value).padStart(match.length, "0"));
}
return current;
}, format).replace(/\[([^\]]*)]/g, "$1");
};
//#endregion
export { formatTime, getTime };
//# sourceMappingURL=utils.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"utils.mjs","names":[],"sources":["../../../../../../packages/components/countdown/src/utils.ts"],"sourcesContent":["import { isNumber } from '@element-plus/utils'\n\nimport type { Dayjs } from 'dayjs'\n\nconst timeUnits = [\n ['Y', 1000 * 60 * 60 * 24 * 365], // years\n ['M', 1000 * 60 * 60 * 24 * 30], // months\n ['D', 1000 * 60 * 60 * 24], // days\n ['H', 1000 * 60 * 60], // hours\n ['m', 1000 * 60], // minutes\n ['s', 1000], // seconds\n ['S', 1], // million seconds\n] as const\n\nexport const getTime = (value: number | Dayjs) => {\n return isNumber(value) ? new Date(value).getTime() : value.valueOf()\n}\n\nexport const formatTime = (timestamp: number, format: string) => {\n let timeLeft = timestamp\n const escapeRegex = /\\[([^\\]]*)]/g\n\n const replacedText = timeUnits.reduce((current, [name, unit]) => {\n const replaceRegex = new RegExp(`${name}+(?![^\\\\[\\\\]]*\\\\])`, 'g')\n if (replaceRegex.test(current)) {\n const value = Math.floor(timeLeft / unit)\n timeLeft -= value * unit\n return current.replace(replaceRegex, (match) =>\n String(value).padStart(match.length, '0')\n )\n }\n return current\n }, format)\n\n return replacedText.replace(escapeRegex, '$1')\n}\n"],"mappings":";;AAIA,MAAM,YAAY;CAChB,CAAC,KAAK,MAAO,KAAK,KAAK,KAAK,IAAI;CAChC,CAAC,KAAK,MAAO,KAAK,KAAK,KAAK,GAAG;CAC/B,CAAC,KAAK,MAAO,KAAK,KAAK,GAAG;CAC1B,CAAC,KAAK,MAAO,KAAK,GAAG;CACrB,CAAC,KAAK,MAAO,GAAG;CAChB,CAAC,KAAK,IAAK;CACX,CAAC,KAAK,EAAE;CACT;AAED,MAAa,WAAW,UAA0B;CAChD,OAAO,SAAS,MAAM,GAAG,IAAI,KAAK,MAAM,CAAC,SAAS,GAAG,MAAM,SAAS;;AAGtE,MAAa,cAAc,WAAmB,WAAmB;CAC/D,IAAI,WAAW;CAef,OAZqB,UAAU,QAAQ,SAAS,CAAC,MAAM,UAAU;EAC/D,MAAM,eAAe,IAAI,OAAO,GAAG,KAAK,qBAAqB,IAAI;EACjE,IAAI,aAAa,KAAK,QAAQ,EAAE;GAC9B,MAAM,QAAQ,KAAK,MAAM,WAAW,KAAK;GACzC,YAAY,QAAQ;GACpB,OAAO,QAAQ,QAAQ,eAAe,UACpC,OAAO,MAAM,CAAC,SAAS,MAAM,QAAQ,IAAI,CAC1C;;EAEH,OAAO;IACN,OAEgB,CAAC,QAAQ,gBAAa,KAAK"}

View File

@@ -0,0 +1,2 @@
import "../../base/style/css.mjs";
import "element-plus/theme-chalk/el-statistic.css";

View File

@@ -0,0 +1,2 @@
import "../../base/style/index.mjs";
import "element-plus/theme-chalk/src/statistic.scss";