@ray-js/components 1.7.56-beta.3 → 1.7.56

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/lib/index.d.ts CHANGED
@@ -33,5 +33,3 @@ 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,5 +32,4 @@ 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';
36
- export { default as Animated } from './Animated';
35
+ export { default as SvgRender } from './SvgRender';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/components",
3
- "version": "1.7.56-beta.3",
3
+ "version": "1.7.56",
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.56-beta.3",
33
- "@ray-js/framework-shared": "1.7.56-beta.3",
32
+ "@ray-js/adapter": "1.7.56",
33
+ "@ray-js/framework-shared": "1.7.56",
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.56-beta.3"
43
+ "@ray-js/cli": "1.7.56"
44
44
  },
45
45
  "publishConfig": {
46
46
  "access": "public",
47
47
  "registry": "https://registry.npmjs.org"
48
48
  },
49
- "gitHead": "fdf56468c021ff48a0f36d027dcb9408533ef3ba"
49
+ "gitHead": "1cea5f9cd86e0fcf170de355449135ed3773cc3d"
50
50
  }
@@ -1,47 +0,0 @@
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
- }
@@ -1,21 +0,0 @@
1
- /**
2
- * Animated - 纯净底层动画组件
3
- *
4
- * 只提供三个核心方法:
5
- * - setProperty(property, value): 设置动画属性
6
- * - setStyle(style): 设置样式
7
- * - setText(text): 设置文本内容
8
- *
9
- * 可以配合任何动画库使用(GSAP、Anime.js、Framer Motion 等)
10
- */
11
- import React from 'react';
12
- import type { AnimatedViewRef, AnimatedTextRef, AnimatedProps } from './types';
13
- /**
14
- * 默认导出
15
- */
16
- declare const Animated: {
17
- View: React.ForwardRefExoticComponent<Omit<AnimatedProps, "mode"> & React.RefAttributes<AnimatedViewRef>>;
18
- Text: React.ForwardRefExoticComponent<Omit<AnimatedProps, "mode"> & React.RefAttributes<AnimatedTextRef>>;
19
- };
20
- export default Animated;
21
- export type { AnimatedViewRef, AnimatedTextRef, AnimatedProps } from './types';
@@ -1,297 +0,0 @@
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 = finish;
140
- } else {
141
- // 如果没有传 finish 参数,清空之前的回调
142
- // 避免 duration: 0 的重置动画再次触发之前的 finish
143
- callbackRef.current = null;
144
- }
145
- (_inst$__apply = inst.__apply) === null || _inst$__apply === void 0 || _inst$__apply.call(inst, callback, option);
146
- },
147
- /**
148
- * 获取元素的布局位置和尺寸信息
149
- * 基于小程序 SelectorQuery.boundingClientRect API
150
- */
151
- getBoundingClientRect() {
152
- return new Promise(resolve => {
153
- try {
154
- // 检查小程序 API 是否存在
155
- if (typeof ty === 'undefined' || !ty.createSelectorQuery) {
156
- console.error('[Animated] getBoundingClientRect: ty.createSelectorQuery 不存在');
157
- resolve(null);
158
- return;
159
- }
160
- const query = ty.createSelectorQuery();
161
- query.select("#".concat(componentIdRef.current)).boundingClientRect(rect => {
162
- resolve(rect || null);
163
- }).exec();
164
- } catch (error) {
165
- console.error('[Animated] getBoundingClientRect 执行失败:', error);
166
- resolve(null);
167
- }
168
- });
169
- },
170
- /**
171
- * 获取元素的详细信息(包括样式、属性等)
172
- * 基于小程序 SelectorQuery.fields API
173
- */
174
- getFields(fields) {
175
- return new Promise(resolve => {
176
- try {
177
- // 检查小程序 API 是否存在
178
- if (typeof ty === 'undefined' || !ty.createSelectorQuery) {
179
- console.error('[Animated] getFields: ty.createSelectorQuery 不存在');
180
- resolve(null);
181
- return;
182
- }
183
- const query = ty.createSelectorQuery();
184
- query.select("#".concat(componentIdRef.current)).fields(fields, res => {
185
- resolve(res || null);
186
- }).exec();
187
- } catch (error) {
188
- console.error('[Animated] getFields 执行失败:', error);
189
- resolve(null);
190
- }
191
- });
192
- },
193
- /**
194
- * 获取元素的计算后样式
195
- * 便捷方法,专门用于查询样式
196
- */
197
- getComputedStyle(styleNames) {
198
- return new Promise(resolve => {
199
- try {
200
- // 检查小程序 API 是否存在
201
- if (typeof ty === 'undefined' || !ty.createSelectorQuery) {
202
- console.error('[Animated] getComputedStyle: ty.createSelectorQuery 不存在');
203
- resolve(null);
204
- return;
205
- }
206
- const query = ty.createSelectorQuery();
207
- query.select("#".concat(componentIdRef.current)).fields({
208
- computedStyle: styleNames
209
- }, res => {
210
- if (!res) {
211
- resolve(null);
212
- return;
213
- }
214
-
215
- // 提取样式信息,过滤掉非样式字段
216
- const styles = {};
217
- styleNames.forEach(styleName => {
218
- if (res[styleName] !== undefined) {
219
- styles[styleName] = res[styleName];
220
- }
221
- });
222
- resolve(Object.keys(styles).length > 0 ? styles : null);
223
- }).exec();
224
- } catch (error) {
225
- console.error('[Animated] getComputedStyle 执行失败:', error);
226
- resolve(null);
227
- }
228
- });
229
- }
230
- };
231
- }, []);
232
-
233
- // 处理 customStyle,避免传入 undefined
234
- const customStyleValue = useMemo(() => {
235
- if (!style) return undefined;
236
- return typeof style === 'object' ? styleToString(style) : style;
237
- }, []);
238
- const handleAnimationEnd = useCallback(event => {
239
- if (callbackRef.current && typeof callbackRef.current === 'function') {
240
- const temp = callbackRef.current;
241
- callbackRef.current = null;
242
- temp(event);
243
- }
244
- if (onAnimationEnd) {
245
- onAnimationEnd();
246
- }
247
- }, [onAnimationEnd, callbackRef.current]);
248
- const eventBindings = {};
249
- if (onClick) eventBindings['bind:click'] = onClick;
250
- if (onTouchStart) eventBindings['bind:touchstart'] = onTouchStart;
251
- if (onTouchEnd) eventBindings['bind:touchend'] = onTouchEnd;
252
- if (onAnimationStart) eventBindings['bind:animationbegin'] = onAnimationStart;
253
- eventBindings['bind:animationfinish'] = handleAnimationEnd;
254
- return (
255
- /*#__PURE__*/
256
- // @ts-ignore - 小程序自定义组件
257
- React.createElement(TyAnimatedComponent, _extends({
258
- id: componentIdRef.current,
259
- __mode: mode,
260
- customClass: className
261
- }, customStyleValue ? {
262
- customStyle: customStyleValue
263
- } : {}, mode === 'text' && textContent !== undefined ? {
264
- __text: textContent
265
- } : {}, eventBindings), mode === 'view' ? children : null)
266
- );
267
- });
268
- AnimatedBase.displayName = 'AnimatedBase';
269
-
270
- /**
271
- * Animated.View 组件(不包含 setText)
272
- */
273
- const AnimatedView = /*#__PURE__*/forwardRef((props, ref) => /*#__PURE__*/React.createElement(AnimatedBase, _extends({}, props, {
274
- mode: "view",
275
- ref: ref
276
- })));
277
- AnimatedView.displayName = 'Animated.View';
278
-
279
- /**
280
- * Animated.Text 组件(包含 setText)
281
- */
282
- const AnimatedText = /*#__PURE__*/forwardRef((props, ref) => /*#__PURE__*/React.createElement(AnimatedBase, _extends({}, props, {
283
- mode: "text",
284
- ref: ref
285
- })));
286
- AnimatedText.displayName = 'Animated.Text';
287
-
288
- /**
289
- * 默认导出
290
- */
291
- const Animated = {
292
- View: AnimatedView,
293
- Text: AnimatedText
294
- };
295
- export default Animated;
296
-
297
- // 导出类型
@@ -1,5 +0,0 @@
1
- import * as React from 'react';
2
- declare const TyAnimated: React.ComponentType<any>;
3
- export default TyAnimated;
4
-
5
-
@@ -1,226 +0,0 @@
1
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import "core-js/modules/es.string.trim.js";
3
- import "core-js/modules/esnext.iterator.constructor.js";
4
- import "core-js/modules/esnext.iterator.filter.js";
5
- import "core-js/modules/esnext.iterator.map.js";
6
- import "core-js/modules/web.dom-collections.iterator.js";
7
- // @ts-nocheck
8
- /**
9
- * TyAnimated - 高性能动画组件(小程序原生层)
10
- */
11
-
12
- // 小程序原生组件注册
13
- Component({
14
- properties: {
15
- __mode: {
16
- type: String,
17
- value: 'view'
18
- },
19
- __text: {
20
- type: String,
21
- value: ''
22
- },
23
- __style: {
24
- type: String,
25
- value: ''
26
- },
27
- __className: {
28
- type: String,
29
- value: ''
30
- },
31
- // 兼容 FastView 接口
32
- customStyle: {
33
- type: String,
34
- value: ''
35
- },
36
- customClass: {
37
- type: String,
38
- value: '',
39
- observer: function (v) {
40
- this.setData({
41
- __className: v
42
- });
43
- }
44
- },
45
- onAnimationStart: {
46
- type: null,
47
- value: null
48
- },
49
- // 动画结束回调函数
50
- onAnimationEnd: {
51
- type: null,
52
- value: null
53
- }
54
- },
55
- // 定义外部事件
56
- externalClasses: [],
57
- data: {
58
- __text: '',
59
- __style: '',
60
- __className: '',
61
- __animData: null // 动画数据
62
- },
63
- lifetimes: {
64
- attached() {
65
- // 组件初始化:将 customStyle 的初始值复制到 __style
66
- const initialStyle = this.properties.customStyle || '';
67
- if (initialStyle) {
68
- this.setData({
69
- __style: initialStyle
70
- });
71
- }
72
- },
73
- detached() {
74
- // 清理工作
75
- }
76
- },
77
- methods: {
78
- /**
79
- * 事件处理器
80
- */
81
- __handleTiggerEvent(eventName, e) {
82
- // 触发自定义事件,让外部可以监听
83
- this.triggerEvent(eventName, e, {
84
- // bubbles: true,
85
- composed: true
86
- });
87
- },
88
- /**
89
- * 创建 IntersectionObserver
90
- */
91
- createIntersectionObserver(options) {
92
- try {
93
- // @ts-ignore
94
- if (typeof ty !== 'undefined' && ty.createIntersectionObserver) {
95
- return ty.createIntersectionObserver(this, options);
96
- }
97
- } catch (e) {
98
- console.error('createIntersectionObserver error:', e);
99
- }
100
- return null;
101
- },
102
- /**
103
- * 获取小程序的 createAnimation 方法
104
- */
105
- _getCreateAnimation() {
106
- try {
107
- // @ts-ignore
108
- if (typeof ty !== 'undefined' && ty.createAnimation) {
109
- return ty.createAnimation;
110
- }
111
- } catch (e) {
112
- // ignore
113
- }
114
- return null;
115
- },
116
- /**
117
- * 解析样式字符串为对象
118
- */
119
- _parseStyle(styleString) {
120
- if (!styleString) return {};
121
- const result = {};
122
- const styles = styleString.split(';').filter(Boolean);
123
- for (const style of styles) {
124
- const colonIndex = style.indexOf(':');
125
- if (colonIndex > 0) {
126
- const key = style.substring(0, colonIndex).trim();
127
- const value = style.substring(colonIndex + 1).trim();
128
- if (key && value) {
129
- result[key] = value;
130
- }
131
- }
132
- }
133
- return result;
134
- },
135
- /**
136
- * 样式对象转字符串
137
- */
138
- _styleToString(styleObj) {
139
- return Object.entries(styleObj).map(_ref => {
140
- let [key, value] = _ref;
141
- return "".concat(key, ":").concat(value);
142
- }).join(';');
143
- },
144
- setCustomStyle(value) {
145
- // 防止传入 undefined 或 null 导致小程序报错
146
- if (value === undefined || value === null) {
147
- console.warn('[TyAnimatedComponent] setCustomStyle: value is undefined or null, ignored');
148
- return;
149
- }
150
-
151
- // 1. 合并样式
152
- const currentStyle = this._parseStyle(this.data.__style || '');
153
- const newStyle = this._parseStyle(value);
154
- const mergedStyle = _objectSpread(_objectSpread({}, currentStyle), newStyle);
155
- const mergedStyleString = this._styleToString(mergedStyle);
156
- if (mergedStyleString === this.data.__style && this.data.__animData !== null) {
157
- console.log('[TyAnimated] 值相同且有动画数据,强制刷新');
158
-
159
- // 先清空样式和动画数据
160
- this.setData({
161
- __style: '',
162
- __animData: null
163
- }, () => {
164
- // 再设置目标样式
165
- this.setData({
166
- __style: mergedStyleString
167
- });
168
- });
169
- return;
170
- }
171
- this.setData({
172
- __style: mergedStyleString,
173
- __animData: null
174
- });
175
- },
176
- /**
177
- * 设置文本内容(__mode='text' 时使用)
178
- */
179
- __applyText(text) {
180
- if (typeof text === 'string') {
181
- this.setData({
182
- __text: text
183
- });
184
- }
185
- },
186
- /**
187
- * 核心方法:直接应用 Animation 对象
188
- * @param {Function} fn - 接收 Animation 实例的回调函数
189
- * @param {Object} options - 动画选项,包括 transformOrigin
190
- *
191
- * 使用示例:
192
- * comp.__apply((anim) => {
193
- * anim.opacity(0.5).scale(0.8).step();
194
- * return anim.export();
195
- * }, { transformOrigin: 'top left' });
196
- */
197
- __apply(fn) {
198
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
199
- const createAnimation = this._getCreateAnimation();
200
- if (!createAnimation) {
201
- return;
202
- }
203
- const anim = createAnimation(options);
204
-
205
- // 执行用户的动画配置
206
- const exported = fn(anim);
207
-
208
- // 应用动画数据
209
- const animData = exported || anim.export();
210
- this.setData({
211
- __animData: animData
212
- });
213
- },
214
- // 核心触摸事件处理(只保留最常用的)
215
- __onClick(e) {
216
- this.__handleTiggerEvent('click', e);
217
- },
218
- __onTouchStart(e) {
219
- this.__handleTiggerEvent('touchstart', e);
220
- },
221
- __onTouchEnd(e) {
222
- this.__handleTiggerEvent('touchend', e);
223
- }
224
- }
225
- });
226
- export default 'ty-animated-component';
@@ -1,4 +0,0 @@
1
- {
2
- "component": true,
3
- "usingComponents": {}
4
- }
@@ -1,26 +0,0 @@
1
- <block>
2
- <view
3
- wx:if="{{__mode==='view'}}"
4
- id="root"
5
- class="container {{__className}}"
6
- style="{{__style}}"
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}}"
18
- style="{{__style}}"
19
- animation="{{__animData}}"
20
- bindtap="__onClick"
21
- bindtouchstart="__onTouchStart"
22
- bindtouchend="__onTouchEnd"
23
- >{{__text}}</text>
24
- </block>
25
-
26
-
@@ -1,3 +0,0 @@
1
- .container { display: block; }
2
-
3
-
@@ -1,277 +0,0 @@
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 {};
@@ -1 +0,0 @@
1
- export {};