@tarojs/taro-h5 3.4.0 → 3.4.3

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 (49) hide show
  1. package/dist/api/ai/visual.js +2 -0
  2. package/dist/api/base/system.js +187 -0
  3. package/dist/api/canvas/CanvasContext.js +1 -1
  4. package/dist/api/canvas/index.js +5 -1
  5. package/dist/api/cloud/index.js +4 -0
  6. package/dist/api/device/battery.js +18 -1
  7. package/dist/api/device/index.js +1 -0
  8. package/dist/api/{base/system → device}/network.js +29 -14
  9. package/dist/api/device/wifi.js +1 -0
  10. package/dist/api/media/{editor.js → EditorContext.js} +1 -0
  11. package/dist/api/media/audio/InnerAudioContext.js +84 -0
  12. package/dist/api/media/audio/index.js +1 -74
  13. package/dist/api/media/background-audio/BackgroundAudioManager.js +86 -0
  14. package/dist/api/media/{background-audio.js → background-audio/index.js} +6 -2
  15. package/dist/api/media/index.js +0 -1
  16. package/dist/api/network/upload.js +2 -7
  17. package/dist/api/ui/animation/index.js +9 -5
  18. package/dist/api/ui/fonts.js +50 -2
  19. package/dist/api/ui/scroll/index.js +3 -3
  20. package/dist/api/utils/handler.js +45 -45
  21. package/dist/api/utils/index.js +36 -12
  22. package/dist/index.cjs.js +517 -188
  23. package/dist/taroApis.js +1 -1
  24. package/package.json +7 -7
  25. package/src/api/ai/visual.ts +3 -0
  26. package/src/api/base/system.ts +207 -0
  27. package/src/api/canvas/CanvasContext.ts +7 -7
  28. package/src/api/canvas/index.ts +10 -2
  29. package/src/api/cloud/index.ts +4 -0
  30. package/src/api/device/battery.ts +18 -1
  31. package/src/api/device/index.ts +1 -0
  32. package/src/api/{base/system → device}/network.ts +35 -15
  33. package/src/api/device/wifi.ts +1 -0
  34. package/src/api/media/{editor.ts → EditorContext.ts} +2 -0
  35. package/src/api/media/audio/InnerAudioContext.ts +98 -0
  36. package/src/api/media/audio/index.ts +1 -86
  37. package/src/api/media/background-audio/BackgroundAudioManager.ts +103 -0
  38. package/src/api/media/{background-audio.ts → background-audio/index.ts} +7 -2
  39. package/src/api/media/index.ts +0 -1
  40. package/src/api/network/upload.ts +2 -8
  41. package/src/api/ui/animation/index.ts +10 -6
  42. package/src/api/ui/fonts.ts +61 -2
  43. package/src/api/ui/scroll/index.ts +3 -3
  44. package/src/api/utils/handler.ts +4 -4
  45. package/src/api/utils/index.ts +33 -12
  46. package/dist/api/base/system/index.js +0 -2
  47. package/dist/api/base/system/info.js +0 -57
  48. package/src/api/base/system/index.ts +0 -2
  49. package/src/api/base/system/info.ts +0 -64
@@ -1,7 +1,6 @@
1
- import { temporarilyNotSupport } from '../utils';
2
1
  import { CallbackManager } from '../utils/handler';
3
2
  import { convertObjectUrlToBlob, NETWORK_TIMEOUT, setHeader, XHR_STATS } from './utils';
