@predy-js/render-interface 0.3.4-beta.14 → 0.3.4-beta.16

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/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * Name: @predy-js/render-interface
3
3
  * Description: undefined
4
4
  * Author: undefined
5
- * Version: v0.3.4-beta.14
5
+ * Version: v0.3.4-beta.16
6
6
  */
7
7
 
8
8
  'use strict';
@@ -197,6 +197,12 @@ var EVENT_TYPE_TOUCH_START = 'touchstart';
197
197
  var EVENT_TYPE_TOUCH_MOVE = 'touchmove';
198
198
  var EVENT_TYPE_TOUCH_END = 'touchend';
199
199
  var EVENT_TYPE_TOUCH_CANCEL = 'touchcancel';
200
+ exports.PredyNativeEventType = void 0;
201
+ (function (PredyNativeEventType) {
202
+ PredyNativeEventType[PredyNativeEventType["touchstart"] = 1] = "touchstart";
203
+ PredyNativeEventType[PredyNativeEventType["touchmove"] = 2] = "touchmove";
204
+ PredyNativeEventType[PredyNativeEventType["touchend"] = 3] = "touchend";
205
+ })(exports.PredyNativeEventType || (exports.PredyNativeEventType = {}));
200
206
  // // 扩展事件类型
201
207
  // export enum EVENT_TYPE {
202
208
  // // 基础事件
