@tarojs/runtime 3.6.6-alpha.0 → 3.6.6-alpha.2

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.
@@ -18,7 +18,7 @@ export declare class History extends Events {
18
18
  #private;
19
19
  constructor(location: LocationType.Location, options: Options);
20
20
  get length(): number;
21
- get state(): HistoryState;
21
+ get state(): Record<string, any> | null;
22
22
  go(delta: number): void;
23
23
  back(): void;
24
24
  forward(): void;
@@ -1,14 +1,16 @@
1
1
  import type { TaroElement } from './element';
2
- export declare class ClassList extends Set<string> {
2
+ export declare class ClassList {
3
3
  private el;
4
+ private tokenList;
4
5
  constructor(className: string, el: TaroElement);
5
6
  get value(): string;
6
- add(s: string): this;
7
7
  get length(): number;
8
- remove(s: string): void;
9
- toggle(s: string): void;
10
- replace(s1: string, s2: string): void;
11
- contains(s: string): boolean;
8
+ add(): void;
9
+ remove(): void;
10
+ contains(token: string): boolean;
11
+ toggle(token: string, force: boolean): boolean;
12
+ replace(token: string, replacement_token: string): void;
12
13
  toString(): string;
14
+ private checkTokenIsValid;
13
15
  private _update;
14
16
  }
@@ -65,6 +65,8 @@ export interface PageInstance extends PageLifeCycle {
65
65
  path?: string;
66
66
  /** 页面的组件选项 */
67
67
  options?: Record<string, unknown>;
68
+ /** 页面渲染引擎类型 */
69
+ renderer?: 'webview' | 'skyline';
68
70
  }
69
71
  interface Show {
70
72
  componentDidShow?(): void;
@@ -6,17 +6,19 @@ import { Component as Vue3Component } from "@vue/runtime-core";
6
6
  import { Component, ComponentClass } from "react";
7
7
  import { CombinedVueInstance } from "vue/types/vue";
8
8
  declare let document: any;
9
- declare class ClassList extends Set<string> {
9
+ declare class ClassList {
10
10
  private el;
11
+ private tokenList;
11
12
  constructor(className: string, el: TaroElement);
12
13
  get value(): string;
13
- add(s: string): this;
14
14
  get length(): number;
15
- remove(s: string): void;
16
- toggle(s: string): void;
17
- replace(s1: string, s2: string): void;
18
- contains(s: string): boolean;
15
+ add(): void;
16
+ remove(): void;
17
+ contains(token: string): boolean;
18
+ toggle(token: string, force: boolean): boolean;
19
+ replace(token: string, replacement_token: string): void;
19
20
  toString(): string;
21
+ private checkTokenIsValid;
20
22
  private _update;
21
23
  }
22
24
  interface Attributes {
@@ -405,7 +407,7 @@ declare class History extends Events {
405
407
  constructor(location: LocationType.Location, options: Options$0);
406
408
  /* public property */
407
409
  get length(): number;
408
- get state(): HistoryState;
410
+ get state(): Record<string, any> | null;
409
411
  /* public method */
410
412
  go(delta: number): void;
411
413
  back(): void;
@@ -639,6 +641,8 @@ interface PageInstance extends PageLifeCycle {
639
641
  path?: string;
640
642
  /** 页面的组件选项 */
641
643
  options?: Record<string, unknown>;
644
+ /** 页面渲染引擎类型 */
645
+ renderer?: "webview" | "skyline";
642
646
  }
643
647
  interface Show {
644
648
  componentDidShow?(): void;
@@ -283,46 +283,90 @@ function getComponentsAlias() {
283
283
  return componentsAlias$1;
284
284
  }
285
285
 
286
- class ClassList extends Set {
286
+ class ClassList {
287
287
  constructor(className, el) {
288
- super();
289
- className.trim().split(/\s+/).forEach(super.add.bind(this));
288
+ this.tokenList = [];
290
289
  this.el = el;
290
+ className.trim().split(/\s+/).forEach(token => this.tokenList.push(token));
291
291
  }
292
292
  get value() {
293
- return [...this].filter(v => v !== '').join(' ');
294
- }
295
- add(s) {
296
- super.add(s);
297
- this._update();
298
- return this;
293
+ return this.toString();
299
294
  }
300
295
  get length() {
301
- return this.size;
296
+ return this.tokenList.length;
297
+ }
298
+ add() {
299
+ let index = 0;
300
+ let updated = false;
301
+ const tokens = arguments;
302
+ const length = tokens.length;
303
+ const tokenList = this.tokenList;
304
+ do {
305
+ const token = tokens[index];
306
+ if (this.checkTokenIsValid(token) && !~tokenList.indexOf(token)) {
307
+ tokenList.push(token);
308
+ updated = true;
309
+ }
310
+ } while (++index < length);
311
+ if (updated) {
312
+ this._update();
313
+ }
314
+ }
315
+ remove() {
316
+ let i = 0;
317
+ let updated = false;
318
+ const tokens = arguments;
319
+ const length = tokens.length;
320
+ const tokenList = this.tokenList;
321
+ do {
322
+ const token = tokens[i] + '';
323
+ if (!this.checkTokenIsValid(token))
324
+ continue;
325
+ const index = tokenList.indexOf(token);
326
+ if (~tokenList.indexOf(token)) {
327
+ tokenList.splice(index, 1);
328
+ updated = true;
329
+ }
330
+ } while (++i < length);
331
+ if (updated) {
332
+ this._update();
333
+ }
302
334
  }
303
- remove(s) {
304
- super.delete(s);
305
- this._update();
335
+ contains(token) {
336
+ if (!this.checkTokenIsValid(token))
337
+ return false;
338
+ return !!~this.tokenList.indexOf(token);
306
339
  }
307
- toggle(s) {
308
- if (super.has(s)) {
309
- super.delete(s);
340
+ toggle(token, force) {
341
+ const result = this.contains(token);
342
+ const method = result ? force !== true && 'remove' : force !== false && 'add';
343
+ if (method) {
344
+ // @ts-ignore
345
+ this[method](token);
346
+ }
347
+ if (force === true || force === false) {
348
+ return force;
310
349
  }
311
350
  else {
312
- super.add(s);
351
+ return !result;
313
352
  }
314
- this._update();
315
- }
316
- replace(s1, s2) {
317
- super.delete(s1);
318
- super.add(s2);
319
- this._update();
320
353
  }
321
- contains(s) {
322
- return super.has(s);
354
+ replace(token, replacement_token) {
355
+ if (!this.checkTokenIsValid(token) || !this.checkTokenIsValid(replacement_token))
356
+ return;
357
+ const index = this.tokenList.indexOf(token);
358
+ if (~index) {
359
+ this.tokenList.splice(index, 1, replacement_token);
360
+ this._update();
361
+ }
323
362
  }
324
363
  toString() {
325
- return this.value;
364
+ return this.tokenList.filter(v => v !== '').join(' ');
365
+ }
366
+ checkTokenIsValid(token) {
367
+ if (token === '' || /\s/.test(token))
368
+ return false;
369
+ return true;
326
370
  }
327
371
  _update() {
328
372
  this.el.className = this.value;
@@ -803,7 +847,8 @@ const styleProperties = [
803
847
  'widows',
804
848
  'width',
805
849
  'zIndex',
806
- 'pointerEvents'
850
+ 'pointerEvents',
851
+ 'aspectRatio'
807
852
  /** 非常用 style */
808
853
  // 'azimuth',
809
854
  // 'backfaceVisibility',
@@ -971,10 +1016,12 @@ function setStyle(newVal, styleKey) {
971
1016
  }
972
1017
  !this._pending && enqueueUpdate(this);
973
1018
  }
974
- function initStyle(ctor) {
1019
+ function initStyle(ctor, styleProperties) {
975
1020
  const properties = {};
976
1021
  for (let i = 0; i < styleProperties.length; i++) {
977
1022
  const styleKey = styleProperties[i];
1023
+ if (ctor[styleKey])
1024
+ return;
978
1025
  properties[styleKey] = {
979
1026
  get() {
980
1027
  const val = this._value[styleKey];
@@ -1085,7 +1132,17 @@ class Style {
1085
1132
  return value;
1086
1133
  }
1087
1134
  }
1088
- initStyle(Style);
1135
+ initStyle(Style, styleProperties);
1136
+ hooks.tap('injectNewStyleProperties', (newStyleProperties) => {
1137
+ if (isArray(newStyleProperties)) {
1138
+ initStyle(Style, newStyleProperties);
1139
+ }
1140
+ else {
1141
+ if (typeof newStyleProperties !== 'string')
1142
+ return;
1143
+ initStyle(Style, [newStyleProperties]);
1144
+ }
1145
+ });
1089
1146
 
1090
1147
  function returnTrue() {
1091
1148
  return true;
@@ -1104,7 +1161,9 @@ function treeToArray(root, predict) {
1104
1161
  }
1105
1162
  function following(el, root) {
1106
1163
  const firstChild = el.firstChild;
1107
- if (firstChild) {
1164
+ const isElmentTypeValid = el.nodeType === 1 /* NodeType.ELEMENT_NODE */ || el.nodeType === 9 /* NodeType.DOCUMENT_NODE */;
1165
+ // 如果当前 el 不是 element 或 document 元素,则可以直接不递归他的子元素了
1166
+ if (firstChild && isElmentTypeValid) {
1108
1167
  return firstChild;
1109
1168
  }
1110
1169
  let current = el;
@@ -1345,10 +1404,10 @@ class TaroElement extends TaroNode {
1345
1404
  });
1346
1405
  }
1347
1406
  getElementsByClassName(className) {
1407
+ const classNames = className.trim().split(/\s+/);
1348
1408
  return treeToArray(this, (el) => {
1349
1409
  const classList = el.classList;
1350
- const classNames = className.trim().split(/\s+/);
1351
- return classNames.every(c => classList.has(c));
1410
+ return classNames.every(c => classList.contains(c));
1352
1411
  });
1353
1412
  }
1354
1413
  dispatchEvent(event) {
@@ -3333,7 +3392,7 @@ class History extends Events {
3333
3392
  return __classPrivateFieldGet(this, _History_stack, "f").length;
3334
3393
  }
3335
3394
  get state() {
3336
- return __classPrivateFieldGet(this, _History_stack, "f")[__classPrivateFieldGet(this, _History_cur, "f")];
3395
+ return __classPrivateFieldGet(this, _History_stack, "f")[__classPrivateFieldGet(this, _History_cur, "f")].state;
3337
3396
  }
3338
3397
  /* public method */
3339
3398
  go(delta) {