@fast-china/utils 2.1.9 → 2.1.10
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/CHANGELOG.md +7 -0
- package/dist/index.d.mts +22 -0
- package/dist/index.global.min.js +1 -1
- package/dist/index.global.min.js.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/vue/index.mjs +2 -1
- package/dist/vue/transition.mjs +60 -0
- package/dist/vue/transition.mjs.map +1 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -26,7 +26,8 @@ import { useNow } from "./vue/now.mjs";
|
|
|
26
26
|
import { definePropType, useProps } from "./vue/props.mjs";
|
|
27
27
|
import { useRender } from "./vue/render.mjs";
|
|
28
28
|
import { makeSlots } from "./vue/slots.mjs";
|
|
29
|
+
import { useTransition } from "./vue/transition.mjs";
|
|
29
30
|
import { useWindowSize } from "./vue/window-size.mjs";
|
|
30
31
|
import { withDefineType } from "./vue/with.mjs";
|
|
31
32
|
import "./vue/index.mjs";
|
|
32
|
-
export { AESDecrypt, AESDecryptAuthenticated, AESDecryptWithPassword, AESEncrypt, AESEncryptAuthenticated, AESEncryptWithPassword, DeriveECDHKeySHA256, DeriveECDHSecret, ECDSASign, ECDSAVerify, FixedTimeEquals, GenerateECDHKeyPair, GenerateECDSAKeyPair, GenerateRSAKeyPair, GenerateRandomBytes, HKDFSHA256, HMACSHA256Encrypt, HMACSHA384Encrypt, HMACSHA512Encrypt, HashPasswordPBKDF2SHA256, Local, MD5Encrypt, PBKDF2SHA256, RSADecryptOAEP, RSAEncryptOAEP, RSASignPSS, RSAVerifyPSS, SHA1Encrypt, SHA256Bytes, SHA256Encrypt, SHA384Bytes, SHA384Encrypt, SHA512Bytes, SHA512Encrypt, Session, VerifyPasswordPBKDF2SHA256, addCssUnit, addDays, addMonths, addYears, allEqualBy, average, base64StorageCodec, callOptionalFunction, camelCase, chunk, clamp, cloneDeep, configureInstallationIdentity, configureLogger, configureStorage, contrastRatio, copy, createDateRangeShortcuts, createDateShortcuts, createLogger, createOneMonthRangeFromToday, debounce, decodeBase64, decodeBase64Bytes, decodeBase64Url, decodeBase64UrlBytes, decodeLatin1Base64, decodeSecureBase64, decodeURIComponentRepeatedly, definePropType, detectRuntime, difference, encodeBase64, encodeBase64Bytes, encodeBase64Url, encodeBase64UrlBytes, encodeLatin1Base64, encodeSecureBase64, endOfDay, escapeHtml, formatBytes, formatChineseRelativeTime, formatHexColor, formatRelativeTime, generateUuidV4, getLocalDayBounds, getLocalTimeGreeting, getOrCreateInstallationId, getStartOfToday, groupBy, hasDuplicatesBy, hasOwn, hasWebCrypto, inRange, installationIdentity, intersection, isBrowser, isDateAfterNow, isEqual, isFuture, isMobileUserAgent, isNode, isPlainObject, isSameDay, isStorageConfigured, isTabletUserAgent, isUniApp, isUuidV4, isValidDate, isValidJson, isWebWorker, isWithinInterval, kebabCase, lerp, logger, lowerFirst, makeSlots, mapConcurrent, mapValues, mixHexColorWithBlack, mixHexColorWithWhite, mixHexColors, normalizeWhitespace, omit, omitBy, once, parseHexColor, parseQueryString, partition, pascalCase, pick, pickBy, pickHigherContrastColor, randomInt, randomString, relativeLuminance, removeNullishValues, retry, roundTo, serializeStyle, shallowEqual, sleep, splitWords, startOfDay, sum, symmetricDifference, throttle, toDate, toQueryString, truncateGraphemes, unique, uniqueBy, upperFirst, useBreakpoints, useElementSize, useEmits, useEventListener, useExpose, useNow, useProps, useRender, useResizeObserver, useWindowSize, withDefineType, withInstall, withInstallDirective, withNoopInstall, withTimeout };
|
|
33
|
+
export { AESDecrypt, AESDecryptAuthenticated, AESDecryptWithPassword, AESEncrypt, AESEncryptAuthenticated, AESEncryptWithPassword, DeriveECDHKeySHA256, DeriveECDHSecret, ECDSASign, ECDSAVerify, FixedTimeEquals, GenerateECDHKeyPair, GenerateECDSAKeyPair, GenerateRSAKeyPair, GenerateRandomBytes, HKDFSHA256, HMACSHA256Encrypt, HMACSHA384Encrypt, HMACSHA512Encrypt, HashPasswordPBKDF2SHA256, Local, MD5Encrypt, PBKDF2SHA256, RSADecryptOAEP, RSAEncryptOAEP, RSASignPSS, RSAVerifyPSS, SHA1Encrypt, SHA256Bytes, SHA256Encrypt, SHA384Bytes, SHA384Encrypt, SHA512Bytes, SHA512Encrypt, Session, VerifyPasswordPBKDF2SHA256, addCssUnit, addDays, addMonths, addYears, allEqualBy, average, base64StorageCodec, callOptionalFunction, camelCase, chunk, clamp, cloneDeep, configureInstallationIdentity, configureLogger, configureStorage, contrastRatio, copy, createDateRangeShortcuts, createDateShortcuts, createLogger, createOneMonthRangeFromToday, debounce, decodeBase64, decodeBase64Bytes, decodeBase64Url, decodeBase64UrlBytes, decodeLatin1Base64, decodeSecureBase64, decodeURIComponentRepeatedly, definePropType, detectRuntime, difference, encodeBase64, encodeBase64Bytes, encodeBase64Url, encodeBase64UrlBytes, encodeLatin1Base64, encodeSecureBase64, endOfDay, escapeHtml, formatBytes, formatChineseRelativeTime, formatHexColor, formatRelativeTime, generateUuidV4, getLocalDayBounds, getLocalTimeGreeting, getOrCreateInstallationId, getStartOfToday, groupBy, hasDuplicatesBy, hasOwn, hasWebCrypto, inRange, installationIdentity, intersection, isBrowser, isDateAfterNow, isEqual, isFuture, isMobileUserAgent, isNode, isPlainObject, isSameDay, isStorageConfigured, isTabletUserAgent, isUniApp, isUuidV4, isValidDate, isValidJson, isWebWorker, isWithinInterval, kebabCase, lerp, logger, lowerFirst, makeSlots, mapConcurrent, mapValues, mixHexColorWithBlack, mixHexColorWithWhite, mixHexColors, normalizeWhitespace, omit, omitBy, once, parseHexColor, parseQueryString, partition, pascalCase, pick, pickBy, pickHigherContrastColor, randomInt, randomString, relativeLuminance, removeNullishValues, retry, roundTo, serializeStyle, shallowEqual, sleep, splitWords, startOfDay, sum, symmetricDifference, throttle, toDate, toQueryString, truncateGraphemes, unique, uniqueBy, upperFirst, useBreakpoints, useElementSize, useEmits, useEventListener, useExpose, useNow, useProps, useRender, useResizeObserver, useTransition, useWindowSize, withDefineType, withInstall, withInstallDirective, withNoopInstall, withTimeout };
|
package/dist/vue/index.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import { useNow } from "./now.mjs";
|
|
|
10
10
|
import { definePropType, useProps } from "./props.mjs";
|
|
11
11
|
import { useRender } from "./render.mjs";
|
|
12
12
|
import { makeSlots } from "./slots.mjs";
|
|
13
|
+
import { useTransition } from "./transition.mjs";
|
|
13
14
|
import { useWindowSize } from "./window-size.mjs";
|
|
14
15
|
import { withDefineType } from "./with.mjs";
|
|
15
|
-
export { callOptionalFunction, definePropType, makeSlots, useBreakpoints, useElementSize, useEmits, useEventListener, useExpose, useNow, useProps, useRender, useResizeObserver, useWindowSize, withDefineType, withInstall, withInstallDirective, withNoopInstall };
|
|
16
|
+
export { callOptionalFunction, definePropType, makeSlots, useBreakpoints, useElementSize, useEmits, useEventListener, useExpose, useNow, useProps, useRender, useResizeObserver, useTransition, useWindowSize, withDefineType, withInstall, withInstallDirective, withNoopInstall };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { runtimeGlobals } from "../internal/runtime.mjs";
|
|
2
|
+
import { computed, getCurrentScope, readonly, shallowRef, toValue, watch } from "vue";
|
|
3
|
+
//#region src/vue/transition.ts
|
|
4
|
+
/**
|
|
5
|
+
* 将响应式数值的变化平滑过渡为只读数值。
|
|
6
|
+
*
|
|
7
|
+
* @param source - 有限数值、Ref 或 getter;初值直接显示,不执行入场动画。
|
|
8
|
+
* @param options - 创建时读取的时长与缓动选项
|
|
9
|
+
* @returns 只读数值 Ref;SSR 或缺少动画帧 API 时直接跟随输入。
|
|
10
|
+
* @remarks 浏览器动画必须在 Vue 响应式作用域内创建,停止作用域时自动取消。
|
|
11
|
+
* 新目标从当前显示值继续过渡,首个动画帧开始计时,完成时精确落到目标值。
|
|
12
|
+
* `duration: 0` 直接同步目标。选项不响应后续修改;仅支持单个数值。
|
|
13
|
+
* @throws `Error` 当支持动画帧的环境中不存在 Vue 响应式作用域。
|
|
14
|
+
* @throws `RangeError` 当输入或时长非法;后续非法输入由 Vue watcher 报错,非法缓动结果在动画帧中抛错。
|
|
15
|
+
*/
|
|
16
|
+
function useTransition(source, options = {}) {
|
|
17
|
+
const { duration = 300, transition = (progress) => progress } = options;
|
|
18
|
+
if (!Number.isFinite(duration) || duration < 0) throw new RangeError("`duration` 必须是非负有限数。");
|
|
19
|
+
const readSource = () => {
|
|
20
|
+
const value = toValue(source);
|
|
21
|
+
if (!Number.isFinite(value)) throw new RangeError("`source` 必须是有限数值。");
|
|
22
|
+
return value;
|
|
23
|
+
};
|
|
24
|
+
const output = shallowRef(readSource());
|
|
25
|
+
const window = runtimeGlobals.window;
|
|
26
|
+
if (window === void 0 || typeof window.requestAnimationFrame !== "function" || typeof window.cancelAnimationFrame !== "function") return computed(readSource);
|
|
27
|
+
if (getCurrentScope() === void 0) throw new Error("`useTransition` 必须在 Vue 响应式作用域内调用。");
|
|
28
|
+
watch(readSource, (target, _previous, onCleanup) => {
|
|
29
|
+
let frame;
|
|
30
|
+
let active = true;
|
|
31
|
+
onCleanup(() => {
|
|
32
|
+
active = false;
|
|
33
|
+
if (frame !== void 0) window.cancelAnimationFrame(frame);
|
|
34
|
+
});
|
|
35
|
+
if (duration === 0 || output.value === target) {
|
|
36
|
+
output.value = target;
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const from = output.value;
|
|
40
|
+
let startedAt;
|
|
41
|
+
const tick = (timestamp) => {
|
|
42
|
+
frame = void 0;
|
|
43
|
+
if (!active) return;
|
|
44
|
+
startedAt ??= timestamp;
|
|
45
|
+
const progress = Math.min(1, Math.max(0, (timestamp - startedAt) / duration));
|
|
46
|
+
const weight = progress === 1 ? 1 : transition(progress);
|
|
47
|
+
const value = progress === 1 ? target : from * (1 - weight) + target * weight;
|
|
48
|
+
if (!Number.isFinite(weight) || !Number.isFinite(value)) throw new RangeError("缓动结果必须是有限数值。");
|
|
49
|
+
if (!active) return;
|
|
50
|
+
output.value = value;
|
|
51
|
+
if (active && progress < 1) frame = window.requestAnimationFrame(tick);
|
|
52
|
+
};
|
|
53
|
+
frame = window.requestAnimationFrame(tick);
|
|
54
|
+
}, { flush: "sync" });
|
|
55
|
+
return readonly(output);
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
export { useTransition };
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=transition.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transition.mjs","names":[],"sources":["../../src/vue/transition.ts"],"sourcesContent":["import { computed, getCurrentScope, readonly, shallowRef, toValue, watch } from \"vue\";\nimport { runtimeGlobals } from \"../internal/runtime\";\nimport type { MaybeRefOrGetter, ShallowRef } from \"vue\";\n\n/** 数值过渡选项 */\nexport interface UseTransitionOptions {\n\t/** 过渡时长,单位为毫秒;必须是非负有限数。默认 `300`。 */\n\tduration?: number;\n\t/** 将 `[0, 1]` 的进度映射为有限插值系数,默认线性;允许超出区间以实现回弹。 */\n\ttransition?: (progress: number) => number;\n}\n\n/**\n * 将响应式数值的变化平滑过渡为只读数值。\n *\n * @param source - 有限数值、Ref 或 getter;初值直接显示,不执行入场动画。\n * @param options - 创建时读取的时长与缓动选项\n * @returns 只读数值 Ref;SSR 或缺少动画帧 API 时直接跟随输入。\n * @remarks 浏览器动画必须在 Vue 响应式作用域内创建,停止作用域时自动取消。\n * 新目标从当前显示值继续过渡,首个动画帧开始计时,完成时精确落到目标值。\n * `duration: 0` 直接同步目标。选项不响应后续修改;仅支持单个数值。\n * @throws `Error` 当支持动画帧的环境中不存在 Vue 响应式作用域。\n * @throws `RangeError` 当输入或时长非法;后续非法输入由 Vue watcher 报错,非法缓动结果在动画帧中抛错。\n */\nexport function useTransition(source: MaybeRefOrGetter<number>, options: UseTransitionOptions = {}): Readonly<ShallowRef<number>> {\n\tconst { duration = 300, transition = (progress: number) => progress } = options;\n\tif (!Number.isFinite(duration) || duration < 0) throw new RangeError(\"`duration` 必须是非负有限数。\");\n\tconst readSource = () => {\n\t\tconst value = toValue(source);\n\t\tif (!Number.isFinite(value)) throw new RangeError(\"`source` 必须是有限数值。\");\n\t\treturn value;\n\t};\n\tconst output = shallowRef(readSource());\n\tconst window = runtimeGlobals.window;\n\tif (window === undefined || typeof window.requestAnimationFrame !== \"function\" || typeof window.cancelAnimationFrame !== \"function\") {\n\t\treturn computed(readSource);\n\t}\n\tif (getCurrentScope() === undefined) throw new Error(\"`useTransition` 必须在 Vue 响应式作用域内调用。\");\n\twatch(\n\t\treadSource,\n\t\t(target, _previous, onCleanup) => {\n\t\t\tlet frame: number | undefined;\n\t\t\tlet active = true;\n\t\t\tonCleanup(() => {\n\t\t\t\tactive = false;\n\t\t\t\tif (frame !== undefined) window.cancelAnimationFrame(frame);\n\t\t\t});\n\t\t\tif (duration === 0 || output.value === target) {\n\t\t\t\toutput.value = target;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst from = output.value;\n\t\t\tlet startedAt: number | undefined;\n\t\t\tconst tick = (timestamp: number) => {\n\t\t\t\tframe = undefined;\n\t\t\t\tif (!active) return;\n\t\t\t\tstartedAt ??= timestamp;\n\t\t\t\tconst progress = Math.min(1, Math.max(0, (timestamp - startedAt) / duration));\n\t\t\t\tconst weight = progress === 1 ? 1 : transition(progress);\n\t\t\t\tconst value = progress === 1 ? target : from * (1 - weight) + target * weight;\n\t\t\t\tif (!Number.isFinite(weight) || !Number.isFinite(value)) throw new RangeError(\"缓动结果必须是有限数值。\");\n\t\t\t\tif (!active) return;\n\t\t\t\toutput.value = value;\n\t\t\t\tif (active && progress < 1) frame = window.requestAnimationFrame(tick);\n\t\t\t};\n\t\t\tframe = window.requestAnimationFrame(tick);\n\t\t},\n\t\t{ flush: \"sync\" }\n\t);\n\treturn readonly(output);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAwBA,SAAgB,cAAc,QAAkC,UAAgC,CAAC,GAAiC;CACjI,MAAM,EAAE,WAAW,KAAK,cAAc,aAAqB,aAAa;CACxE,IAAI,CAAC,OAAO,SAA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