@@ -6039,15 +6045,17 @@ var WebHandler = /** @class */ (function () {
6039
6045
  };
6040
6046
  WebHandler.prototype.handleEvent = function (type, e) {
6041
6047
  e.preventDefault();
6042
- var np = this.getNormalizedPos(e);
6048
+ // const np = this.getNormalizedPos(e);
6049
+ var rect = e.target.getBoundingClientRect();
6043
6050
  var pointer = {
6044
6051
  id: e.pointerId,
6045
- x: np[0],
6046
- y: np[1],
6047
- clientX: e.clientX,
6048
- clientY: e.clientY,
6049
- force: 1,
6052
+ x: e.clientX - rect.left,
6053
+ y: e.clientY - rect.top,
6050
6054
  ts: this.timeStamp,
6055
+ layout: {
6056
+ width: rect.width,
6057
+ height: rect.height,
6058
+ },
6051
6059
  };
6052
6060
  // 更新触点集合
6053
6061
  if (type === EVENT_TYPE_TOUCH_END) {
@@ -6074,7 +6082,12 @@ var WebHandler = /** @class */ (function () {
6074
6082
 
6075
6083
  var RNHandler = /** @class */ (function () {
6076
6084
  function RNHandler(system) {
6085
+ var _this = this;
6077
6086
  this.system = system;
6087
+ this.handleTouch = function (e) {
6088
+ e.preventDefault();
6089
+ _this.system.handleBaseEvent(e);
6090
+ };
6078
6091
  this.timeOrigin = Date.now();
6079
6092
  }
6080
6093
  Object.defineProperty(RNHandler.prototype, "timeStamp", {
@@ -6085,10 +6098,16 @@ var RNHandler = /** @class */ (function () {
6085
6098
  configurable: true
6086
6099
  });
6087
6100
  RNHandler.prototype.setup = function () {
6088
- throw new Error('Method not implemented.');
6101
+ var target = this.system.target;
6102
+ target.addEventListener('touchstart', this.handleTouch);
6103
+ target.addEventListener('touchmove', this.handleTouch);
6104
+ target.addEventListener('touchend', this.handleTouch);
6089
6105
  };
6090
6106
  RNHandler.prototype.teardown = function () {
6091
- throw new Error('Method not implemented.');
6107
+ var target = this.system.target;
6108
+ target.removeEventListener('touchstart', this.handleTouch);
6109
+ target.removeEventListener('touchmove', this.handleTouch);
6110
+ target.removeEventListener('touchend', this.handleTouch);
6092
6111
  };
6093
6112
  return RNHandler;
6094
6113
  }());
@@ -6103,7 +6122,7 @@ var H5Handler = /** @class */ (function () {
6103
6122
  var event = {
6104
6123
  type: type,
6105
6124
  timestamp: _this.timeStamp,
6106
- target: e.target,
6125
+ // target: e.target,
6107
6126
  touches: _this.encapsulate(e.targetTouches),
6108
6127
  changedTouches: _this.encapsulate(e.changedTouches),
6109
6128
  preventDefault: function () { return e.preventDefault(); },
@@ -6149,15 +6168,17 @@ var H5Handler = /** @class */ (function () {
6149
6168
  var touches = [];
6150
6169
  for (var i = 0; i < list.length; i++) {
6151
6170
  var touch = list[i];
6152
- var _a = this.getNormalizedPos(touch), x = _a[0], y = _a[1];
6171
+ // const [x, y] = this.getNormalizedPos(touch);
6172
+ var rect = touch.target.getBoundingClientRect();
6153
6173
  touches.push({
6154
6174
  id: touch.identifier,
6155
- x: x,
6156
- y: y,
6157
- clientX: touch.clientX,
6158
- clientY: touch.clientY,
6159
- force: 1,
6175
+ x: touch.clientX - rect.left,
6176
+ y: touch.clientY - rect.top,
6160
6177
  ts: this.timeStamp,
6178
+ layout: {
6179
+ width: rect.width,
6180
+ height: rect.height,
6181
+ },
6161
6182
  });
6162
6183
  }
6163
6184
  return touches;
@@ -6215,7 +6236,7 @@ var UniversalRecognizer = /** @class */ (function () {
6215
6236
  this.gestureStartTime = event.timestamp;
6216
6237
  this.trackedTouches.clear();
6217
6238
  event.touches.forEach(function (t) { return _this.trackedTouches.set(t.id, t); });
6218
- this.startPositions = event.touches.map(function (t) { return [t.clientX, t.clientY]; });
6239
+ this.startPositions = event.touches.map(function (t) { return [t.x, t.y]; });
6219
6240
  // 初始化多指手势数据
6220
6241
  if (this.options.touchCount > 1) {
6221
6242
  this.initialCenter = this.calculateCenter(event.touches);
@@ -6227,16 +6248,26 @@ var UniversalRecognizer = /** @class */ (function () {
6227
6248
  if (![exports.RecognizerState.BEGAN, exports.RecognizerState.ACTIVE].includes(this.state)) {
6228
6249
  return;
6229
6250
  }
6230
- // 验证触点数量一致性
6231
- if (event.touches.length !== this.options.touchCount) {
6251
+ // 验证触点数量
6252
+ if (!this.validateTouchCount(event)) {
6232
6253
  this.reset();
6233
6254
  return;
6234
6255
  }
6235
- // 核心验证逻辑
6236
- if (!this.validateGesture(event)) {
6256
+ // 验证时间区间
6257
+ if (!this.validateDuration(event)) {
6237
6258
  this.handleFailure();
6238
6259
  return;
6239
6260
  }
6261
+ // 验证距离区间
6262
+ if (!this.validateDistance(event)) {
6263
+ return;
6264
+ }
6265
+ // 方向/路径验证
6266
+ if (this.options.direction !== undefined) {
6267
+ if (!this.validateDirection(event)) {
6268
+ return;
6269
+ }
6270
+ }
6240
6271
  // 更新状态为持续活动
6241
6272
  if (this.state === exports.RecognizerState.BEGAN) {
6242
6273
  this.setState(exports.RecognizerState.ACTIVE);
@@ -6248,9 +6279,8 @@ var UniversalRecognizer = /** @class */ (function () {
6248
6279
  if (![exports.RecognizerState.BEGAN, exports.RecognizerState.ACTIVE].includes(this.state)) {
6249
6280
  return;
6250
6281
  }
6251
- // 最终验证(例如点击的持续时间)
6252
- var isValid = this.validateFinalConditions(event);
6253
- if (isValid) {
6282
+ // 最终验证
6283
+ if (this.validateDuration(event)) {
6254
6284
  this.setState(exports.RecognizerState.END);
6255
6285
  if (this.validateThreshold(event)) {
6256
6286
  this.trigger(event);
@@ -6264,26 +6294,6 @@ var UniversalRecognizer = /** @class */ (function () {
6264
6294
  /**
6265
6295
  * 手势识别核心算法
6266
6296
  */
6267
- UniversalRecognizer.prototype.validateGesture = function (event) {
6268
- // 基础验证
6269
- if (!this.validateTouchCount(event)) {
6270
- return false;
6271
- }
6272
- if (!this.validateDuration(event)) {
6273
- return false;
6274
- }
6275
- if (!this.validateDistance(event)) {
6276
- return false;
6277
- }
6278
- // 方向/路径验证
6279
- if (this.options.direction !== undefined) {
6280
- if (!this.validateDirection(event)) {
6281
- return false;
6282
- }
6283
- }
6284
- // 高级手势验证
6285
- return true;
6286
- };
6287
6297
  UniversalRecognizer.prototype.validateTouchCount = function (event) {
6288
6298
  return event.touches.length === this.options.touchCount;
6289
6299
  };
@@ -6341,26 +6351,13 @@ var UniversalRecognizer = /** @class */ (function () {
6341
6351
  return true;
6342
6352
  }
6343
6353
  };
6344
- UniversalRecognizer.prototype.validateFinalConditions = function (event) {
6345
- // 验证时间区间
6346
- var duration = event.timestamp - this.gestureStartTime;
6347
- if (this.options.minDuration && duration < this.options.minDuration) {
6348
- return false;
6349
- }
6350
- if (this.options.maxDuration && duration > this.options.maxDuration) {
6351
- return false;
6352
- }
6353
- // 验证点击次数(需要外部状态管理)
6354
- // 此处需要结合外部计数器实现双击等逻辑
6355
- return true;
6356
- };
6357
6354
  UniversalRecognizer.prototype.calculateOverallDelta = function (event) {
6358
6355
  var _this = this;
6359
6356
  // 计算多点触控的平均移动量
6360
6357
  var totalDelta = [0, 0];
6361
6358
  event.touches.forEach(function (t, idx) {
6362
- totalDelta[0] += t.clientX - _this.startPositions[idx][0];
6363
- totalDelta[1] += t.clientY - _this.startPositions[idx][1];
6359
+ totalDelta[0] += t.x - _this.startPositions[idx][0];
6360
+ totalDelta[1] += t.y - _this.startPositions[idx][1];
6364
6361
  });
6365
6362
  return [totalDelta[0] / event.touches.length, totalDelta[1] / event.touches.length];
6366
6363
  };
@@ -6372,7 +6369,7 @@ var UniversalRecognizer = /** @class */ (function () {
6372
6369
  var currentCentroid = this.calculateCenter(touches);
6373
6370
  // 计算所有触点到中心点的平均距离
6374
6371
  var currentDistances = touches.map(function (t) {
6375
- return Math.hypot(t.clientX - currentCentroid[0], t.clientY - currentCentroid[1]);
6372
+ return Math.hypot(t.x - currentCentroid[0], t.y - currentCentroid[1]);
6376
6373
  });
6377
6374
  var currentAvgDistance = currentDistances.reduce(function (a, b) { return a + b; }) / touches.length;
6378
6375
  // 初始平均距离(从startPositions计算)
@@ -6391,7 +6388,7 @@ var UniversalRecognizer = /** @class */ (function () {
6391
6388
  var totalAngleChange = 0;
6392
6389
  touches.forEach(function (t, index) {
6393
6390
  // 当前触点角度
6394
- var currentAngle = Math.atan2(t.clientY - currentCentroid[1], t.clientX - currentCentroid[0]);
6391
+ var currentAngle = Math.atan2(t.y - currentCentroid[1], t.x - currentCentroid[0]);
6395
6392
  // 初始触点角度
6396
6393
  var initialPos = _this.startPositions[index];
6397
6394
  var initialAngle = Math.atan2(initialPos[1] - _this.initialCenter[1], initialPos[0] - _this.initialCenter[0]);
@@ -6412,14 +6409,14 @@ var UniversalRecognizer = /** @class */ (function () {
6412
6409
  UniversalRecognizer.prototype.calculateCenter = function (touchList) {
6413
6410
  var pointersLength = touchList.length;
6414
6411
  if (pointersLength === 1) {
6415
- return [touchList[0].clientX, touchList[0].clientY];
6412
+ return [touchList[0].x, touchList[0].y];
6416
6413
  }
6417
6414
  var x = 0;
6418
6415
  var y = 0;
6419
6416
  var i = 0;
6420
6417
  while (i < pointersLength) {
6421
- x += touchList[i].clientX;
6422
- y += touchList[i].clientY;
6418
+ x += touchList[i].x;
6419
+ y += touchList[i].y;
6423
6420
  i++;
6424
6421
  }
6425
6422
  return [x / pointersLength, y / pointersLength];
@@ -6603,7 +6600,7 @@ var BaseRecognizer = /** @class */ (function () {
6603
6600
  return BaseRecognizer;
6604
6601
  }());
6605
6602
 
6606
- consoleLog('version: ' + "0.3.4-beta.14");
6603
+ consoleLog('version: ' + "0.3.4-beta.16");
6607
6604
  var ModuleMsg = 'RI Package: @predy-js/render-interface';
6608
6605
 
6609
6606
  var RI = /*#__PURE__*/Object.freeze({
@@ -6646,6 +6643,7 @@ var RI = /*#__PURE__*/Object.freeze({
6646
6643
  EVENT_TYPE_TOUCH_MOVE: EVENT_TYPE_TOUCH_MOVE,
6647
6644
  EVENT_TYPE_TOUCH_END: EVENT_TYPE_TOUCH_END,
6648
6645
  EVENT_TYPE_TOUCH_CANCEL: EVENT_TYPE_TOUCH_CANCEL,
6646
+ get PredyNativeEventType () { return exports.PredyNativeEventType; },
6649
6647
  get GESTURE_DIRECTION () { return exports.GESTURE_DIRECTION; },
6650
6648
  get ShaderCompileResultStatus () { return exports.ShaderCompileResultStatus; },
6651
6649
  ShaderLibraryEmpty: ShaderLibraryEmpty