@ray-js/components 1.7.55 → 1.7.56-beta.1

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.
@@ -0,0 +1,47 @@
1
+ interface IAnimation {
2
+ // transform
3
+ translate(x?: number, y?: number): this
4
+ translateX(x?: number): this
5
+ translateY(y?: number): this
6
+ translateZ(z?: number): this
7
+
8
+ rotate(angle: number): this
9
+ rotateX(angle: number): this
10
+ rotateY(angle: number): this
11
+ rotateZ(angle: number): this
12
+ rotate3d(x: number, y: number, z: number, angle: number): this
13
+
14
+ scale(x?: number, y?: number): this
15
+ scaleX(x?: number): this
16
+ scaleY(y?: number): this
17
+ scaleZ(z?: number): this
18
+ scale3d(x?: number, y?: number, z?: number): this
19
+
20
+ skew(x?: number, y?: number): this
21
+ skewX(x?: number): this
22
+ skewY(y?: number): this
23
+
24
+ matrix(...args: number[]): this
25
+ matrix3d(...args: number[]): this
26
+
27
+ // style
28
+ opacity(opacity: number): this
29
+ width(value: number | string): this
30
+ height(value: number | string): this
31
+ top(value: number | string): this
32
+ left(value: number | string): this
33
+ right(value: number | string): this
34
+ bottom(value: number | string): this
35
+ backgroundColor(value: string): this
36
+
37
+ // step / export
38
+ step(
39
+ options?: Partial<{
40
+ transformOrigin: string
41
+ duration: number
42
+ timingFunction: string
43
+ delay: number
44
+ }>
45
+ ): this
46
+ export(): { actions: any[] }
47
+ }
@@ -0,0 +1,295 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
+ const _excluded = ["finish"];
4
+ import "core-js/modules/es.regexp.exec.js";
5
+ import "core-js/modules/es.string.replace.js";
6
+ import "core-js/modules/esnext.iterator.constructor.js";
7
+ import "core-js/modules/esnext.iterator.for-each.js";
8
+ import "core-js/modules/esnext.iterator.map.js";
9
+ import "core-js/modules/web.dom-collections.iterator.js";
10
+ /**
11
+ * Animated - 纯净底层动画组件
12
+ *
13
+ * 只提供三个核心方法:
14
+ * - setProperty(property, value): 设置动画属性
15
+ * - setStyle(style): 设置样式
16
+ * - setText(text): 设置文本内容
17
+ *
18
+ * 可以配合任何动画库使用(GSAP、Anime.js、Framer Motion 等)
19
+ */
20
+ import React, { forwardRef, useImperativeHandle, useRef, useMemo, useCallback } from 'react';
21
+ import TyAnimatedComponent from './native/ty-animated';
22
+
23
+ // 小程序 API 声明
24
+
25
+ /**
26
+ * 样式对象转 CSS 字符串
27
+ */
28
+ function styleToString(style) {
29
+ return Object.entries(style).map(_ref => {
30
+ let [key, value] = _ref;
31
+ const cssKey = key.replace(/([A-Z])/g, '-$1').toLowerCase();
32
+ return "".concat(cssKey, ":").concat(value);
33
+ }).join(';');
34
+ }
35
+
36
+ /**
37
+ * 基础 Animated 组件
38
+ */
39
+ const AnimatedBase = /*#__PURE__*/forwardRef((props, ref) => {
40
+ const {
41
+ children,
42
+ className,
43
+ style,
44
+ id,
45
+ mode = 'view',
46
+ onAnimationStart,
47
+ onAnimationEnd,
48
+ // 核心触摸事件(只保留最常用的三个)
49
+ onClick,
50
+ onTouchStart,
51
+ onTouchEnd
52
+ } = props;
53
+ const callbackRef = useRef(onAnimationEnd);
54
+ const componentIdRef = useRef(id || "animated-".concat(Math.random().toString(36).slice(2, 11)));
55
+
56
+ // 提取文本内容(当 mode='text' 时)
57
+ const textContent = useMemo(() => {
58
+ if (mode !== 'text' || !children) return undefined;
59
+ if (typeof children === 'string' || typeof children === 'number') {
60
+ return String(children);
61
+ }
62
+ return undefined;
63
+ }, [mode, children]);
64
+ useImperativeHandle(ref, () => {
65
+ /**
66
+ * 获取 DOM 实例
67
+ */
68
+ const getDomInstance = () => {
69
+ try {
70
+ var _getCurrentPages;
71
+ const pages = (_getCurrentPages = getCurrentPages) === null || _getCurrentPages === void 0 ? void 0 : _getCurrentPages();
72
+ if (!pages || pages.length === 0) return null;
73
+ const currentPage = pages[pages.length - 1];
74
+ if (!(currentPage !== null && currentPage !== void 0 && currentPage.selectComponent)) return null;
75
+ return currentPage.selectComponent("#".concat(componentIdRef.current));
76
+ } catch (error) {
77
+ console.error('[Animated] 获取组件实例失败:', error);
78
+ return null;
79
+ }
80
+ };
81
+ return {
82
+ /**
83
+ * 设置样式(直通通道)
84
+ * 用途:设置静态样式,绕过 React/Ray 层,提升性能
85
+ * @example
86
+ * ref.current.setStyle({ color: 'red', fontSize: '16px', border: '1px solid #ccc' })
87
+ */
88
+ setStyle(styleValue) {
89
+ var _inst$setCustomStyle;
90
+ const inst = getDomInstance();
91
+ if (!inst) return;
92
+
93
+ // 防止传入 undefined 或空值
94
+ if (styleValue === undefined || styleValue === null) return;
95
+ const styleString = typeof styleValue === 'string' ? styleValue : styleToString(styleValue);
96
+ if (!styleString) return;
97
+ (_inst$setCustomStyle = inst.setCustomStyle) === null || _inst$setCustomStyle === void 0 || _inst$setCustomStyle.call(inst, styleString);
98
+ },
99
+ /**
100
+ * 设置文本内容(仅 mode='text' 时可用)
101
+ * 不触发 React 重渲染
102
+ */
103
+ setText(text) {
104
+ var _inst$__applyText;
105
+ // 运行时检查:只有 Text 组件才能调用 setText
106
+ if (mode !== 'text') {
107
+ console.error('[Animated] setText 只能在 Animated.Text 组件上使用');
108
+ return;
109
+ }
110
+ const inst = getDomInstance();
111
+ if (!inst) {
112
+ console.warn('[Animated] setText: 无法获取组件实例');
113
+ return;
114
+ }
115
+ (_inst$__applyText = inst.__applyText) === null || _inst$__applyText === void 0 || _inst$__applyText.call(inst, text);
116
+ },
117
+ /**
118
+ * 使用小程序原生动画 API
119
+ * 这是性能最优的动画方式
120
+ *
121
+ * @example
122
+ * ref.current?.animate((anim) => {
123
+ * anim.translateX(100).scale(1.2).step({ duration: 300 })
124
+ * }, { transformOrigin: 'center center' })
125
+ */
126
+ animate(callback, options) {
127
+ var _inst$__apply;
128
+ const inst = getDomInstance();
129
+ if (!inst) {
130
+ console.warn('[Animated] animate: 无法获取组件实例');
131
+ return;
132
+ }
133
+ const _ref2 = options || {},
134
+ {
135
+ finish
136
+ } = _ref2,
137
+ option = _objectWithoutProperties(_ref2, _excluded);
138
+ if (finish && typeof finish === 'function') {
139
+ callbackRef.current = event => {
140
+ finish(event);
141
+ callbackRef.current = null;
142
+ };
143
+ }
144
+ (_inst$__apply = inst.__apply) === null || _inst$__apply === void 0 || _inst$__apply.call(inst, callback, option);
145
+ },
146
+ /**
147
+ * 获取元素的布局位置和尺寸信息
148
+ * 基于小程序 SelectorQuery.boundingClientRect API
149
+ */
150
+ getBoundingClientRect() {
151
+ return new Promise(resolve => {
152
+ try {
153
+ // 检查小程序 API 是否存在
154
+ if (typeof ty === 'undefined' || !ty.createSelectorQuery) {
155
+ console.error('[Animated] getBoundingClientRect: ty.createSelectorQuery 不存在');
156
+ resolve(null);
157
+ return;
158
+ }
159
+ const query = ty.createSelectorQuery();
160
+ query.select("#".concat(componentIdRef.current)).boundingClientRect(rect => {
161
+ resolve(rect || null);
162
+ }).exec();
163
+ } catch (error) {
164
+ console.error('[Animated] getBoundingClientRect 执行失败:', error);
165
+ resolve(null);
166
+ }
167
+ });
168
+ },
169
+ /**
170
+ * 获取元素的详细信息(包括样式、属性等)
171
+ * 基于小程序 SelectorQuery.fields API
172
+ */
173
+ getFields(fields) {
174
+ return new Promise(resolve => {
175
+ try {
176
+ // 检查小程序 API 是否存在
177
+ if (typeof ty === 'undefined' || !ty.createSelectorQuery) {
178
+ console.error('[Animated] getFields: ty.createSelectorQuery 不存在');
179
+ resolve(null);
180
+ return;
181
+ }
182
+ const query = ty.createSelectorQuery();
183
+ query.select("#".concat(componentIdRef.current)).fields(fields, res => {
184
+ resolve(res || null);
185
+ }).exec();
186
+ } catch (error) {
187
+ console.error('[Animated] getFields 执行失败:', error);
188
+ resolve(null);
189
+ }
190
+ });
191
+ },
192
+ /**
193
+ * 获取元素的计算后样式
194
+ * 便捷方法,专门用于查询样式
195
+ */
196
+ getComputedStyle(styleNames) {
197
+ return new Promise(resolve => {
198
+ try {
199
+ // 检查小程序 API 是否存在
200
+ if (typeof ty === 'undefined' || !ty.createSelectorQuery) {
201
+ console.error('[Animated] getComputedStyle: ty.createSelectorQuery 不存在');
202
+ resolve(null);
203
+ return;
204
+ }
205
+ const query = ty.createSelectorQuery();
206
+ query.select("#".concat(componentIdRef.current)).fields({
207
+ computedStyle: styleNames
208
+ }, res => {
209
+ if (!res) {
210
+ resolve(null);
211
+ return;
212
+ }
213
+
214
+ // 提取样式信息,过滤掉非样式字段
215
+ const styles = {};
216
+ styleNames.forEach(styleName => {
217
+ if (res[styleName] !== undefined) {
218
+ styles[styleName] = res[styleName];
219
+ }
220
+ });
221
+ resolve(Object.keys(styles).length > 0 ? styles : null);
222
+ }).exec();
223
+ } catch (error) {
224
+ console.error('[Animated] getComputedStyle 执行失败:', error);
225
+ resolve(null);
226
+ }
227
+ });
228
+ }
229
+ };
230
+ }, []);
231
+
232
+ // 处理 customStyle,避免传入 undefined
233
+ const customStyleValue = useMemo(() => {
234
+ if (!style) return undefined;
235
+ return typeof style === 'object' ? styleToString(style) : style;
236
+ }, [style]);
237
+ const handleAnimationEnd = useCallback(event => {
238
+ if (callbackRef.current) {
239
+ callbackRef.current(event);
240
+ callbackRef.current = null;
241
+ }
242
+ if (onAnimationEnd) {
243
+ onAnimationEnd();
244
+ }
245
+ }, [onAnimationEnd, callbackRef.current]);
246
+ const eventBindings = {};
247
+ if (onClick) eventBindings['bind:click'] = onClick;
248
+ if (onTouchStart) eventBindings['bind:touchstart'] = onTouchStart;
249
+ if (onTouchEnd) eventBindings['bind:touchend'] = onTouchEnd;
250
+ if (onAnimationStart) eventBindings['bind:animationbegin'] = onAnimationStart;
251
+ eventBindings['bind:animationfinish'] = handleAnimationEnd;
252
+ return (
253
+ /*#__PURE__*/
254
+ // @ts-ignore - 小程序自定义组件
255
+ React.createElement(TyAnimatedComponent, _extends({
256
+ id: componentIdRef.current,
257
+ __mode: mode,
258
+ customClass: className
259
+ }, customStyleValue ? {
260
+ customStyle: customStyleValue
261
+ } : {}, mode === 'text' && textContent !== undefined ? {
262
+ __text: textContent
263
+ } : {}, eventBindings), mode === 'view' ? children : null)
264
+ );
265
+ });
266
+ AnimatedBase.displayName = 'AnimatedBase';
267
+
268
+ /**
269
+ * Animated.View 组件(不包含 setText)
270
+ */
271
+ const AnimatedView = /*#__PURE__*/forwardRef((props, ref) => /*#__PURE__*/React.createElement(AnimatedBase, _extends({}, props, {
272
+ mode: "view",
273
+ ref: ref
274
+ })));
275
+ AnimatedView.displayName = 'Animated.View';
276
+
277
+ /**
278
+ * Animated.Text 组件(包含 setText)
279
+ */
280
+ const AnimatedText = /*#__PURE__*/forwardRef((props, ref) => /*#__PURE__*/React.createElement(AnimatedBase, _extends({}, props, {
281
+ mode: "text",
282
+ ref: ref
283
+ })));
284
+ AnimatedText.displayName = 'Animated.Text';
285
+
286
+ /**
287
+ * 默认导出
288
+ */
289
+ const Animated = {
290
+ View: AnimatedView,
291
+ Text: AnimatedText
292
+ };
293
+ export default Animated;
294
+
295
+ // 导出类型
@@ -0,0 +1,5 @@
1
+ import * as React from 'react';
2
+ declare const TyAnimated: React.ComponentType<any>;
3
+ export default TyAnimated;
4
+
5
+
@@ -0,0 +1,170 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * TyAnimated - 高性能动画组件(小程序原生层)
4
+ */
5
+
6
+ // 小程序原生组件注册
7
+ Component({
8
+ properties: {
9
+ __mode: {
10
+ type: String,
11
+ value: 'view'
12
+ },
13
+ __text: {
14
+ type: String,
15
+ value: ''
16
+ },
17
+ __style: {
18
+ type: String,
19
+ value: ''
20
+ },
21
+ __className: {
22
+ type: String,
23
+ value: ''
24
+ },
25
+ // 兼容 FastView 接口
26
+ customStyle: {
27
+ type: String,
28
+ value: '',
29
+ observer: function (v) {
30
+ this.setData({
31
+ __style: v
32
+ });
33
+ }
34
+ },
35
+ customClass: {
36
+ type: String,
37
+ value: '',
38
+ observer: function (v) {
39
+ this.setData({
40
+ __className: v
41
+ });
42
+ }
43
+ },
44
+ onAnimationStart: {
45
+ type: null,
46
+ value: null
47
+ },
48
+ // 动画结束回调函数
49
+ onAnimationEnd: {
50
+ type: null,
51
+ value: null
52
+ }
53
+ },
54
+ // 定义外部事件
55
+ externalClasses: [],
56
+ data: {
57
+ __text: '',
58
+ __style: '',
59
+ __className: '',
60
+ __animData: null // 动画数据
61
+ },
62
+ lifetimes: {
63
+ attached() {
64
+ // 组件初始化
65
+ },
66
+ detached() {
67
+ // 清理工作
68
+ }
69
+ },
70
+ methods: {
71
+ /**
72
+ * 事件处理器
73
+ */
74
+ __handleTiggerEvent(eventName, e) {
75
+ // 触发自定义事件,让外部可以监听
76
+ this.triggerEvent(eventName, e, {
77
+ // bubbles: true,
78
+ composed: true
79
+ });
80
+ },
81
+ /**
82
+ * 创建 IntersectionObserver
83
+ */
84
+ createIntersectionObserver(options) {
85
+ try {
86
+ // @ts-ignore
87
+ if (typeof ty !== 'undefined' && ty.createIntersectionObserver) {
88
+ return ty.createIntersectionObserver(this, options);
89
+ }
90
+ } catch (e) {
91
+ console.error('createIntersectionObserver error:', e);
92
+ }
93
+ return null;
94
+ },
95
+ /**
96
+ * 获取小程序的 createAnimation 方法
97
+ */
98
+ _getCreateAnimation() {
99
+ try {
100
+ // @ts-ignore
101
+ if (typeof ty !== 'undefined' && ty.createAnimation) {
102
+ return ty.createAnimation;
103
+ }
104
+ } catch (e) {
105
+ // ignore
106
+ }
107
+ return null;
108
+ },
109
+ setCustomStyle(value) {
110
+ // 防止传入 undefined 或 null 导致小程序报错
111
+ if (value === undefined || value === null) {
112
+ console.warn('[TyAnimatedComponent] setCustomStyle: value is undefined or null, ignored');
113
+ return;
114
+ }
115
+ this.setData({
116
+ __style: value,
117
+ customStyle: value
118
+ });
119
+ },
120
+ /**
121
+ * 设置文本内容(__mode='text' 时使用)
122
+ */
123
+ __applyText(text) {
124
+ if (typeof text === 'string') {
125
+ this.setData({
126
+ __text: text
127
+ });
128
+ }
129
+ },
130
+ /**
131
+ * 核心方法:直接应用 Animation 对象
132
+ * @param {Function} fn - 接收 Animation 实例的回调函数
133
+ * @param {Object} options - 动画选项,包括 transformOrigin
134
+ *
135
+ * 使用示例:
136
+ * comp.__apply((anim) => {
137
+ * anim.opacity(0.5).scale(0.8).step();
138
+ * return anim.export();
139
+ * }, { transformOrigin: 'top left' });
140
+ */
141
+ __apply(fn) {
142
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
143
+ const createAnimation = this._getCreateAnimation();
144
+ if (!createAnimation) {
145
+ return;
146
+ }
147
+ const anim = createAnimation(options);
148
+
149
+ // 执行用户的动画配置
150
+ const exported = fn(anim);
151
+
152
+ // 应用动画数据
153
+ const animData = exported || anim.export();
154
+ this.setData({
155
+ __animData: animData
156
+ });
157
+ },
158
+ // 核心触摸事件处理(只保留最常用的)
159
+ __onClick(e) {
160
+ this.__handleTiggerEvent('click', e);
161
+ },
162
+ __onTouchStart(e) {
163
+ this.__handleTiggerEvent('touchstart', e);
164
+ },
165
+ __onTouchEnd(e) {
166
+ this.__handleTiggerEvent('touchend', e);
167
+ }
168
+ }
169
+ });
170
+ export default 'ty-animated-component';
@@ -0,0 +1,4 @@
1
+ {
2
+ "component": true,
3
+ "usingComponents": {}
4
+ }
@@ -0,0 +1,26 @@
1
+ <block>
2
+ <view
3
+ wx:if="{{__mode==='view'}}"
4
+ id="root"
5
+ class="container {{__className}} {{customClass}}"
6
+ style="{{__style}};{{customStyle}}"
7
+ animation="{{__animData}}"
8
+ bindtap="__onClick"
9
+ bindtouchstart="__onTouchStart"
10
+ bindtouchend="__onTouchEnd"
11
+ >
12
+ <slot></slot>
13
+ </view>
14
+ <text
15
+ wx:else
16
+ id="rootText"
17
+ class="container {{__className}} {{customClass}}"
18
+ style="{{__style}};{{customStyle}}"
19
+ animation="{{__animData}}"
20
+ bindtap="__onClick"
21
+ bindtouchstart="__onTouchStart"
22
+ bindtouchend="__onTouchEnd"
23
+ >{{__text}}</text>
24
+ </block>
25
+
26
+
@@ -0,0 +1,3 @@
1
+ .container { display: block; }
2
+
3
+
@@ -0,0 +1,277 @@
1
+ import type React from 'react';
2
+ /**
3
+ * 触摸事件处理器(只保留核心事件)
4
+ *
5
+ * 注:只提供最常用的三个事件(onClick, onTouchStart, onTouchEnd)
6
+ * 如需其他事件(如 onLongPress, onTouchMove 等),请在 Animated 的子元素上直接绑定
7
+ */
8
+ export interface TouchEventHandler {
9
+ onClick?: (e: TouchEvent) => any;
10
+ onTouchStart?: (e: TouchEvent) => any;
11
+ onTouchEnd?: (e: TouchEvent) => any;
12
+ }
13
+ interface TargetType {
14
+ id: string;
15
+ offsetLeft: number;
16
+ offsetTop: number;
17
+ paths: any;
18
+ uid: any;
19
+ dataset: {
20
+ [key: string]: any;
21
+ };
22
+ }
23
+ export interface EventType {
24
+ type: string;
25
+ target: TargetType;
26
+ currentTarget: TargetType;
27
+ timestamp: number;
28
+ stopPropagation: () => void;
29
+ detail: any;
30
+ }
31
+ export type timing = 'linear' | 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'step-start' | 'step-end';
32
+ export type TOptions = {
33
+ duration?: number;
34
+ timingFunction?: timing;
35
+ delay?: number;
36
+ transformOrigin?: string;
37
+ };
38
+ /**
39
+ * 元素边界信息
40
+ */
41
+ export interface BoundingClientRect {
42
+ /** 元素的 ID */
43
+ id: string;
44
+ /** dataset 数据 */
45
+ dataset: Record<string, any>;
46
+ /** 左边界坐标 */
47
+ left: number;
48
+ /** 右边界坐标 */
49
+ right: number;
50
+ /** 上边界坐标 */
51
+ top: number;
52
+ /** 下边界坐标 */
53
+ bottom: number;
54
+ /** 元素宽度 */
55
+ width: number;
56
+ /** 元素高度 */
57
+ height: number;
58
+ }
59
+ /**
60
+ * 元素查询字段配置
61
+ */
62
+ export interface NodeFields {
63
+ /** 是否返回节点 id */
64
+ id?: boolean;
65
+ /** 是否返回节点 dataset */
66
+ dataset?: boolean;
67
+ /** 是否返回节点布局位置(left right top bottom) */
68
+ rect?: boolean;
69
+ /** 是否返回节点尺寸(width height) */
70
+ size?: boolean;
71
+ /** 是否返回节点的 scrollLeft scrollTop */
72
+ scrollOffset?: boolean;
73
+ /** 指定属性名列表,返回节点对应属性名的当前属性值 */
74
+ properties?: string[];
75
+ /** 指定样式名列表,返回节点对应样式名的当前值 */
76
+ computedStyle?: string[];
77
+ /** 是否返回节点对应的 Node 实例 */
78
+ node?: boolean;
79
+ }
80
+ /**
81
+ * Animated.View 组件的 Ref 类型(不包含 setText)
82
+ *
83
+ * @example
84
+ * ```tsx
85
+ * import { useRef } from 'react'
86
+ * import Animated, { type AnimatedViewRef } from '@/components/animated'
87
+ *
88
+ * const boxRef = useRef<AnimatedViewRef>(null)
89
+ * boxRef.current?.setStyle({ opacity: 0.5 })
90
+ * boxRef.current?.animate((anim) => {
91
+ * anim.translateX(100).step({ duration: 300 })
92
+ * })
93
+ * ```
94
+ */
95
+ export interface AnimatedViewRef {
96
+ /**
97
+ * 直接设置样式(无动画)
98
+ *
99
+ * @param style - 样式对象或 CSS 字符串
100
+ *
101
+ * @example
102
+ * ```tsx
103
+ * ref.current?.setStyle({ opacity: 0.5, color: 'red' })
104
+ * ref.current?.setStyle('transform: translateX(100px);')
105
+ * ```
106
+ */
107
+ setStyle: (style: React.CSSProperties | string) => void;
108
+ /**
109
+ * 使用小程序原生动画 API
110
+ * 这是性能最优的动画方式
111
+ *
112
+ * @param callback - 动画配置回调,接收小程序动画对象
113
+ * @param options - 动画选项
114
+ *
115
+ * @example
116
+ * ```tsx
117
+ * // 单个动画
118
+ * ref.current?.animate((anim) => {
119
+ * anim.translateX(100).scale(1.2).step({ duration: 300, timingFunction: 'ease-out' })
120
+ * })
121
+ *
122
+ * // 序列动画
123
+ * ref.current?.animate((anim) => {
124
+ * anim.translateX(100).step({ duration: 300 })
125
+ * anim.scale(1.2).step({ duration: 200 })
126
+ * anim.rotate(360).step({ duration: 500 })
127
+ * })
128
+ *
129
+ * // 设置 transformOrigin
130
+ * ref.current?.animate((anim) => {
131
+ * anim.scaleX(0.5).step({ duration: 300 })
132
+ * }, { transformOrigin: 'left center' })
133
+ * ```
134
+ */
135
+ animate: (callback: (anim: IAnimation) => any, options?: TOptions & {
136
+ finish: (event: EventType) => void;
137
+ }) => void;
138
+ /**
139
+ * 获取元素的布局位置和尺寸信息
140
+ * 基于小程序 SelectorQuery.boundingClientRect API
141
+ *
142
+ * @returns Promise<BoundingClientRect | null>
143
+ *
144
+ * @example
145
+ * ```tsx
146
+ * const rect = await boxRef.current?.getBoundingClientRect()
147
+ * console.log(rect?.left, rect?.top, rect?.width, rect?.height)
148
+ *
149
+ * // 使用位置信息实现动画
150
+ * if (rect) {
151
+ * const centerX = window.innerWidth / 2 - rect.left - rect.width / 2
152
+ * const centerY = window.innerHeight / 2 - rect.top - rect.height / 2
153
+ * boxRef.current?.animate((anim) => {
154
+ * anim.translateX(centerX).translateY(centerY).scale(2).step({ duration: 300 })
155
+ * })
156
+ * }
157
+ * ```
158
+ */
159
+ getBoundingClientRect: () => Promise<BoundingClientRect | null>;
160
+ /**
161
+ * 获取元素的详细信息(包括样式、属性等)
162
+ * 基于小程序 SelectorQuery.fields API
163
+ *
164
+ * @param fields - 查询字段配置
165
+ * @returns Promise<any>
166
+ *
167
+ * @example
168
+ * ```tsx
169
+ * // 获取元素的位置和计算后的样式
170
+ * const info = await boxRef.current?.getFields({
171
+ * rect: true,
172
+ * size: true,
173
+ * computedStyle: ['backgroundColor', 'transform']
174
+ * })
175
+ * console.log(info?.backgroundColor, info?.transform)
176
+ * ```
177
+ */
178
+ getFields: (fields: NodeFields) => Promise<any>;
179
+ /**
180
+ * 获取元素的计算后样式(computed style)
181
+ * 这是一个便捷方法,内部调用 getFields
182
+ *
183
+ * 使用注意事项:
184
+ * 1. width/height 限制:通过 CSS 自动布局的元素,width/height 通常返回 'auto'
185
+ * - 错误用法:用 getComputedStyle 获取实际像素尺寸
186
+ * - 正确用法:使用 getBoundingClientRect() 获取实际尺寸
187
+ *
188
+ * 2. 内联样式限制:通过 React style 属性设置的样式可能无法查询
189
+ * - 原因:小程序查询的是最终渲染的 CSS,不是 JS 设置的内联样式
190
+ *
191
+ * 3. 适用场景:
192
+ * - 查询 transform 动画状态(动画执行中)
193
+ * - 查询 opacity 等动画属性
194
+ * - 查询通过 CSS 类设置的样式
195
+ * - 查询元素实际尺寸(用 getBoundingClientRect)
196
+ * - 查询通过 style={{ }} 设置的背景色等
197
+ *
198
+ * @param styleNames - 样式名称数组
199
+ * @returns Promise<Record<string, any> | null> - 返回样式对象
200
+ *
201
+ * @example
202
+ * ```tsx
203
+ * // 正确示例:查询动画相关样式
204
+ * const styles = await boxRef.current?.getComputedStyle([
205
+ * 'transform',
206
+ * 'opacity'
207
+ * ])
208
+ *
209
+ * console.log(styles?.transform) // 'matrix(1.5, 0, 0, 1.5, 100, 50)'
210
+ * console.log(styles?.opacity) // '0.8'
211
+ *
212
+ * // 根据当前 transform 决定下一步动画
213
+ * if (styles?.transform !== 'none') {
214
+ * // 当前有 transform,恢复原位
215
+ * boxRef.current?.animate((anim) => {
216
+ * anim.translateX(0).translateY(0).scale(1).step({ duration: 300 })
217
+ * })
218
+ * }
219
+ *
220
+ * // 错误示例:查询尺寸
221
+ * const styles = await boxRef.current?.getComputedStyle(['width', 'height'])
222
+ * console.log(styles?.width) // 可能返回 'auto',不是实际像素值
223
+ *
224
+ * // 正确做法:使用 getBoundingClientRect
225
+ * const rect = await boxRef.current?.getBoundingClientRect()
226
+ * console.log(rect?.width) // 335 (实际像素值)
227
+ * ```
228
+ */
229
+ getComputedStyle: (styleNames: string[]) => Promise<Record<string, any> | null>;
230
+ }
231
+ /**
232
+ * Animated.Text 组件的 Ref 类型(包含 setText)
233
+ *
234
+ * @example
235
+ * ```tsx
236
+ * import { useRef } from 'react'
237
+ * import Animated, { type AnimatedTextRef } from '@/components/animated'
238
+ *
239
+ * const textRef = useRef<AnimatedTextRef>(null)
240
+ * textRef.current?.setText('新文本')
241
+ * textRef.current?.animate((anim) => {
242
+ * anim.opacity(0.5).step({ duration: 300 })
243
+ * })
244
+ * ```
245
+ */
246
+ export interface AnimatedTextRef extends AnimatedViewRef {
247
+ /**
248
+ * 直接设置文本内容(仅 Animated.Text 可用)
249
+ * 直接操作底层组件,不触发 React 重渲染
250
+ *
251
+ * @param text - 文本内容
252
+ *
253
+ * @example
254
+ * ```tsx
255
+ * <Animated.Text ref={textRef}>0</Animated.Text>
256
+ * // 更新文本
257
+ * textRef.current?.setText('100')
258
+ * ```
259
+ */
260
+ setText: (text: string) => void;
261
+ }
262
+ /**
263
+ * Animated 组件 Props
264
+ */
265
+ export interface AnimatedProps extends TouchEventHandler {
266
+ children?: React.ReactNode;
267
+ className?: string;
268
+ style?: React.CSSProperties;
269
+ id?: string;
270
+ /** 组件模式:'view' 为容器模式(默认),'text' 为文本模式 */
271
+ mode?: 'view' | 'text';
272
+ /** 动画开始回调 */
273
+ onAnimationStart?: () => void;
274
+ /** 动画结束回调 */
275
+ onAnimationEnd?: () => void;
276
+ }
277
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,4 @@
1
1
  import React from 'react';
