vant 4.3.1 → 4.4.0

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.
Files changed (113) hide show
  1. package/es/address-edit/AddressEdit.mjs +1 -0
  2. package/es/area/Area.d.ts +6 -8
  3. package/es/area/Area.mjs +1 -1
  4. package/es/area/index.d.ts +4 -6
  5. package/es/back-top/BackTop.d.ts +1 -1
  6. package/es/back-top/BackTop.mjs +6 -3
  7. package/es/back-top/index.css +1 -1
  8. package/es/back-top/index.d.ts +1 -1
  9. package/es/barrage/Barrage.d.ts +93 -0
  10. package/es/barrage/Barrage.mjs +134 -0
  11. package/es/barrage/index.css +1 -0
  12. package/es/barrage/index.d.ts +69 -0
  13. package/es/barrage/index.mjs +10 -0
  14. package/es/barrage/style/index.d.ts +1 -0
  15. package/es/barrage/style/index.mjs +2 -0
  16. package/es/barrage/types.d.ts +7 -0
  17. package/es/barrage/types.mjs +0 -0
  18. package/es/cascader/Cascader.mjs +14 -0
  19. package/es/checkbox/Checker.d.ts +2 -0
  20. package/es/checkbox/Checker.mjs +13 -1
  21. package/es/contact-list/ContactList.mjs +1 -1
  22. package/es/contact-list/index.css +1 -1
  23. package/es/date-picker/DatePicker.mjs +5 -2
  24. package/es/date-picker/utils.d.ts +1 -1
  25. package/es/dialog/index.css +1 -1
  26. package/es/divider/Divider.d.ts +4 -0
  27. package/es/divider/Divider.mjs +4 -2
  28. package/es/divider/index.css +1 -1
  29. package/es/divider/index.d.ts +3 -0
  30. package/es/field/Field.mjs +4 -0
  31. package/es/image-preview/ImagePreviewItem.mjs +60 -26
  32. package/es/index.d.ts +2 -1
  33. package/es/index.mjs +4 -1
  34. package/es/notice-bar/NoticeBar.d.ts +1 -1
  35. package/es/notice-bar/index.d.ts +1 -1
  36. package/es/picker-group/PickerGroup.d.ts +15 -1
  37. package/es/picker-group/PickerGroup.mjs +8 -6
  38. package/es/picker-group/index.d.ts +11 -1
  39. package/es/signature/Signature.d.ts +13 -0
  40. package/es/signature/Signature.mjs +24 -8
  41. package/es/signature/index.css +1 -1
  42. package/es/signature/index.d.ts +9 -0
  43. package/es/step/index.css +1 -1
  44. package/es/submit-bar/index.css +1 -1
  45. package/es/tabs/Tabs.mjs +8 -2
  46. package/es/tabs/utils.d.ts +2 -2
  47. package/es/tabs/utils.mjs +14 -4
  48. package/es/uploader/Uploader.d.ts +6 -1
  49. package/es/uploader/Uploader.mjs +25 -10
  50. package/es/uploader/UploaderPreviewItem.d.ts +5 -1
  51. package/es/uploader/UploaderPreviewItem.mjs +6 -3
  52. package/es/uploader/index.d.ts +5 -1
  53. package/es/uploader/types.d.ts +1 -0
  54. package/lib/address-edit/AddressEdit.js +1 -0
  55. package/lib/area/Area.d.ts +6 -8
  56. package/lib/area/Area.js +1 -1
  57. package/lib/area/index.d.ts +4 -6
  58. package/lib/back-top/BackTop.d.ts +1 -1
  59. package/lib/back-top/BackTop.js +6 -3
  60. package/lib/back-top/index.css +1 -1
  61. package/lib/back-top/index.d.ts +1 -1
  62. package/lib/barrage/Barrage.d.ts +93 -0
  63. package/lib/barrage/Barrage.js +153 -0
  64. package/lib/barrage/index.css +1 -0
  65. package/lib/barrage/index.d.ts +69 -0
  66. package/lib/barrage/index.js +39 -0
  67. package/lib/barrage/style/index.d.ts +1 -0
  68. package/lib/barrage/style/index.js +2 -0
  69. package/lib/barrage/types.d.ts +7 -0
  70. package/lib/barrage/types.js +15 -0
  71. package/lib/cascader/Cascader.js +14 -0
  72. package/lib/checkbox/Checker.d.ts +2 -0
  73. package/lib/checkbox/Checker.js +13 -1
  74. package/lib/contact-list/ContactList.js +1 -1
  75. package/lib/contact-list/index.css +1 -1
  76. package/lib/date-picker/DatePicker.js +5 -2
  77. package/lib/date-picker/utils.d.ts +1 -1
  78. package/lib/dialog/index.css +1 -1
  79. package/lib/divider/Divider.d.ts +4 -0
  80. package/lib/divider/Divider.js +4 -2
  81. package/lib/divider/index.css +1 -1
  82. package/lib/divider/index.d.ts +3 -0
  83. package/lib/field/Field.js +4 -0
  84. package/lib/image-preview/ImagePreviewItem.js +59 -25
  85. package/lib/index.css +1 -1
  86. package/lib/index.d.ts +2 -1
  87. package/lib/index.js +4 -1
  88. package/lib/notice-bar/NoticeBar.d.ts +1 -1
  89. package/lib/notice-bar/index.d.ts +1 -1
  90. package/lib/picker-group/PickerGroup.d.ts +15 -1
  91. package/lib/picker-group/PickerGroup.js +6 -4
  92. package/lib/picker-group/index.d.ts +11 -1
  93. package/lib/signature/Signature.d.ts +13 -0
  94. package/lib/signature/Signature.js +23 -7
  95. package/lib/signature/index.css +1 -1
  96. package/lib/signature/index.d.ts +9 -0
  97. package/lib/step/index.css +1 -1
  98. package/lib/submit-bar/index.css +1 -1
  99. package/lib/tabs/Tabs.js +8 -2
  100. package/lib/tabs/utils.d.ts +2 -2
  101. package/lib/tabs/utils.js +13 -3
  102. package/lib/uploader/Uploader.d.ts +6 -1
  103. package/lib/uploader/Uploader.js +25 -10
  104. package/lib/uploader/UploaderPreviewItem.d.ts +5 -1
  105. package/lib/uploader/UploaderPreviewItem.js +6 -3
  106. package/lib/uploader/index.d.ts +5 -1
  107. package/lib/uploader/types.d.ts +1 -0
  108. package/lib/vant.cjs.js +611 -358
  109. package/lib/vant.es.js +612 -359
  110. package/lib/vant.js +611 -358
  111. package/lib/vant.min.js +1 -1
  112. package/lib/web-types.json +1 -1
  113. package/package.json +1 -1
