sard 1.0.21 → 1.0.22

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.
@@ -5,12 +5,12 @@ declare const __VLS_base: import("vue").DefineComponent<ButtonProps, {}, {}, {},
5
5
  }, string, import("vue").PublicProps, Readonly<ButtonProps> & Readonly<{
6
6
  onClick?: ((event: MouseEvent) => any) | undefined;
7
7
  }>, {
8
+ round: boolean;
8
9
  size: "xs" | "small" | "medium" | "large";
9
10
  loading: boolean;
10
11
  disabled: boolean;
11
12
  color: "primary" | "secondary" | "success" | "warning" | "danger" | "white" | "black";
12
13
  square: boolean;
13
- round: boolean;
14
14
  variant: "solid" | "outlined" | "dashed" | "filled" | "text" | "link";
15
15
  loadingType: "clock" | "circular";
16
16
  block: boolean;
@@ -1,7 +1,7 @@
1
1
  import { type CountToProps } from './common';
2
2
  declare const __VLS_export: import("vue").DefineComponent<CountToProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<CountToProps> & Readonly<{}>, {
3
- value: number;
4
3
  duration: number;
4
+ value: number;
5
5
  separator: string;
6
6
  precision: number;
7
7
  separatorDigit: number;
@@ -1,7 +1,7 @@
1
1
  import { addSeparator } from "../../utils/string.js";
2
+ import { animateNumber } from "../../utils/animation.js";
2
3
  import { defaultCountToProps } from "./common.js";
3
4
  import { computed, createElementBlock, defineComponent, mergeDefaults, onUnmounted, openBlock, ref, toDisplayString, watch } from "vue";
4
- import { createAnimation } from "lwa";
5
5
  //#region packages/sard/components/count-to/count-to.vue
6
6
  var count_to_default = /*@__PURE__*/ defineComponent({
7
7
  __name: "count-to",
@@ -30,14 +30,14 @@ var count_to_default = /*@__PURE__*/ defineComponent({
30
30
  setup(__props) {
31
31
  const props = __props;
32
32
  const number = ref(0);
33
- let tl;
33
+ let animation;
34
34
  const renderedNumer = computed(() => {
35
35
  const fixedNum = number.value.toFixed(props.precision);
36
36
  return props.separator ? addSeparator(fixedNum, props.separator, props.separatorDigit) : fixedNum;
37
37
  });
38
38
  watch(() => props.value, () => {
39
- tl?.pause();
40
- tl = createAnimation(number, { value: props.value }, {
39
+ animation?.pause();
40
+ animation = animateNumber(number, props.value, {
41
41
  duration: props.duration,
42
42
  easing: "easeOutQuint",
43
43
  round: Math.pow(10, props.precision)
@@ -47,7 +47,7 @@ var count_to_default = /*@__PURE__*/ defineComponent({
47
47
  immediate: true
48
48
  });
49
49
  onUnmounted(() => {
50
- tl?.pause();
50
+ animation?.pause();
51
51
  });
52
52
  return (_ctx, _cache) => {
53
53
  return openBlock(), createElementBlock("span", null, toDisplayString(renderedNumer.value), 1);
@@ -7,8 +7,8 @@ declare const __VLS_base: import("vue").DefineComponent<FloatingPanelProps, Floa
7
7
  "onUpdate:height"?: ((value: number) => any) | undefined;
8
8
  "onHeight-change"?: ((value: number) => any) | undefined;
9
9
  }>, {
10
- height: number;
11
10
  duration: number;
11
+ height: number;
12
12
  anchors: number[];
13
13
  contentDraggable: boolean;
14
14
  safeAreaInsetBottom: boolean;
@@ -3,8 +3,8 @@ type __VLS_Slots = SkeletonSlots;
3
3
  declare const __VLS_base: import("vue").DefineComponent<SkeletonProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<SkeletonProps> & Readonly<{}>, {
4
4
  title: boolean;
5
5
  animated: boolean;
6
- loading: boolean;
7
6
  round: boolean;
7
+ loading: boolean;
8
8
  avatar: boolean;
9
9
  rows: number;
10
10
  avatarSize: string;
@@ -1,14 +1,14 @@
1
+ import { animateNumber } from "../../utils/animation.js";
1
2
  import { withResolvers } from "../../utils/polyfill.js";
2
3
  import { onUnmounted } from "vue";
3
- import { createAnimation } from "lwa";
4
4
  //#region packages/sard/components/swiper/useSwiperAnimation.ts
5
5
  function useSwiperAnimation(target) {
6
- let tl;
6
+ let animation;
7
7
  let promiseWithResolvers;
8
8
  const play = (value, duration, update) => {
9
- tl?.pause();
9
+ animation?.pause();
10
10
  promiseWithResolvers = withResolvers();
11
- tl = createAnimation(target, { value }, {
11
+ animation = animateNumber(target, value, {
12
12
  duration,
13
13
  easing: "easeOutCubic",
14
14
  update,
@@ -19,7 +19,7 @@ function useSwiperAnimation(target) {
19
19
  return promiseWithResolvers.promise;
20
20
  };
21
21
  const pause = () => {
22
- tl?.pause();
22
+ animation?.pause();
23
23
  };
24
24
  onUnmounted(() => {
25
25
  pause();
@@ -7,8 +7,8 @@ declare const __VLS_base: import("vue").DefineComponent<TabbarProps, {}, {}, {},
7
7
  onChange?: ((value: string | number) => any) | undefined;
8
8
  "onUpdate:modelValue"?: ((value: string | number) => any) | undefined;
9
9
  }>, {
10
- fixed: boolean;
11
10
  modelValue: number | string;
11
+ fixed: boolean;
12
12
  color: string;
13
13
  bordered: boolean;
14
14
  safeAreaInsetBottom: boolean;
@@ -8,10 +8,10 @@ declare const __VLS_base: import("vue").DefineComponent<TagProps, {}, {}, {}, {}
8
8
  onClose?: ((event: any) => any) | undefined;
9
9
  }>, {
10
10
  mark: "left" | "right";
11
+ round: boolean;
11
12
  size: "small" | "medium" | "large";
12
13
  color: "default" | "primary" | "success" | "warning" | "danger";
13
14
  closable: boolean;
14
- round: boolean;
15
15
  variant: "filled" | "solid" | "outlined";
16
16
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
17
17
  declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sard",
3
- "version": "1.0.21",
3
+ "version": "1.0.22",
4
4
  "description": "sard 是基于 Vue3 的 Web 移动端 UI 组件库",
5
5
  "keywords": [
6
6
  "UI",
@@ -20,12 +20,10 @@
20
20
  "main": "index.js",
21
21
  "devDependencies": {
22
22
  "@sard/icons": "^0.1.0",
23
- "lwa": "^0.3.0",
24
23
  "vue": "^3.5.0"
25
24
  },
26
25
  "peerDependencies": {
27
26
  "@sard/icons": "^0.1.0",
28
- "lwa": "^0.3.0",
29
27
  "vue": "^3.5.0"
30
28
  }
31
29
  }
@@ -1,6 +1,6 @@
1
1
  import { random } from "../utils/number.js";
2
+ import { ticker } from "../utils/animation.js";
2
3
  import { computed, onScopeDispose, ref, unref } from "vue";
3
- import { ticker } from "lwa";
4
4
  //#region packages/sard/use/useLuckyDraw.ts
5
5
  const defaultOptions = {
6
6
  minSpeed: .1,
package/use/usePopper.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { clamp } from "../utils/number.js";
2
2
  import { isRectEqual } from "../utils/geometry.js";
3
+ import { ticker } from "../utils/animation.js";
3
4
  import { onBeforeUnmount, reactive, watch } from "vue";
4
- import { ticker } from "lwa";
5
5
  //#region packages/sard/use/usePopper.ts
6
6
  const directions = [
7
7
  "top",
@@ -0,0 +1,31 @@
1
+ import { type Ref } from 'vue';
2
+ type TickCallback = () => void;
3
+ /**
4
+ * 基于单个 requestAnimationFrame 的共享循环,多个动画共用同一帧循环。
5
+ */
6
+ export declare const ticker: {
7
+ add(callback: TickCallback): void;
8
+ remove(callback: TickCallback): void;
9
+ };
10
+ type EasingName = 'easeOutCubic' | 'easeOutQuint';
11
+ export interface AnimateNumberOptions {
12
+ /** 动画时长,单位毫秒 */
13
+ duration?: number;
14
+ /** 缓动函数名或自定义缓动函数 */
15
+ easing?: EasingName | ((k: number) => number);
16
+ /** 取整因子,每帧值会被舍入为 Math.round(value * round) / round */
17
+ round?: number;
18
+ /** 每帧更新后回调 */
19
+ update?: () => void;
20
+ /** 动画结束回调 */
21
+ complete?: () => void;
22
+ }
23
+ export interface Animation {
24
+ /** 暂停动画,暂停后不会触发 complete */
25
+ pause: () => void;
26
+ }
27
+ /**
28
+ * 将数字 ref 的 value 从当前值缓动到目标值,创建后自动播放。
29
+ */
30
+ export declare function animateNumber(ref: Ref<number>, to: number, options?: AnimateNumberOptions): Animation;
31
+ export {};
@@ -0,0 +1,56 @@
1
+ //#region packages/sard/utils/animation.ts
2
+ const callbacks = /* @__PURE__ */ new Set();
3
+ let rafId = 0;
4
+ function loop() {
5
+ rafId = requestAnimationFrame(loop);
6
+ callbacks.forEach((callback) => callback());
7
+ }
8
+ /**
9
+ * 基于单个 requestAnimationFrame 的共享循环,多个动画共用同一帧循环。
10
+ */
11
+ const ticker = {
12
+ add(callback) {
13
+ callbacks.add(callback);
14
+ if (rafId === 0) rafId = requestAnimationFrame(loop);
15
+ },
16
+ remove(callback) {
17
+ callbacks.delete(callback);
18
+ if (rafId !== 0 && callbacks.size === 0) {
19
+ cancelAnimationFrame(rafId);
20
+ rafId = 0;
21
+ }
22
+ }
23
+ };
24
+ const easings = {
25
+ easeOutCubic: (k) => 1 - Math.pow(1 - k, 3),
26
+ easeOutQuint: (k) => 1 - Math.pow(1 - k, 5)
27
+ };
28
+ /**
29
+ * 将数字 ref 的 value 从当前值缓动到目标值,创建后自动播放。
30
+ */
31
+ function animateNumber(ref, to, options = {}) {
32
+ const { duration = 0, easing = "easeOutCubic", round, update, complete } = options;
33
+ const easingFn = typeof easing === "function" ? easing : easings[easing];
34
+ const from = ref.value;
35
+ const change = to - from;
36
+ const start = performance.now();
37
+ const setValue = (value) => {
38
+ ref.value = round === void 0 ? value : Math.round(value * round) / round;
39
+ };
40
+ const tick = () => {
41
+ const progress = duration > 0 ? Math.min((performance.now() - start) / duration, 1) : 1;
42
+ setValue(from + change * easingFn(progress));
43
+ update?.();
44
+ if (progress >= 1) {
45
+ pause();
46
+ complete?.();
47
+ }
48
+ };
49
+ const pause = () => {
50
+ ticker.remove(tick);
51
+ };
52
+ ticker.add(tick);
53
+ return { pause };
54
+ }
55
+ //#endregion
56
+ export { animateNumber, ticker };
@@ -1,4 +1,4 @@
1
- import { ticker } from "lwa";
1
+ import { ticker } from "./animation.js";
2
2
  //#region packages/sard/utils/inertialAnimate.ts
3
3
  const friction = .95;
4
4
  const minVelocity = .1;
@@ -1,14 +1,14 @@
1
+ import { animateNumber } from "../animation.js";
1
2
  import { withResolvers } from "../polyfill.js";
2
3
  import { onUnmounted } from "vue";
3
- import { createAnimation } from "lwa";
4
4
  //#region packages/sard/utils/scroller/useEasingAnimation.ts
5
5
  function useEasingAnimation(target) {
6
- let tl;
6
+ let animation;
7
7
  let promiseWithResolvers;
8
8
  const play = (value, duration) => {
9
- tl?.pause();
9
+ animation?.pause();
10
10
  promiseWithResolvers = withResolvers();
11
- tl = createAnimation(target, { value }, {
11
+ animation = animateNumber(target, value, {
12
12
  duration,
13
13
  easing: "easeOutCubic",
14
14
  complete() {
@@ -18,7 +18,7 @@ function useEasingAnimation(target) {
18
18
  return promiseWithResolvers.promise;
19
19
  };
20
20
  const pause = () => {
21
- tl?.pause();
21
+ animation?.pause();
22
22
  };
23
23
  onUnmounted(() => {
24
24
  pause();
@@ -1,4 +1,4 @@
1
- import { ticker } from "lwa";
1
+ import { ticker } from "../animation.js";
2
2
  //#region packages/sard/utils/scroller/useScrollAnimation.ts
3
3
  /**
4
4
  * 创建一个基于 requestAnimationFrame 的动画循环。