4
- const createUploadTask = ({ url, filePath, formData, name, header, timeout, fileName, success, error }) => {
3
+ const createUploadTask = ({ url, filePath, formData = {}, name, header, timeout, fileName, success, error }) => {
5
4
  let timeoutInter;
6
5
  let formKey;
7
6
  const apiName = 'uploadFile';
@@ -106,16 +105,12 @@ const createUploadTask = ({ url, filePath, formData, name, header, timeout, file
106
105
  * @param {ProgressUpdateCallback} callback HTTP Response Header 事件的回调函数
107
106
  */
108
107
  const offProgressUpdate = callbackManager.progressUpdate.remove;
109
- const headersReceived = temporarilyNotSupport('UploadTask.headersReceived');
110
- const progress = temporarilyNotSupport('UploadTask.progress');
111
108
  return {
112
109
  abort,
113
110
  onHeadersReceived,
114
111
  offHeadersReceived,
115
112
  onProgressUpdate,
116
- offProgressUpdate,
117
- headersReceived,
118
- progress
113
+ offProgressUpdate
119
114
  };
120
115
  };
121
116
  /**
@@ -4,12 +4,16 @@
4
4
  */
5
5
  class StyleSheet {
6
6
  constructor() {
7
+ this.$style = null;
8
+ this.sheet = null;
7
9
  this.appendStyleSheet = () => {
8
- var _a, _b, _c;
9
- (_a = this.$style) === null || _a === void 0 ? void 0 : _a.setAttribute('type', 'text/css');
10
- (_b = this.$style) === null || _b === void 0 ? void 0 : _b.setAttribute('data-type', 'Taro');
11
- document.getElementsByTagName('head')[0].appendChild(this.$style);
12
- this.sheet = (_c = this.$style) === null || _c === void 0 ? void 0 : _c.sheet;
10
+ if (this.$style) {
11
+ const head = document.getElementsByTagName('head')[0];
12
+ this.$style.setAttribute('type', 'text/css');
13
+ this.$style.setAttribute('data-type', 'Taro');
14
+ head.appendChild(this.$style);
15
+ this.sheet = this.$style.sheet;
16
+ }
13
17
  if (this.sheet && !('insertRule' in this.sheet)) {
14
18
  console.warn('当前浏览器不支持 stylesheet.insertRule 接口');
15
19
  }
@@ -1,3 +1,51 @@
1
- import { temporarilyNotSupport } from '../utils';
1
+ import { MethodHandler } from '../utils/handler';
2
2
  // 字体
3
- export const loadFontFace = temporarilyNotSupport('loadFontFace');
3
+ export const loadFontFace = async (options) => {
4
+ options = Object.assign({ global: false }, options);
5
+ const { success, fail, complete, family, source, desc = {} } = options;
6
+ const handle = new MethodHandler({ name: 'loadFontFace', success, fail, complete });
7
+ // @ts-ignore
8
+ const fonts = document.fonts;
9
+ if (fonts) {
10
+ // @ts-ignore
11
+ const fontFace = new FontFace(family, source, desc);
12
+ try {
13
+ await fontFace.load();
14
+ fonts.add(fontFace);
15
+ return handle.success({});
16
+ }
17
+ catch (error) {
18
+ return handle.fail({
19
+ errMsg: error.message || error
20
+ });
21
+ }
22
+ }
23
+ else {
24
+ const style = document.createElement('style');
25
+ let innerText = `font-family:"${family}";src:${source};font-style:${desc.style || 'normal'};font-weight:${desc.weight || 'normal'};font-variant:${desc.variant || 'normal'};`;
26
+ if (desc.ascentOverride) {
27
+ innerText += `ascent-override:${desc.ascentOverride};`;
28
+ }
29
+ if (desc.descentOverride) {
30
+ innerText += `descent-override:${desc.descentOverride};`;
31
+ }
32
+ if (desc.featureSettings) {
33
+ innerText += `font-feature-settings:${desc.featureSettings};`;
34
+ }
35
+ if (desc.lineGapOverride) {
36
+ innerText += `line-gap-override:${desc.lineGapOverride};`;
37
+ }
38
+ if (desc.stretch) {
39
+ innerText += `font-stretch:${desc.stretch};`;
40
+ }
41
+ if (desc.unicodeRange) {
42
+ innerText += `unicode-range:${desc.unicodeRange};`;
43
+ }
44
+ if (desc.variationSettings) {
45
+ innerText += `font-variation-settings:${desc.variationSettings};`;
46
+ }
47
+ style.innerText = `@font-face{${innerText}}`;
48
+ document.head.appendChild(style);
49
+ return handle.success();
50
+ }
51
+ };
@@ -10,16 +10,16 @@ export const pageScrollTo = ({ scrollTop, selector = '', duration = 300, success
10
10
  let scrollFunc;
11
11
  const handle = new MethodHandler({ name: 'pageScrollTo', success, fail, complete });
12
12
  return new Promise((resolve, reject) => {
13
- var _a;
13
+ var _a, _b;
14
14
  try {
15
15
  if (scrollTop === undefined && !selector) {
16
16
  return handle.fail({
17
17
  errMsg: 'scrollTop" 或 "selector" 需要其之一'
18
18
  }, reject);
19
19
  }
20
- const id = (_a = Current.page) === null || _a === void 0 ? void 0 : _a.path;
20
+ const id = (_b = (_a = Current.page) === null || _a === void 0 ? void 0 : _a.path) === null || _b === void 0 ? void 0 : _b.replace(/([^a-z0-9\u00a0-\uffff_-])/ig, '\\$1');
21
21
  const el = (id
22
- ? document.getElementById(id)
22
+ ? document.querySelector(`.taro_page#${id}`)
23
23
  : document.querySelector('.taro_page') ||
24
24
  document.querySelector('.taro_router'));
25
25
  if (!scrollFunc) {
@@ -29,52 +29,52 @@ export class MethodHandler {
29
29
  export class CallbackManager {
30
30
  constructor() {
31
31
  this.callbacks = [];
32
- }
33
- /**
34
- * 添加回调
35
- * @param {{ callback: function, ctx: any } | function} opt
36
- */
37
- add(opt) {
38
- if (opt)
39
- this.callbacks.push(opt);
40
- }
41
- /**
42
- * 移除回调
43
- * @param {{ callback: function, ctx: any } | function} opt
44
- */
45
- remove(opt) {
46
- if (opt) {
47
- let pos = -1;
48
- this.callbacks.forEach((callback, k) => {
49
- if (callback === opt) {
50
- pos = k;
32
+ /**
33
+ * 添加回调
34
+ * @param {{ callback: function, ctx: any } | function} opt
35
+ */
36
+ this.add = (opt) => {
37
+ if (opt)
38
+ this.callbacks.push(opt);
39
+ };
40
+ /**
41
+ * 移除回调
42
+ * @param {{ callback: function, ctx: any } | function} opt
43
+ */
44
+ this.remove = (opt) => {
45
+ if (opt) {
46
+ let pos = -1;
47
+ this.callbacks.forEach((callback, k) => {
48
+ if (callback === opt) {
49
+ pos = k;
50
+ }
51
+ });
52
+ if (pos > -1) {
53
+ this.callbacks.splice(pos, 1);
51
54
  }
52
- });
53
- if (pos > -1) {
54
- this.callbacks.splice(pos, 1);
55
55
  }
56
- }
57
- }
58
- /**
59
- * 获取回调函数数量
60
- * @return {number}
61
- */
62
- count() {
63
- return this.callbacks.length;
64
- }
65
- /**
66
- * 触发回调
67
- * @param {...any} args 回调的调用参数
68
- */
69
- trigger(...args) {
70
- this.callbacks.forEach(opt => {
71
- if (typeof opt === 'function') {
72
- opt(...args);
73
- }
74
- else {
75
- const { callback, ctx } = opt;
76
- typeof callback === 'function' && callback.call(ctx, ...args);
77
- }
78
- });
56
+ };
57
+ /**
58
+ * 获取回调函数数量
59
+ * @return {number}
60
+ */
61
+ this.count = () => {
62
+ return this.callbacks.length;
63
+ };
64
+ /**
65
+ * 触发回调
66
+ * @param {...any} args 回调的调用参数
67
+ */
68
+ this.trigger = (...args) => {
69
+ this.callbacks.forEach(opt => {
70
+ if (typeof opt === 'function') {
71
+ opt(...args);
72
+ }
73
+ else {
74
+ const { callback, ctx } = opt;
75
+ typeof callback === 'function' && callback.call(ctx, ...args);
76
+ }
77
+ });
78
+ };
79
79
  }
80
80
  }
@@ -74,28 +74,52 @@ export function serializeParams(params) {
74
74
  export function temporarilyNotSupport(apiName) {
75
75
  return () => {
76
76
  const errMsg = `暂时不支持 API ${apiName}`;
77
- console.error(errMsg);
78
- return Promise.reject({
79
- errMsg
80
- });
77
+ if (process.env.NODE_ENV !== 'production') {
78
+ console.error(errMsg);
79
+ return Promise.reject({
80
+ errMsg
81
+ });
82
+ }
83
+ else {
84
+ console.warn(errMsg);
85
+ return Promise.resolve({
86
+ errMsg
87
+ });
88
+ }
81
89
  };
82
90
  }
83
91
  export function weixinCorpSupport(apiName) {
84
92
  return () => {
85
93
  const errMsg = `h5端仅在微信公众号中支持 API ${apiName}`;
86
- console.error(errMsg);
87
- return Promise.reject({
88
- errMsg
89
- });
94
+ if (process.env.NODE_ENV !== 'production') {
95
+ console.error(errMsg);
96
+ return Promise.reject({
97
+ errMsg
98
+ });
99
+ }
100
+ else {
101
+ console.warn(errMsg);
102
+ return Promise.resolve({
103
+ errMsg
104
+ });
105
+ }
90
106
  };
91
107
  }
92
108
  export function permanentlyNotSupport(apiName) {
93
109
  return () => {
94
110
  const errMsg = `不支持 API ${apiName}`;
95
- console.error(errMsg);
96
- return Promise.reject({
97
- errMsg
98
- });
111
+ if (process.env.NODE_ENV !== 'production') {
112
+ console.error(errMsg);
113
+ return Promise.reject({
114
+ errMsg
115
+ });
116
+ }
117
+ else {
118
+ console.warn(errMsg);
119
+ return Promise.resolve({
120
+ errMsg
121
+ });
122
+ }
99
123
  };
100
124
  }
101
125
  export function isFunction(obj) {