@rxdrag/website-lib 0.0.9 → 0.0.11

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/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Do not write code directly here, instead use the `src` folder!
2
- // Then, use this file to export everything you want your user to access.
3
-
4
- export * from './src/index';
1
+ // Do not write code directly here, instead use the `src` folder!
2
+ // Then, use this file to export everything you want your user to access.
3
+
4
+ export * from './src/index';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rxdrag/website-lib",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.ts"
@@ -22,19 +22,19 @@
22
22
  "@types/react-dom": "^18.2.7",
23
23
  "astro": "^4.0.0",
24
24
  "eslint": "^7.32.0",
25
+ "gsap": "^3.12.7",
25
26
  "typescript": "^5",
26
- "@rxdrag/tsconfig": "0.2.0",
27
- "@rxdrag/entify-hooks": "0.2.39",
28
- "@rxdrag/eslint-config-custom": "0.2.11",
29
- "@rxdrag/slate-preview": "1.2.54"
27
+ "@rxdrag/slate-preview": "1.2.55",
28
+ "@rxdrag/entify-hooks": "0.2.40",
29
+ "@rxdrag/eslint-config-custom": "0.2.12",
30
+ "@rxdrag/tsconfig": "0.2.0"
30
31
  },
31
32
  "dependencies": {
32
33
  "clsx": "^2.1.0",
33
- "motion": "^12.4.7",
34
34
  "react": "^18.2.0",
35
35
  "react-dom": "^18.2.0",
36
- "@rxdrag/rxcms-models": "0.3.45",
37
- "@rxdrag/website-lib-core": "0.0.7"
36
+ "@rxdrag/website-lib-core": "0.0.9",
37
+ "@rxdrag/rxcms-models": "0.3.46"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "astro": "^4.0.0 || ^5.0.0"
@@ -1,14 +1,10 @@
1
1
  ---
2
- import { AnimationOptions } from "motion";
2
+ import {
3
+ getAnimationNumberDataAttrs,
4
+ type AnimationNumberProps,
5
+ } from "@rxdrag/website-lib-core";
3
6
 
4
- interface Props {
5
- start?: number;
6
- end?: number;
7
- transition?: AnimationOptions;
8
- class?: string;
9
- sign?: "string";
10
- once?: boolean;
11
- }
7
+ interface Props extends AnimationNumberProps {}
12
8
 
13
9
  const {
14
10
  start = 0,
@@ -17,88 +13,31 @@ const {
17
13
  class: className,
18
14
  sign = "+",
19
15
  once = false,
16
+ type = "int",
17
+ fractionDigits = 1,
20
18
  } = Astro.props;
21
19
 
22
- const motionValue = {
20
+ const attrs = getAnimationNumberDataAttrs({
23
21
  start,
24
22
  end,
25
23
  transition,
26
- };
24
+ type,
25
+ fractionDigits,
26
+ once,
27
+ });
27
28
  ---
28
29
 
29
- <div
30
- data-animation-number={JSON.stringify(motionValue)}
31
- data-animation-number-once={once}
32
- class:list={["flex items-center justify-center gap-2", className]}
33
- >
30
+ <div {...attrs} class={className}>
34
31
  <span class="motion-safe:animate-number">{start}</span>
35
- {
36
- sign && (
37
- <span class="motion-safe:animate-sign" style="display: none;">
38
- {sign}
39
- </span>
40
- )
41
- }
32
+ {sign && <span class="motion-safe:animate-sign hidden">{sign}</span>}
42
33
  </div>
43
34
 
44
35
  <script>
45
- import { onEverySwap, onPageLoaded } from "@rxdrag/website-lib-core";
46
- import { animate, inView } from "motion";
36
+ import { pageLoader } from "@rxdrag/website-lib-core";
37
+ import { numberController } from "@rxdrag/website-lib-core";
47
38
 
48
- function initAnimation() {
49
- const elements = document.querySelectorAll("[data-animation-number]");
50
- elements.forEach((element) => {
51
- if (element instanceof HTMLElement) {
52
- if (element.dataset.animationNumber) {
53
- const data = JSON.parse(element.dataset.animationNumber);
54
- // 确保 start 和 end 是数字类型
55
- const startValue = Number(data.start);
56
- const endValue = Number(data.end);
57
- const transition = data.transition;
58
- const once = element.dataset.animationNumberOnce === "true";
59
-
60
- const numberElement = element.querySelector(
61
- ".motion-safe\\:animate-number"
62
- ) as HTMLElement;
63
- const signElement = element.querySelector(
64
- ".motion-safe\\:animate-sign"
65
- ) as HTMLElement;
66
-
67
- inView(numberElement, () => {
68
- const aleadyRun =
69
- numberElement.dataset.animationNumberRun === "true";
70
- if (aleadyRun && once) {
71
- return;
72
- }
73
- numberElement.dataset.animationNumberRun = "true";
74
- animate(startValue, endValue, {
75
- ...transition,
76
- onUpdate: (latest) =>
77
- (numberElement.innerHTML = Math.round(latest)?.toString()),
78
- onComplete: () => {
79
- if (signElement) {
80
- signElement.style.display = "inline";
81
- }
82
- },
83
- });
84
- return () => {
85
- if (!once) {
86
- numberElement.innerHTML = startValue.toString();
87
- if (signElement) {
88
- signElement.style.display = "none";
89
- }
90
- }
91
- };
92
- });
93
- }
94
- }
95
- });
96
- }
97
-
98
- onPageLoaded(() => {
99
- initAnimation();
100
- });
101
- onEverySwap(() => {
102
- initAnimation();
39
+ // 页面加载后重新初始化动画
40
+ pageLoader.onLoaded(() => {
41
+ numberController.mount();
103
42
  });
104
43
  </script>
@@ -1,5 +1,5 @@
1
1
  ---
2
- import { HTMLElementsWithChildren } from "./MotionTypes";
2
+ import { type HTMLElementsWithChildren } from "@rxdrag/website-lib-core";
3
3
 
4
4
  interface Props {
5
5
  flipKey?: string;
@@ -35,19 +35,9 @@ const flipProps = {
35
35
  </style>
36
36
 
37
37
  <script>
38
- import { onEverySwap, onPageLoaded } from "@rxdrag/website-lib-core";
39
- import { FlipController } from "./FlipLogic";
40
-
41
- const initFlip = () => {
42
- FlipController.getInstance().init();
43
- };
44
-
38
+ import { flip, pageLoader } from "@rxdrag/website-lib-core";
45
39
  // 在页面加载和每次页面转场后都初始化Flip
46
- onPageLoaded(() => {
47
- initFlip();
48
- });
49
-
50
- onEverySwap(() => {
51
- initFlip();
40
+ pageLoader.onLoaded(() => {
41
+ flip.mount();
52
42
  });
53
43
  </script>
@@ -1,81 +1,47 @@
1
- ---
2
- import { LinkType, toHref } from "./LinkLogic";
3
- import { IMotionProps } from "./MotionTypes";
4
- import Motion from "./Motion.astro";
5
-
6
- // 定义a标签属性的接口
7
- interface AnchorAttributes {
8
- target?: "_blank" | "_self" | "_parent" | "_top";
9
- rel?: string;
10
- download?: boolean | string;
11
- ping?: string;
12
- referrerpolicy?: string;
13
- hreflang?: string;
14
- }
15
-
16
- interface Props extends IMotionProps, AnchorAttributes {
17
- type?: LinkType | string;
18
- to?: string;
19
- class?: string;
20
- //用于active类名的传递
21
- activeWhen?: string | true;
22
- }
23
-
24
- const { type, to, class: className, activeWhen, ...props } = Astro.props;
25
- const href = toHref(type, to);
26
- ---
27
-
28
- <Motion
29
- as="a"
30
- data-actived-path={activeWhen}
31
- href={href}
32
- class={className}
33
- {...props}
34
- >
35
- <slot />
36
- </Motion>
37
-
38
- <script>
39
- import { onEverySwap, onPageLoaded } from "@rxdrag/website-lib-core";
40
-
41
- const initLinks = () => {
42
- // 获取当前URL的路径部分(去除域名)
43
- const currentPath = window.location.pathname;
44
-
45
- // 获取所有导航链接
46
- const links = document.querySelectorAll<HTMLAnchorElement>(
47
- "[data-actived-path]"
48
- );
49
-
50
- links.forEach((anchorLink) => {
51
- // 从链接URL中提取路径部分
52
- try {
53
- const linkUrl = new URL(anchorLink.href);
54
- const linkPath =
55
- anchorLink.dataset.activedPath === "true"
56
- ? linkUrl.pathname
57
- : anchorLink.dataset.activedPath;
58
-
59
- // 检查当前路径是否与链接路径匹配或是其子路径
60
- if (
61
- currentPath === linkPath ||
62
- (linkPath !== "/" && linkPath && currentPath.startsWith(linkPath))
63
- ) {
64
- anchorLink.classList.add("actived");
65
- } else {
66
- anchorLink.classList.remove("actived");
67
- }
68
- } catch (e) {
69
- // 处理无效URL的情况
70
- console.warn("Invalid URL:", e, anchorLink);
71
- }
72
- });
73
- };
74
-
75
- onEverySwap(() => {
76
- initLinks();
77
- });
78
- onPageLoaded(() => {
79
- initLinks();
80
- });
81
- </script>
1
+ ---
2
+ import {
3
+ toHref,
4
+ type IMotionProps,
5
+ type LinkType,
6
+ } from "@rxdrag/website-lib-core";
7
+ import Motion from "./Motion.astro";
8
+
9
+ // 定义a标签属性的接口
10
+ interface AnchorAttributes {
11
+ target?: "_blank" | "_self" | "_parent" | "_top";
12
+ rel?: string;
13
+ download?: boolean | string;
14
+ ping?: string;
15
+ referrerpolicy?: string;
16
+ hreflang?: string;
17
+ }
18
+
19
+ interface Props extends IMotionProps, AnchorAttributes {
20
+ type?: LinkType | string;
21
+ to?: string;
22
+ class?: string;
23
+ //用于active类名的传递
24
+ activeWhen?: string | true;
25
+ }
26
+
27
+ const { type, to, class: className, activeWhen, ...props } = Astro.props;
28
+ const href = toHref(type || "", to || "");
29
+ ---
30
+
31
+ <Motion
32
+ as="a"
33
+ data-actived-path={activeWhen}
34
+ href={href}
35
+ class={className}
36
+ {...props}
37
+ >
38
+ <slot />
39
+ </Motion>
40
+
41
+ <script>
42
+ import { initLinks, pageLoader } from "@rxdrag/website-lib-core";
43
+
44
+ pageLoader.onLoaded(() => {
45
+ initLinks();
46
+ });
47
+ </script>
@@ -1,66 +1,64 @@
1
- ---
2
- import { PageMeta } from "@rxdrag/rxcms-models";
3
-
4
- interface Props {
5
- content?: PageMeta;
6
- title?: string;
7
- }
8
-
9
- const { content, title: propTitle } = Astro.props;
10
-
11
- // 从content中提取SEO相关属性
12
- const {
13
- // SeoMeta属性
14
- seoTitle,
15
- seoKeywords,
16
- seoDescription,
17
- seoAuthor,
18
- publisher,
19
- seoRobots,
20
- // OgMeta属性
21
- ogTitle,
22
- ogDescription,
23
- ogUrl,
24
- ogSiteName,
25
- ogType,
26
- xCard,
27
- xSite,
28
- xTitle,
29
- xDescription,
30
- xUrl,
31
- // 其他属性
32
- ogImage,
33
- } = content || {};
34
-
35
- const title = propTitle || seoTitle || "YiZhanFei";
36
-
37
- const canonicalURL = Astro.url.href;
38
- const imageUrl = ogImage?.file?.url || "";
39
- ---
40
-
41
- <title>{seoTitle || title}</title>
42
- <meta name="description" content={seoDescription} />
43
- <meta name="keywords" content={seoKeywords} />
44
- <meta name="author" content={seoAuthor} />
45
- <meta name="publisher" content={publisher} />
46
- <meta name="robots" content={seoRobots || "index, follow"} />
47
- <link rel="canonical" href={canonicalURL} />
48
-
49
- <!-- Open Graph / Facebook -->
50
- <meta property="og:type" content={ogType || "website"} />
51
- <meta property="og:url" content={ogUrl || canonicalURL} />
52
- <meta property="og:title" content={ogTitle || title} />
53
- <meta property="og:description" content={ogDescription || seoDescription} />
54
- <meta property="og:image" content={imageUrl} />
55
- {ogSiteName && <meta property="og:site_name" content={ogSiteName} />}
56
-
57
- <!-- Twitter -->
58
- <meta property="twitter:card" content={xCard || "summary_large_image"} />
59
- <meta property="twitter:url" content={xUrl || ogUrl || canonicalURL} />
60
- <meta property="twitter:title" content={xTitle || ogTitle || title} />
61
- <meta
62
- property="twitter:description"
63
- content={xDescription || ogDescription || seoDescription}
64
- />
65
- <meta property="twitter:image" content={imageUrl} />
66
- {xSite && <meta property="twitter:site" content={xSite} />}
1
+ ---
2
+ import type { PageMeta } from "@rxdrag/rxcms-models";
3
+
4
+ interface Props {
5
+ content?: PageMeta;
6
+ title?: string;
7
+ }
8
+
9
+ const { content, title: propTitle } = Astro.props;
10
+
11
+ // 从content中提取SEO相关属性
12
+ const {
13
+ // SeoMeta属性
14
+ seoTitle,
15
+ seoKeywords,
16
+ seoDescription,
17
+ seoAuthor,
18
+ publisher,
19
+ seoRobots,
20
+ // OgMeta属性
21
+ ogTitle,
22
+ ogDescription,
23
+ ogUrl,
24
+ ogSiteName,
25
+ ogType,
26
+ xCard,
27
+ xSite,
28
+ xUrl,
29
+ // 其他属性
30
+ ogImage,
31
+ } = content || {};
32
+
33
+ const title = propTitle || seoTitle || "YiZhanFei";
34
+
35
+ const canonicalURL = Astro.url.href;
36
+ const imageUrl = ogImage?.file?.url || "";
37
+ ---
38
+
39
+ <title>{seoTitle || title}</title>
40
+ <meta name="description" content={seoDescription} />
41
+ <meta name="keywords" content={seoKeywords} />
42
+ <meta name="author" content={seoAuthor} />
43
+ <meta name="publisher" content={publisher} />
44
+ <meta name="robots" content={seoRobots || "index, follow"} />
45
+ <link rel="canonical" href={canonicalURL} />
46
+
47
+ <!-- Open Graph / Facebook -->
48
+ <meta property="og:type" content={ogType || "website"} />
49
+ <meta property="og:url" content={ogUrl || canonicalURL} />
50
+ <meta property="og:title" content={ogTitle || title} />
51
+ <meta property="og:description" content={ogDescription || seoDescription} />
52
+ <meta property="og:image" content={imageUrl} />
53
+ {ogSiteName && <meta property="og:site_name" content={ogSiteName} />}
54
+
55
+ <!-- Twitter -->
56
+ <meta property="twitter:card" content={xCard || "summary_large_image"} />
57
+ <meta property="twitter:url" content={xUrl || ogUrl || canonicalURL} />
58
+ <meta property="twitter:title" content={ogTitle || title} />
59
+ <meta
60
+ property="twitter:description"
61
+ content={ogDescription || seoDescription}
62
+ />
63
+ <meta property="twitter:image" content={imageUrl} />
64
+ {xSite && <meta property="twitter:site" content={xSite} />}
@@ -1,69 +1,14 @@
1
1
  ---
2
- import type { CSSProperties } from "react";
3
- import Popup from "./Popup.astro";
4
- import { DATA_POPUP_ROLE, PopupRole } from "@rxdrag/website-lib-core";
5
- import type { IMotionProps } from "./MotionTypes";
2
+ import { getModalDataAttrs, type IMotionProps } from "@rxdrag/website-lib-core";
3
+ import Motion from "./Motion.astro";
6
4
 
7
5
  interface Props extends IMotionProps {
8
6
  popupKey: string;
9
- class?: string;
10
- style?: string | CSSProperties;
11
7
  }
12
8
 
13
- const roleProps = {
14
- [DATA_POPUP_ROLE]: PopupRole.ModalContainer,
15
- };
9
+ const dataAttrs = getModalDataAttrs(Astro.props.popupKey);
16
10
  ---
17
11
 
18
- <Popup {...roleProps} {...Astro.props}>
12
+ <Motion {...dataAttrs} {...Astro.props}>
19
13
  <slot />
20
- </Popup>
21
-
22
- <script>
23
- import {
24
- initModal,
25
- initModalCloser,
26
- onEverySwap,
27
- onPageLoaded,
28
- } from "@rxdrag/website-lib-core";
29
- import {
30
- DATA_POPUP,
31
- DATA_POPUP_ROLE,
32
- PopupRole,
33
- } from "@rxdrag/website-lib-core";
34
-
35
- const initModals = () => {
36
- // 获取所有的 Modal 实例
37
- const popups = document.querySelectorAll(`[${DATA_POPUP}]`);
38
- popups.forEach((popup) => {
39
- const popupKey = popup.getAttribute(DATA_POPUP);
40
- //处理鼠标交互事件
41
- if (popupKey && popup) {
42
- if (popup.getAttribute(DATA_POPUP_ROLE) === PopupRole.ModalTrigger) {
43
- initModal(popupKey, popup as HTMLElement);
44
- }
45
- }
46
- //获取所有 ModalCloser 实例,并处理点击事件
47
- //TODO:未处理嵌套跟Modal外部关闭的情况
48
- const closers = popup.querySelectorAll(
49
- `[${DATA_POPUP_ROLE}="${PopupRole.ModalCloser}"]`
50
- );
51
-
52
- closers.forEach((closer) => {
53
- // 使用initModalCloser函数处理关闭按钮事件
54
- if (popupKey) {
55
- initModalCloser(popupKey, closer as HTMLElement);
56
- }
57
- });
58
- });
59
- };
60
-
61
- // 在页面加载和每次页面转场后都初始化Modal
62
- onPageLoaded(() => {
63
- initModals();
64
- });
65
-
66
- onEverySwap(() => {
67
- initModals();
68
- });
69
- </script>
14
+ </Motion>
@@ -1,22 +1,19 @@
1
1
  ---
2
- import { CSSProperties } from "react";
3
- import { DATA_POPUP_ROLE, PopupRole } from "@rxdrag/website-lib-core";
4
- import Popup from "./Popup.astro";
5
- import { IMotionProps } from "./MotionTypes";
2
+ import {
3
+ type IMotionProps,
4
+ getModalCloserDataAttrs,
5
+ } from "@rxdrag/website-lib-core";
6
+ import { Motion } from "../..";
6
7
 
7
8
  interface Props extends IMotionProps {
8
9
  popupKey?: string;
9
- class?: string;
10
- style?: string | CSSProperties;
11
10
  }
12
11
 
13
- const roleProps = {
14
- [DATA_POPUP_ROLE]: PopupRole.ModalCloser,
15
- };
12
+ const dataAttrs = getModalCloserDataAttrs(Astro.props.popupKey);
16
13
  ---
17
14
 
18
- <Popup {...roleProps} {...Astro.props}>
15
+ <Motion {...dataAttrs} {...Astro.props}>
19
16
  <slot />
20
- </Popup>
17
+ </Motion>
21
18
 
22
19
  <script></script>
@@ -1,22 +1,19 @@
1
1
  ---
2
- import { CSSProperties } from "react";
3
- import { DATA_POPUP_ROLE, PopupRole } from "@rxdrag/website-lib-core";
4
- import Popup from "./Popup.astro";
5
- import { IMotionProps } from "./MotionTypes";
2
+ import {
3
+ getModalPanelDataAttrs,
4
+ type IMotionProps,
5
+ } from "@rxdrag/website-lib-core";
6
+ import Motion from "./Motion.astro";
6
7
 
7
8
  interface Props extends IMotionProps {
8
9
  popupKey?: string;
9
- class?: string;
10
- style?: string | CSSProperties;
11
10
  }
12
11
 
13
- const roleProps = {
14
- [DATA_POPUP_ROLE]: PopupRole.ModalPanel,
15
- };
12
+ const dataAttrs = getModalPanelDataAttrs(Astro.props.popupKey);
16
13
  ---
17
14
 
18
- <Popup {...roleProps} {...Astro.props}>
15
+ <Motion {...dataAttrs} {...Astro.props}>
19
16
  <slot />
20
- </Popup>
17
+ </Motion>
21
18
 
22
19
  <script></script>
@@ -1,30 +1,18 @@
1
1
  ---
2
- import { CSSProperties } from "react";
3
2
  import {
4
- DATA_POPUP_CTA,
5
- DATA_POPUP_ROLE,
6
- PopupRole,
3
+ getModalTriggerDataAttrs,
4
+ type ModalTriggerProps,
7
5
  } from "@rxdrag/website-lib-core";
8
- import Popup from "./Popup.astro";
9
- import { HTMLElementsWithChildren, IMotionProps } from "./MotionTypes";
6
+ import Motion from "./Motion.astro";
10
7
 
11
- interface Props extends IMotionProps {
12
- popupKey: string;
13
- callToAction?: string;
14
- as?: HTMLElementsWithChildren;
15
- class?: string;
16
- style?: string | CSSProperties;
17
- }
8
+ interface Props extends ModalTriggerProps {}
18
9
 
19
10
  const { callToAction, ...rest } = Astro.props;
20
- const roleProps = {
21
- [DATA_POPUP_CTA]: callToAction,
22
- [DATA_POPUP_ROLE]: PopupRole.ModalTrigger,
23
- };
11
+ const dataAttrs = getModalTriggerDataAttrs(Astro.props.popupKey);
24
12
  ---
25
13
 
26
- <Popup {...roleProps} {...rest}>
14
+ <Motion {...dataAttrs} {...rest}>
27
15
  <slot />
28
- </Popup>
16
+ </Motion>
29
17
 
30
18
  <script></script>