@@ -29,7 +29,12 @@ var import_image = require("../image");
29
29
  var import_loading = require("../loading");
30
30
  var import_swipe_item = require("../swipe-item");
31
31
  const getDistance = (touches) => Math.sqrt((touches[0].clientX - touches[1].clientX) ** 2 + (touches[0].clientY - touches[1].clientY) ** 2);
32
+ const getCenter = (touches) => ({
33
+ x: (touches[0].clientX + touches[1].clientX) / 2,
34
+ y: (touches[0].clientY + touches[1].clientY) / 2
35
+ });
32
36
  const bem = (0, import_utils.createNamespace)("image-preview")[1];
37
+ const longImageRatio = 2.6;
33
38
  var stdin_default = (0, import_vue2.defineComponent)({
34
39
  props: {
35
40
  src: String,
@@ -52,20 +57,14 @@ var stdin_default = (0, import_vue2.defineComponent)({
52
57
  moveY: 0,
53
58
  moving: false,
54
59
  zooming: false,
55
- imageRatio: 0,
56
- displayWidth: 0,
57
- displayHeight: 0
60
+ imageRatio: 0
58
61
  });
59
62
  const touch = (0, import_use_touch.useTouch)();
63
+ const imageRef = (0, import_vue2.ref)();
60
64
  const swipeItem = (0, import_vue2.ref)();
61
- const vertical = (0, import_vue2.computed)(() => {
62
- const {
63
- rootWidth,
64
- rootHeight
65
- } = props;
66
- const rootRatio = rootHeight / rootWidth;
67
- return state.imageRatio > rootRatio;
68
- });
65
+ const vertical = (0, import_vue2.ref)(false);
66
+ const isLongImage = (0, import_vue2.ref)(false);
67
+ let initialMoveY = 0;
69
68
  const imageStyle = (0, import_vue2.computed)(() => {
70
69
  const {
71
70
  scale,
@@ -77,10 +76,8 @@ var stdin_default = (0, import_vue2.defineComponent)({
77
76
  const style = {
78
77
  transitionDuration: zooming || moving ? "0s" : ".3s"
79
78
  };
80
- if (scale !== 1) {
81
- const offsetX = moveX / scale;
82
- const offsetY = moveY / scale;
83
- style.transform = `scale(${scale}, ${scale}) translate(${offsetX}px, ${offsetY}px)`;
79
+ if (scale !== 1 || isLongImage.value) {
80
+ style.transform = `matrix(${scale}, 0, 0, ${scale}, ${moveX}, ${moveY})`;
84
81
  }
85
82
  return style;
86
83
  });
@@ -106,10 +103,26 @@ var stdin_default = (0, import_vue2.defineComponent)({
106
103
  }
107
104
  return 0;
108
105
  });
109
- const setScale = (scale) => {
106
+ const setScale = (scale, center) => {
107
+ var _a;
110
108
  scale = (0, import_utils.clamp)(scale, +props.minZoom, +props.maxZoom + 1);
111
109
  if (scale !== state.scale) {
110
+ const ratio = scale / state.scale;
112
111
  state.scale = scale;
112
+ if (center) {
113
+ const imageRect = (0, import_use.useRect)((_a = imageRef.value) == null ? void 0 : _a.$el);
114
+ const origin = {
115
+ x: imageRect.width * 0.5,
116
+ y: imageRect.height * 0.5
117
+ };
118
+ const moveX = state.moveX - (center.x - imageRect.left - origin.x) * (ratio - 1);
119
+ const moveY = state.moveY - (center.y - imageRect.top - origin.y) * (ratio - 1);
120
+ state.moveX = (0, import_utils.clamp)(moveX, -maxMoveX.value, maxMoveX.value);
121
+ state.moveY = (0, import_utils.clamp)(moveY, -maxMoveY.value, maxMoveY.value);
122
+ } else {
123
+ state.moveX = 0;
124
+ state.moveY = isLongImage.value ? initialMoveY : 0;
125
+ }
113
126
  emit("scale", {
114
127
  scale,
115
128
  index: props.active
@@ -118,20 +131,20 @@ var stdin_default = (0, import_vue2.defineComponent)({
118
131
  };
119
132
  const resetScale = () => {
120
133
  setScale(1);
121
- state.moveX = 0;
122
- state.moveY = 0;
123
134
  };
124
135
  const toggleScale = () => {
125
136
  const scale = state.scale > 1 ? 1 : 2;
126
- setScale(scale);
127
- state.moveX = 0;
128
- state.moveY = 0;
137
+ setScale(scale, scale === 2 || isLongImage.value ? {
138
+ x: touch.startX.value,
139
+ y: touch.startY.value
140
+ } : void 0);
129
141
  };
130
142
  let fingerNum;
131
143
  let startMoveX;
132
144
  let startMoveY;
133
145
  let startScale;
134
146
  let startDistance;
147
+ let lastCenter;
135
148
  let doubleTapTimer;
136
149
  let touchStartTime;
137
150
  let isImageMoved = false;
@@ -151,11 +164,11 @@ var stdin_default = (0, import_vue2.defineComponent)({
151
164
  startMoveY = state.moveY;
152
165
  touchStartTime = Date.now();
153
166
  isImageMoved = false;
154
- state.moving = fingerNum === 1 && state.scale !== 1;
167
+ state.moving = fingerNum === 1 && (state.scale !== 1 || isLongImage.value);
155
168
  state.zooming = fingerNum === 2 && !offsetX.value;
156
169
  if (state.zooming) {
157
170
  startScale = state.scale;
158
- startDistance = getDistance(event.touches);
171
+ startDistance = getDistance(touches);
159
172
  }
160
173
  };
161
174
  const onTouchMove = (event) => {
@@ -184,7 +197,8 @@ var stdin_default = (0, import_vue2.defineComponent)({
184
197
  if (touches.length === 2) {
185
198
  const distance = getDistance(touches);
186
199
  const scale = startScale * distance / startDistance;
187
- setScale(scale);
200
+ lastCenter = getCenter(touches);
201
+ setScale(scale, lastCenter);
188
202
  }
189
203
  }
190
204
  };
@@ -238,7 +252,7 @@ var stdin_default = (0, import_vue2.defineComponent)({
238
252
  }
239
253
  const maxZoom = +props.maxZoom;
240
254
  if (state.scale > maxZoom) {
241
- state.scale = maxZoom;
255
+ setScale(maxZoom, lastCenter);
242
256
  }
243
257
  }
244
258
  }
@@ -246,12 +260,30 @@ var stdin_default = (0, import_vue2.defineComponent)({
246
260
  checkTap();
247
261
  touch.reset();
248
262
  };
263
+ const resize = () => {
264
+ const {
265
+ rootWidth,
266
+ rootHeight
267
+ } = props;
268
+ const rootRatio = rootHeight / rootWidth;
269
+ const {
270
+ imageRatio
271
+ } = state;
272
+ vertical.value = state.imageRatio > rootRatio && imageRatio < longImageRatio;
273
+ isLongImage.value = state.imageRatio > rootRatio && imageRatio >= longImageRatio;
274
+ if (isLongImage.value) {
275
+ initialMoveY = (imageRatio * rootWidth - rootHeight) / 2;
276
+ state.moveY = initialMoveY;
277
+ }
278
+ resetScale();
279
+ };
249
280
  const onLoad = (event) => {
250
281
  const {
251
282
  naturalWidth,
252
283
  naturalHeight
253
284
  } = event.target;
254
285
  state.imageRatio = naturalHeight / naturalWidth;
286
+ resize();
255
287
  };
256
288
  (0, import_vue2.watch)(() => props.active, resetScale);
257
289
  (0, import_vue2.watch)(() => props.show, (value) => {
@@ -259,6 +291,7 @@ var stdin_default = (0, import_vue2.defineComponent)({
259
291
  resetScale();
260
292
  }
261
293
  });
294
+ (0, import_vue2.watch)(() => [props.rootWidth, props.rootHeight], resize);
262
295
  (0, import_use.useEventListener)("touchmove", onTouchMove, {
263
296
  target: (0, import_vue2.computed)(() => {
264
297
  var _a;
@@ -283,6 +316,7 @@ var stdin_default = (0, import_vue2.defineComponent)({
283
316
  }, [slots.image({
284
317
  src: props.src
285
318
  })]) : (0, import_vue.createVNode)(import_image.Image, {
319
+ "ref": imageRef,
286
320
  "src": props.src,
287
321
  "fit": "contain",
288
322
  "class": bem("image", {