2
2
  import { ScrollViewProps } from '@ray-js/adapter';
3
- declare const ScrollView: React.FC<ScrollViewProps>;
3
+ declare const ScrollView: React.ForwardRefExoticComponent<ScrollViewProps & React.RefAttributes<any>>;
4
4
  export default ScrollView;
@@ -6,7 +6,7 @@ import React from 'react';
6
6
  import { useEventListener } from 'ahooks';
7
7
  import { ScrollView as ScrollViewDef } from '@ray-js/adapter';
8
8
  import handleProps from '../utils/handleProps';
9
- const ScrollView = props => {
9
+ const ScrollView = /*#__PURE__*/React.forwardRef((props, ref) => {
10
10
  const {
11
11
  onScroll,
12
12
  onScrollToUpper,
@@ -14,6 +14,9 @@ const ScrollView = props => {
14
14
  } = props,
15
15
  restProps = _objectWithoutProperties(props, _excluded);
16
16
  const currentNode = React.useRef(null);
17
+
18
+ // 使用传入的 ref 或内部的 ref
19
+ const scrollRef = ref || currentNode;
17
20
  useEventListener('scroll', e => {
18
21
  onScroll === null || onScroll === void 0 || onScroll(_objectSpread(_objectSpread(_objectSpread({}, e), {}, {
19
22
  type: 'scroll'
@@ -21,7 +24,7 @@ const ScrollView = props => {
21
24
  origin: e
22
25
  }));
23
26
  }, {
24
- target: currentNode
27
+ target: scrollRef
25
28
  });
26
29
  useEventListener('scrolltoupper', e => {
27
30
  onScrollToUpper === null || onScrollToUpper === void 0 || onScrollToUpper(_objectSpread(_objectSpread(_objectSpread({}, e), {}, {
@@ -30,7 +33,7 @@ const ScrollView = props => {
30
33
  origin: e
31
34
  }));
32
35
  }, {
33
- target: currentNode
36
+ target: scrollRef
34
37
  });
35
38
  useEventListener('scrolltolower', e => {
36
39
  onScrollToLower === null || onScrollToLower === void 0 || onScrollToLower(_objectSpread(_objectSpread(_objectSpread({}, e), {}, {
@@ -39,15 +42,15 @@ const ScrollView = props => {
39
42
  origin: e
40
43
  }));
41
44
  }, {
42
- target: currentNode
45
+ target: scrollRef
43
46
  });
44
47
  return (
45
48
  /*#__PURE__*/
46
49
  // @ts-ignore
47
50
  React.createElement("v-scroll-view", _extends({}, handleProps(restProps), {
48
- ref: currentNode
51
+ ref: scrollRef
49
52
  }), props.children)
50
53
  );
51
- };
54
+ });
52
55
  ScrollView.defaultProps = ScrollViewDef.defaultProps;
53
56
  export default ScrollView;
@@ -1,4 +1,4 @@
1
1
  import * as React from 'react';
2
2
  import type { ScrollViewProps } from '@ray-js/adapter';
3
- declare const ScrollView: React.FC<ScrollViewProps>;
3
+ declare const ScrollView: React.ForwardRefExoticComponent<ScrollViewProps & React.RefAttributes<any>>;
4
4
  export default ScrollView;
@@ -4,13 +4,16 @@ const _excluded = ["style"];
4
4
  import * as React from 'react';
5
5
  import { inlineStyle } from '@ray-js/framework-shared';
6
6
  import { ScrollView as RemaxScrollView } from '@ray-js/adapter';
7
- const ScrollView = props => {
7
+ const ScrollView = /*#__PURE__*/React.forwardRef((props, ref) => {
8
8
  const {
9
9
  style
10
10
  } = props,
11
11
  restProps = _objectWithoutProperties(props, _excluded);
12
+ // @ts-ignore - RemaxScrollView 支持 ref,但类型定义可能不完整
12
13
  return /*#__PURE__*/React.createElement(RemaxScrollView, _extends({
14
+ ref: ref,
13
15
  style: inlineStyle(style)
14
16
  }, restProps));
15
- };
17
+ });
18
+ ScrollView.displayName = 'ScrollView';
16
19
  export default ScrollView;
package/lib/index.d.ts CHANGED
@@ -33,3 +33,5 @@ export { default as Iframe } from './Iframe';
33
33
  export { default as Modal } from './Modal';
34
34
  export { default as Video } from './Video';
35
35
  export { default as SvgRender } from './SvgRender';
36
+ export { default as Animated } from './Animated';
37
+ export type { AnimatedViewRef, AnimatedTextRef, AnimatedProps } from './Animated';
package/lib/index.js CHANGED
@@ -32,4 +32,5 @@ export { default as Progress } from './Progress';
32
32
  export { default as Iframe } from './Iframe';
33
33
  export { default as Modal } from './Modal';
34
34
  export { default as Video } from './Video';
35
- export { default as SvgRender } from './SvgRender';
35
+ export { default as SvgRender } from './SvgRender';
36
+ export { default as Animated } from './Animated';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/components",
3
- "version": "1.7.55",
3
+ "version": "1.7.56-beta.1",
4
4
  "description": "Ray basic components",
5
5
  "keywords": [
6
6
  "ray"
@@ -29,8 +29,8 @@
29
29
  "dependencies": {
30
30
  "@ray-core/macro": "^0.4.9",
31
31
  "@ray-core/wechat": "^0.4.9",
32
- "@ray-js/adapter": "1.7.55",
33
- "@ray-js/framework-shared": "1.7.55",
32
+ "@ray-js/adapter": "1.7.56-beta.1",
33
+ "@ray-js/framework-shared": "1.7.56-beta.1",
34
34
  "ahooks": "^3.8.5",
35
35
  "clsx": "^1.2.1",
36
36
  "core-js": "^3.43.0",
@@ -40,11 +40,11 @@
40
40
  "style-to-object": "^0.3.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@ray-js/cli": "1.7.55"
43
+ "@ray-js/cli": "1.7.56-beta.1"
44
44
  },
45
45
  "publishConfig": {
46
46
  "access": "public",
47
47
  "registry": "https://registry.npmjs.org"
48
48
  },
49
- "gitHead": "99c603c95b6dc57833bd51784cf28c93a4d36b96"
49
+ "gitHead": "e1d99bcbd08502ade11590cf19ea8c3d01f41cbb"
50
50
  }