@tarojs/plugin-platform-harmony-ets 4.0.0-alpha.0 → 4.0.0-alpha.11

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 (139) hide show
  1. package/dist/apis/base/system.ts +73 -20
  2. package/dist/apis/canvas/index.ts +10 -1
  3. package/dist/apis/device/clipboard.ts +16 -8
  4. package/dist/apis/device/memory.ts +10 -3
  5. package/dist/apis/framework/index.ts +1 -5
  6. package/dist/apis/index.ts +27 -17
  7. package/dist/apis/media/image/index.ts +1 -1
  8. package/dist/apis/media/video/VideoContext.ts +56 -7
  9. package/dist/apis/media/video/index.ts +3 -2
  10. package/dist/apis/network/request.ts +5 -5
  11. package/dist/apis/route/index.ts +15 -0
  12. package/dist/apis/storage/index.ts +146 -78
  13. package/dist/apis/ui/animation/animation.ts +71 -29
  14. package/dist/apis/ui/background.ts +2 -1
  15. package/dist/apis/ui/interaction/index.ts +42 -59
  16. package/dist/apis/ui/navigation-bar/index.ts +1 -1
  17. package/dist/apis/ui/pull-down-refresh.ts +9 -3
  18. package/dist/apis/ui/scroll/index.ts +5 -5
  19. package/dist/apis/ui/tab-bar.ts +3 -3
  20. package/dist/apis/utils/index.ts +1 -1
  21. package/dist/apis/wxml/IntersectionObserver.ts +18 -10
  22. package/dist/apis/wxml/index.ts +2 -0
  23. package/dist/apis/wxml/selectorQuery.ts +26 -13
  24. package/dist/components-harmony-ets/button.ets +68 -68
  25. package/dist/components-harmony-ets/canvas.ets +51 -0
  26. package/dist/components-harmony-ets/checkbox.ets +81 -102
  27. package/dist/components-harmony-ets/form.ets +54 -45
  28. package/dist/components-harmony-ets/icon.ets +34 -50
  29. package/dist/components-harmony-ets/image.ets +35 -45
  30. package/dist/components-harmony-ets/index.ets +92 -0
  31. package/dist/components-harmony-ets/innerHtml.ets +11 -6
  32. package/dist/components-harmony-ets/input.ets +51 -67
  33. package/dist/components-harmony-ets/label.ets +73 -53
  34. package/dist/components-harmony-ets/listView.ets +26 -0
  35. package/dist/components-harmony-ets/movableArea.ets +124 -0
  36. package/dist/components-harmony-ets/movableView.ets +93 -0
  37. package/dist/components-harmony-ets/navigationBar.ets +65 -0
  38. package/dist/components-harmony-ets/pageMeta.ets +94 -0
  39. package/dist/components-harmony-ets/picker.ets +74 -77
  40. package/dist/components-harmony-ets/progress.ets +52 -0
  41. package/dist/components-harmony-ets/pseudo.ets +80 -0
  42. package/dist/components-harmony-ets/radio.ets +82 -104
  43. package/dist/components-harmony-ets/richText.ets +20 -68
  44. package/dist/components-harmony-ets/scrollList.ets +94 -0
  45. package/dist/components-harmony-ets/scrollView.ets +67 -103
  46. package/dist/components-harmony-ets/slider.ets +23 -47
  47. package/dist/components-harmony-ets/stickySection.ets +42 -0
  48. package/dist/components-harmony-ets/style.ets +396 -0
  49. package/dist/components-harmony-ets/swiper.ets +64 -53
  50. package/dist/components-harmony-ets/switch.ets +44 -55
  51. package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
  52. package/dist/components-harmony-ets/text.ets +134 -75
  53. package/dist/components-harmony-ets/textArea.ets +54 -62
  54. package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
  55. package/dist/components-harmony-ets/utils/DynamicCenter.ts +4 -13
  56. package/dist/components-harmony-ets/utils/flexManager.ets +76 -8
  57. package/dist/components-harmony-ets/utils/helper.ets +20 -7
  58. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  59. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  60. package/dist/components-harmony-ets/utils/index.ts +54 -50
  61. package/dist/components-harmony-ets/utils/styles.ets +178 -63
  62. package/dist/components-harmony-ets/video.ets +37 -54
  63. package/dist/components-harmony-ets/view.ets +63 -94
  64. package/dist/components-harmony-ets/webView.ets +56 -0
  65. package/dist/index.d.ts +152 -0
  66. package/dist/index.js +199 -58
  67. package/dist/index.js.map +1 -1
  68. package/dist/runtime-ets/bom/document.ts +6 -4
  69. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
  70. package/dist/runtime-ets/bom/window.ts +9 -2
  71. package/dist/runtime-ets/current.ts +3 -0
  72. package/dist/runtime-ets/dom/bind.ts +28 -12
  73. package/dist/runtime-ets/dom/class-list.ts +2 -2
  74. package/dist/runtime-ets/dom/cssNesting.ts +409 -0
  75. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +29 -19
  76. package/dist/runtime-ets/dom/document.ts +22 -8
  77. package/dist/runtime-ets/dom/element/canvas.ts +136 -0
  78. package/dist/runtime-ets/dom/element/element.ts +334 -57
  79. package/dist/runtime-ets/dom/element/form.ts +32 -26
  80. package/dist/runtime-ets/dom/element/index.ts +33 -2
  81. package/dist/runtime-ets/dom/element/movableArea.ts +11 -0
  82. package/dist/runtime-ets/dom/element/movableView.ts +242 -0
  83. package/dist/runtime-ets/dom/element/normal.ts +36 -8
  84. package/dist/runtime-ets/dom/element/progress.ts +11 -0
  85. package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
  86. package/dist/runtime-ets/dom/element/text.ts +1 -8
  87. package/dist/runtime-ets/dom/element/video.ts +5 -4
  88. package/dist/runtime-ets/dom/element/webView.ts +68 -0
  89. package/dist/runtime-ets/dom/event.ts +2 -4
  90. package/dist/runtime-ets/dom/eventTarget.ts +2 -3
  91. package/dist/runtime-ets/dom/node.ts +62 -27
  92. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +805 -0
  93. package/dist/runtime-ets/dom/stylesheet/index.ts +98 -518
  94. package/dist/runtime-ets/dom/stylesheet/type.ts +92 -17
  95. package/dist/runtime-ets/dom/stylesheet/util.ts +74 -16
  96. package/dist/runtime-ets/index.ts +2 -2
  97. package/dist/runtime-ets/interface/event.ts +3 -2
  98. package/dist/runtime-ets/utils/index.ts +77 -12
  99. package/dist/runtime-ets/utils/info.ts +4 -2
  100. package/dist/runtime-framework/react/app.ts +17 -22
  101. package/dist/runtime-framework/react/hooks.ts +3 -4
  102. package/dist/runtime-framework/react/index.ts +1 -2
  103. package/dist/runtime-framework/react/native-page.ts +421 -0
  104. package/dist/runtime-framework/react/page.ts +4 -9
  105. package/dist/runtime-framework/solid/app.ts +25 -45
  106. package/dist/runtime-framework/solid/connect.ts +21 -3
  107. package/dist/runtime-framework/solid/hooks.ts +17 -12
  108. package/dist/runtime-framework/solid/index.ts +6 -2
  109. package/dist/runtime-framework/solid/page.ts +84 -30
  110. package/dist/runtime-framework/solid/reconciler/props.ts +70 -25
  111. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  112. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  113. package/dist/runtime-framework/solid/utils/index.ts +0 -2
  114. package/dist/runtime-utils.d.ts +827 -0
  115. package/dist/runtime-utils.js +510 -237
  116. package/dist/runtime-utils.js.map +1 -1
  117. package/dist/runtime.d.ts +1 -0
  118. package/dist/runtime.js +510 -237
  119. package/dist/runtime.js.map +1 -1
  120. package/index.js +3 -1
  121. package/package.json +14 -15
  122. package/static/media/cancel.svg +1 -0
  123. package/static/media/circle.svg +1 -0
  124. package/static/media/clear.svg +1 -0
  125. package/static/media/download.svg +1 -0
  126. package/static/media/info.svg +1 -0
  127. package/static/media/info_circle.svg +1 -0
  128. package/static/media/search.svg +1 -0
  129. package/static/media/success.svg +1 -0
  130. package/static/media/success_no_circle.svg +1 -0
  131. package/static/media/taro_arrow_left.svg +1 -0
  132. package/static/media/taro_home.svg +1 -0
  133. package/static/media/waiting.svg +1 -0
  134. package/static/media/warn.svg +1 -0
  135. package/types/harmony.d.ts +4 -0
  136. package/types/index.d.ts +4 -0
  137. package/types/runtime.d.ts +3 -1
  138. package/dist/runtime-ets/utils/bind.ts +0 -24
  139. /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
@@ -29,12 +29,10 @@ interface FormWidgetProps extends StandardProps {
29
29
  }
30
30
 
31
31
  class TaroFormWidgetElement<T extends FormWidgetProps = FormWidgetProps> extends TaroElement<T> {
32
- _instance
32
+ _isInit = false
33
33
 
34
34
  _name = ''
35
35
 
36
- _value: TaroAny = ''
37
-
38
36
  _reset: TaroAny = ''
39
37
 
40
38
  constructor (tagName: string) {
@@ -43,8 +41,7 @@ class TaroFormWidgetElement<T extends FormWidgetProps = FormWidgetProps> extends
43
41
  bindFocus(this)
44
42
 
45
43
  this._name = this._attrs.name || ''
46
- this._value = this._attrs.value || ''
47
- this._reset = this._attrs.value || ''
44
+ this._nodeInfo._value = this._attrs.value || ''
48
45
  }
49
46
 
50
47
  public setAttribute (name: string, value: any): void {
@@ -65,11 +62,10 @@ class TaroFormWidgetElement<T extends FormWidgetProps = FormWidgetProps> extends
65
62
 
66
63
  public set name (val: string) {
67
64
  this.updateFormWidgetName(val)
68
- this.updateComponent()
69
65
  }
70
66
 
71
67
  public get value () {
72
- return this._value
68
+ return this._nodeInfo._value
73
69
  }
74
70
 
75
71
  public set value (val: TaroAny) {
@@ -77,8 +73,6 @@ class TaroFormWidgetElement<T extends FormWidgetProps = FormWidgetProps> extends
77
73
 
78
74
  if (this._instance) {
79
75
  this._instance.value = val
80
- } else {
81
- this.updateComponent()
82
76
  }
83
77
  }
84
78
 
@@ -88,7 +82,7 @@ class TaroFormWidgetElement<T extends FormWidgetProps = FormWidgetProps> extends
88
82
  }
89
83
 
90
84
  public updateFormWidgetValue (val: TaroAny) {
91
- this._value = val
85
+ this._nodeInfo._value = val
92
86
  this._attrs.value = val
93
87
  }
94
88
 
@@ -104,7 +98,6 @@ class TaroCheckedElement<T extends StandardProps & { checked?: boolean } = Stand
104
98
  super(tagName)
105
99
 
106
100
  this._checked = this._attrs.checked || false
107
- this._reset = this._attrs.checked || false
108
101
  }
109
102
 
110
103
  public setAttribute (name: string, value: any): void {
@@ -121,7 +114,6 @@ class TaroCheckedElement<T extends StandardProps & { checked?: boolean } = Stand
121
114
 
122
115
  set checked (val: boolean) {
123
116
  this.updateCheckedValue(val)
124
- this.updateComponent()
125
117
  }
126
118
 
127
119
  public updateCheckedValue (val: boolean) {
@@ -134,6 +126,7 @@ class TaroCheckedElement<T extends StandardProps & { checked?: boolean } = Stand
134
126
  }
135
127
  }
136
128
 
129
+ @Observed
137
130
  class TaroInputElement<T extends FormWidgetProps = InputProps> extends TaroFormWidgetElement<T> {
138
131
  _height = 0
139
132
 
@@ -193,38 +186,39 @@ class TaroInputElement<T extends FormWidgetProps = InputProps> extends TaroFormW
193
186
  }
194
187
  }
195
188
 
196
-
197
- class TaroTextAreaElement extends TaroInputElement<TextareaProps>{
189
+ @Observed
190
+ class TaroTextAreaElement extends TaroInputElement<TextareaProps> {
198
191
  controller: TextAreaController = new TextAreaController()
199
192
 
200
193
  constructor() {
201
194
  super('TextArea')
202
195
  }
203
196
  }
204
-
205
- class TaroCheckboxElement extends TaroCheckedElement<CheckboxProps>{
197
+ @Observed
198
+ class TaroCheckboxElement extends TaroCheckedElement<CheckboxProps> {
206
199
  constructor() {
207
200
  super('Checkbox')
208
201
  }
209
202
  }
210
203
 
211
- class TaroRadioElement extends TaroCheckedElement<RadioProps>{
204
+ @Observed
205
+ class TaroRadioElement extends TaroCheckedElement<RadioProps> {
212
206
  public group?: string
213
207
 
214
208
  constructor() {
215
209
  super('Radio')
216
210
  }
217
211
  }
218
- class TaroSliderElement extends TaroFormWidgetElement<SliderProps> {
219
- _value = 0
220
212
 
213
+ @Observed
214
+ class TaroSliderElement extends TaroFormWidgetElement<SliderProps> {
221
215
  constructor() {
222
216
  super('Slider')
223
217
 
224
- this._value = Number(this._attrs.value || 0)
218
+ this._nodeInfo._value = Number(this._attrs.value || 0)
225
219
  }
226
220
  }
227
-
221
+ @Observed
228
222
  class TaroPickerElement extends TaroFormWidgetElement<PickerSelectorProps | PickerTimeProps | PickerDateProps | PickerMultiSelectorProps> {
229
223
  constructor() {
230
224
  super('Picker')
@@ -238,7 +232,7 @@ class TaroPickerElement extends TaroFormWidgetElement<PickerSelectorProps | Pick
238
232
  case 'selector': {
239
233
  const key = this._attrs.rangeKey
240
234
  const item = this._attrs.range[this.value]
241
-
235
+
242
236
  if (key) {
243
237
  return item[key]
244
238
  } else {
@@ -262,14 +256,24 @@ class TaroPickerElement extends TaroFormWidgetElement<PickerSelectorProps | Pick
262
256
  return ''
263
257
  }
264
258
  }
259
+
260
+ public reset() {
261
+ super.reset()
262
+
263
+ const event: TaroEvent = createTaroEvent('change', { detail: { value: this._reset } }, this)
264
+
265
+ event.stopPropagation()
266
+ eventHandler(event, 'change', this)
267
+ }
265
268
  }
266
269
 
270
+ @Observed
267
271
  class TaroSwitchElement extends TaroCheckedElement<SwitchProps> {
268
272
  constructor() {
269
273
  super('Switch')
270
274
  }
271
275
  }
272
-
276
+ @Observed
273
277
  class TaroCheckboxGroupElement extends TaroFormWidgetElement<CheckboxGroupProps> {
274
278
  constructor() {
275
279
  super('CheckboxGroup')
@@ -295,6 +299,7 @@ class TaroCheckboxGroupElement extends TaroFormWidgetElement<CheckboxGroupProps>
295
299
  }
296
300
  }
297
301
 
302
+ @Observed
298
303
  class TaroRadioGroupElement extends TaroFormWidgetElement<RadioGroupProps> {
299
304
  constructor() {
300
305
  super('RadioGroup')
@@ -320,6 +325,7 @@ class TaroRadioGroupElement extends TaroFormWidgetElement<RadioGroupProps> {
320
325
  }
321
326
  }
322
327
 
328
+ @Observed
323
329
  class TaroFormElement extends TaroFormWidgetElement {
324
330
  constructor() {
325
331
  super('Form')
@@ -331,7 +337,7 @@ class TaroFormElement extends TaroFormWidgetElement {
331
337
 
332
338
  findChildNodeWithDFS<TaroFormWidgetElement>(this, item => {
333
339
  if (!item.name) return false
334
-
340
+
335
341
  switch (item.nodeName) {
336
342
  case 'INPUT':
337
343
  case 'RADIO':
@@ -362,9 +368,9 @@ class TaroFormElement extends TaroFormWidgetElement {
362
368
  e.stopPropagation()
363
369
  switch (item.nodeName) {
364
370
  case 'INPUT':
365
- case 'SLIDER':
371
+ case 'SLIDER':
366
372
  case 'PICKER':
367
- case 'RADIO':
373
+ case 'RADIO':
368
374
  case 'SWITCH':
369
375
  case 'CHECKBOX':
370
376
  case 'TEXTAREA':
@@ -1,5 +1,6 @@
1
1
  import { Current } from '../../current'
2
2
  import { TaroTextNode } from '../node'
3
+ import { TaroCanvasElement } from './canvas'
3
4
  import { TaroElement } from './element'
4
5
  import {
5
6
  FormElement,
@@ -14,19 +15,26 @@ import {
14
15
  TaroSwitchElement,
15
16
  TaroTextAreaElement
16
17
  } from './form'
18
+ import { TaroMovableAreaElement } from './movableArea'
19
+ import { isTaroMovableViewElement, TaroMovableViewElement } from './movableView'
17
20
  import {
18
21
  TaroButtonElement,
19
22
  TaroIconElement,
20
23
  TaroImageElement,
21
24
  TaroLabelElement,
25
+ TaroNavigationBarElement,
26
+ TaroOtherElement,
27
+ TaroPageMetaElement,
22
28
  TaroRichTextElement,
23
29
  TaroSwiperElement,
24
30
  TaroSwiperItemElement,
25
31
  TaroViewElement
26
32
  } from './normal'
33
+ import { TaroProgressElement } from './progress'
27
34
  import { TaroScrollViewElement } from './scrollView'
28
35
  import { TaroTextElement } from './text'
29
36
  import { TaroVideoElement } from './video'
37
+ import { TaroInnerHtmlElement, TaroWebViewElement } from './webView'
30
38
 
31
39
  export function initHarmonyElement () {
32
40
  Current.createHarmonyElement = (tagName: string) => {
@@ -35,7 +43,11 @@ export function initHarmonyElement () {
35
43
  case 'image': return new TaroImageElement()
36
44
  case 'text': return new TaroTextElement()
37
45
  case 'button': return new TaroButtonElement()
46
+ case 'movable-area': return new TaroMovableAreaElement()
47
+ case 'movable-view': return new TaroMovableViewElement()
48
+ case 'progress': return new TaroProgressElement()
38
49
  case 'scroll-view': return new TaroScrollViewElement()
50
+ case 'scroll-list': return new TaroScrollViewElement()
39
51
  case 'checkbox-group': return new TaroCheckboxGroupElement()
40
52
  case 'input': return new TaroInputElement()
41
53
  case 'picker': return new TaroPickerElement()
@@ -48,11 +60,16 @@ export function initHarmonyElement () {
48
60
  case 'icon': return new TaroIconElement()
49
61
  case 'label': return new TaroLabelElement()
50
62
  case 'rich-text': return new TaroRichTextElement()
63
+ case 'canvas': return new TaroCanvasElement()
51
64
  case 'swiper': return new TaroSwiperElement()
52
65
  case 'swiper-item': return new TaroSwiperItemElement()
53
66
  case 'textarea': return new TaroTextAreaElement()
54
67
  case 'form': return new TaroFormElement()
55
- default: return new TaroElement(tagName)
68
+ case 'web-view': return new TaroWebViewElement()
69
+ case 'inner-html': return new TaroInnerHtmlElement()
70
+ case 'page-meta': return new TaroPageMetaElement()
71
+ case 'navigation-bar': return new TaroNavigationBarElement()
72
+ default: return new TaroOtherElement(tagName)
56
73
  }
57
74
  }
58
75
 
@@ -65,15 +82,23 @@ export function initHarmonyElement () {
65
82
  export {
66
83
  FormElement,
67
84
  TaroButtonElement,
85
+ TaroCanvasElement,
68
86
  TaroCheckboxElement,
69
87
  TaroCheckboxGroupElement,
70
88
  TaroElement,
71
89
  TaroFormElement,
72
90
  TaroIconElement,
73
91
  TaroImageElement,
92
+ TaroInnerHtmlElement,
74
93
  TaroInputElement,
75
94
  TaroLabelElement,
95
+ TaroMovableAreaElement,
96
+ TaroMovableViewElement,
97
+ TaroNavigationBarElement,
98
+ TaroOtherElement,
99
+ TaroPageMetaElement,
76
100
  TaroPickerElement,
101
+ TaroProgressElement,
77
102
  TaroRadioElement,
78
103
  TaroRadioGroupElement,
79
104
  TaroRichTextElement,
@@ -85,5 +110,11 @@ export {
85
110
  TaroTextAreaElement,
86
111
  TaroTextElement,
87
112
  TaroVideoElement,
88
- TaroViewElement
113
+ TaroViewElement,
114
+ TaroWebViewElement
115
+ }
116
+
117
+
118
+ export {
119
+ isTaroMovableViewElement
89
120
  }
@@ -0,0 +1,11 @@
1
+
2
+ import { TaroElement } from './element'
3
+
4
+ import type { MovableAreaProps } from '@tarojs/components/types'
5
+
6
+ @Observed
7
+ export class TaroMovableAreaElement extends TaroElement<MovableAreaProps> {
8
+ constructor() {
9
+ super('MovableArea')
10
+ }
11
+ }
@@ -0,0 +1,242 @@
1
+ import { TaroElement } from './element'
2
+
3
+ import type { MovableViewProps } from '@tarojs/components/types'
4
+ import type { TaroAny } from '../../utils'
5
+
6
+ type Tsize = {
7
+ w: number
8
+ h: number
9
+ }
10
+ type Tpoint = {
11
+ x: number
12
+ y: number
13
+ }
14
+
15
+ function calcPosition(postion: number, start: number, end: number) {
16
+ if (postion <= end && postion >= start) {
17
+ return postion
18
+ } else if (postion < start) {
19
+ return start
20
+ } else {
21
+ return end
22
+ }
23
+ }
24
+
25
+ export function isTaroMovableViewElement (item: TaroAny): item is TaroMovableViewElement {
26
+ return item instanceof TaroMovableViewElement
27
+ }
28
+ @Observed
29
+ export class TaroMovableViewElement extends TaroElement<MovableViewProps & { animation: undefined }> {
30
+ _scaleValue = 1
31
+ _scalevalueTemp = 1
32
+
33
+ // 父级区别的大小
34
+ _area?: Tsize
35
+ // 自己元素的大小
36
+ _selfSize?: Tsize
37
+ _areaInited: false
38
+ _selfSizeInited: false
39
+
40
+ // 元素的位置
41
+ _position: Tpoint = {
42
+ x: 0,
43
+ y: 0,
44
+ }
45
+
46
+ _positionTemp: Tpoint = {
47
+ x: 0,
48
+ y: 0,
49
+ }
50
+
51
+ constructor() {
52
+ super('MovableView')
53
+ }
54
+
55
+ get _outOfBounds() {
56
+ if (this.getAttribute('outOfBounds')) {
57
+ return this.selfSize ? this.selfSize.w / 3 : 0
58
+ }
59
+ return 0
60
+ }
61
+
62
+ startScale() {
63
+ this._scalevalueTemp = this._scaleValue
64
+ }
65
+
66
+ doScale(val: number) {
67
+ const scale = this.getAttribute('scale')
68
+
69
+ // 禁止缩放的时候不生效
70
+ if (scale) {
71
+ this.scaleValue = val * this._scalevalueTemp
72
+ }
73
+ }
74
+
75
+ set scaleValue(val: number) {
76
+ if (this.checkScaleValueInBounds(val)) {
77
+ this._scaleValue = val
78
+
79
+ this.checkPositionBoundary(this.position, val)
80
+
81
+ const scaleFns = this?.__listeners?.scale || []
82
+ scaleFns.forEach((fn) => {
83
+ fn({ ...this.position, scale: this.scaleValue })
84
+ })
85
+ }
86
+ }
87
+
88
+ get visibility () {
89
+ return this._areaInited && this._selfSizeInited ? Visibility.Visible : Visibility.Hidden
90
+ }
91
+
92
+ get scaleValue() {
93
+ return this._scaleValue
94
+ }
95
+
96
+ startMove() {
97
+ this._positionTemp = this._position
98
+ }
99
+
100
+ doMove(val: Tpoint) {
101
+ if (!this.area || !this.selfSize) {
102
+ return
103
+ }
104
+ if (this.getAttribute('disabled')) {
105
+ return
106
+ }
107
+ const direction = this.getAttribute('direction')
108
+
109
+ // 容器的宽高终点
110
+ const areaWidthEnd = this.area.w - this.selfSize.w * this.scaleValue
111
+ const areaHeightEnd = this.area.h - this.selfSize.h * this.scaleValue
112
+
113
+ const incrementWidth = (this.scaleValue - 1) * this.selfSize.w
114
+ const incrementHeight = (this.scaleValue - 1) * this.selfSize.h
115
+
116
+ let x = this._positionTemp.x
117
+ let y = this._positionTemp.y
118
+ if (['all', 'horizontal'].includes(direction)) {
119
+ const nextX = this._positionTemp.x + val.x * this.scaleValue
120
+ x = calcPosition(
121
+ nextX,
122
+ incrementWidth * 0.5 - this._outOfBounds,
123
+ areaWidthEnd + incrementWidth * 0.5 + this._outOfBounds
124
+ )
125
+ }
126
+
127
+ if (['all', 'vertical'].includes(direction)) {
128
+ const nextY = this._positionTemp.y + val.y * this.scaleValue
129
+ y = calcPosition(
130
+ nextY,
131
+ incrementHeight * 0.5 - this._outOfBounds,
132
+ areaHeightEnd + incrementHeight * 0.5 + this._outOfBounds
133
+ )
134
+ }
135
+
136
+ const changeFns = this?.__listeners?.change || []
137
+ changeFns.forEach((fn) => {
138
+ fn({ x, y, source: 'touch' })
139
+ })
140
+
141
+ this.position = {
142
+ x: x,
143
+ y: y,
144
+ }
145
+ }
146
+
147
+ get position() {
148
+ return this._position
149
+ }
150
+
151
+ set position(val: Tpoint) {
152
+ this._position = val
153
+ }
154
+
155
+ set area(val: Tsize) {
156
+ if (val.w === this._area?.w && val.h === this._area?.h) return
157
+ this._area = val
158
+ if (!this._areaInited) {
159
+ this._areaInited = true
160
+ this.initPositionFromAttribute()
161
+ }
162
+ }
163
+
164
+ get area(): Tsize | undefined {
165
+ return this._area
166
+ }
167
+
168
+ set selfSize(val: Tsize) {
169
+ if (val.w === this._selfSize?.w && val.h === this._selfSize?.h) return
170
+ this._selfSize = val
171
+ if (!this._selfSizeInited) {
172
+ this._selfSizeInited = true
173
+ this.initPositionFromAttribute()
174
+ }
175
+ }
176
+
177
+ get selfSize(): Tsize | undefined {
178
+ return this._selfSize
179
+ }
180
+
181
+ initPositionFromAttribute () {
182
+ if (!this.area || !this.selfSize) {
183
+ return
184
+ }
185
+ const x = this.getAttribute('x') ? Number(this.getAttribute('x')) : 0
186
+ const y = this.getAttribute('y') ? Number(this.getAttribute('y')) : 0
187
+ this.checkPositionBoundary({ x, y }, this.scaleValue)
188
+ }
189
+
190
+ checkPositionBoundary(position: Tpoint, scale: number) {
191
+ if (!this.area || !this.selfSize) {
192
+ return { x: 0, y: 0 }
193
+ }
194
+
195
+ const areaWidthEnd = this.area.w - this.selfSize.w * scale
196
+ const areaHeightEnd = this.area.h - this.selfSize.h * scale
197
+
198
+ const incrementWidth = (scale - 1) * this.selfSize.w
199
+ const incrementHeight = (scale - 1) * this.selfSize.h
200
+
201
+ this.position = {
202
+ x: calcPosition(position.x, incrementWidth * 0.5, areaWidthEnd + incrementWidth * 0.5),
203
+ y: calcPosition(position.y, incrementHeight * 0.5, areaHeightEnd + incrementHeight * 0.5),
204
+ }
205
+ }
206
+
207
+ checkScaleValueInBounds(currentScale: number) {
208
+ const scaleMin = this.getAttribute('scaleMin')
209
+ const scaleMax = this.getAttribute('scaleMax')
210
+
211
+ if (scaleMin && Number(scaleMin) >= 0.1 && currentScale < Number(scaleMin)) {
212
+ return false
213
+ } else if (scaleMax && Number(scaleMax) >= 0.1 && currentScale > Number(scaleMax)) {
214
+ return false
215
+ }
216
+
217
+ return true
218
+ }
219
+
220
+ public setAttribute(name: string, value: any): void {
221
+ if (name === 'x') {
222
+ this.checkPositionBoundary({ x: value, y: this.position.y }, this.scaleValue)
223
+ }
224
+ if (name === 'y') {
225
+ this.checkPositionBoundary({ x: this.position.x, y: value }, this.scaleValue)
226
+ }
227
+
228
+ super.setAttribute(name, value)
229
+ }
230
+
231
+ public callTouchEventFnFromGesture(eventName: string, gestureEvent: GestureEvent) {
232
+ const touchFns = (this?.__listeners?.[eventName] || []) as Function[]
233
+ touchFns.forEach(fn => {
234
+ fn({
235
+ changedTouches: gestureEvent.fingerList.map(finger => ({
236
+ clientX: finger.globalX,
237
+ clientY: finger.globalY
238
+ }))
239
+ })
240
+ })
241
+ }
242
+ }
@@ -6,50 +6,60 @@ import type {
6
6
  IconProps,
7
7
  ImageProps,
8
8
  LabelProps,
9
+ NavigationBarProps,
10
+ PageMetaProps,
9
11
  RichTextProps,
10
12
  SwiperItemProps,
11
13
  SwiperProps,
12
14
  ViewProps
13
15
  } from '@tarojs/components/types'
14
16
 
17
+ @Observed
18
+ class TaroOtherElement extends TaroElement<ViewProps> {}
19
+
20
+ @Observed
15
21
  class TaroViewElement extends TaroElement<ViewProps> {
16
22
  constructor() {
17
23
  super('View')
18
24
  }
19
25
  }
20
26
 
27
+ @Observed
21
28
  class TaroImageElement extends TaroElement<ImageProps> {
22
29
  constructor() {
23
30
  super('Image')
24
31
  }
25
32
  }
26
33
 
34
+ @Observed
27
35
  class TaroButtonElement extends TaroElement<ButtonProps> {
28
36
  constructor() {
29
37
  super('Button')
30
38
  }
31
39
  }
32
40
 
33
-
34
- class TaroIconElement extends TaroElement<IconProps>{
41
+ @Observed
42
+ class TaroIconElement extends TaroElement<IconProps> {
35
43
  constructor() {
36
44
  super('Icon')
37
45
  }
38
46
  }
39
-
40
- class TaroLabelElement extends TaroElement<LabelProps>{
47
+ @Observed
48
+ class TaroLabelElement extends TaroElement<LabelProps> {
41
49
  constructor() {
42
50
  super('Label')
43
51
  }
44
52
  }
45
53
 
46
- class TaroRichTextElement extends TaroElement<RichTextProps>{
54
+ @Observed
55
+ class TaroRichTextElement extends TaroElement<RichTextProps> {
47
56
  constructor() {
48
57
  super('RichText')
49
58
  }
50
59
  }
51
60
 
52
- class TaroSwiperElement extends TaroElement<SwiperProps>{
61
+ @Observed
62
+ class TaroSwiperElement extends TaroElement<SwiperProps> {
53
63
  controller: SwiperController = new SwiperController()
54
64
 
55
65
  constructor() {
@@ -57,19 +67,37 @@ class TaroSwiperElement extends TaroElement<SwiperProps>{
57
67
  }
58
68
  }
59
69
 
60
- class TaroSwiperItemElement extends TaroElement<SwiperItemProps>{
70
+ @Observed
71
+ class TaroSwiperItemElement extends TaroElement<SwiperItemProps> {
61
72
  constructor() {
62
73
  super('SwiperItem')
63
74
  }
64
75
  }
65
76
 
77
+ @Observed
78
+ class TaroPageMetaElement extends TaroElement<PageMetaProps> {
79
+ constructor() {
80
+ super('PageMeta')
81
+ }
82
+ }
83
+
84
+ @Observed
85
+ class TaroNavigationBarElement extends TaroElement<NavigationBarProps> {
86
+ constructor() {
87
+ super('NavigationBar')
88
+ }
89
+ }
90
+
66
91
  export {
67
92
  TaroButtonElement,
68
93
  TaroIconElement,
69
94
  TaroImageElement,
70
95
  TaroLabelElement,
96
+ TaroNavigationBarElement,
97
+ TaroOtherElement,
98
+ TaroPageMetaElement,
71
99
  TaroRichTextElement,
72
100
  TaroSwiperElement,
73
101
  TaroSwiperItemElement,
74
- TaroViewElement,
102
+ TaroViewElement
75
103
  }
@@ -0,0 +1,11 @@
1
+
2
+ import { TaroElement } from './element'
3
+
4
+ import type { ProgressProps } from '@tarojs/components/types'
5
+
6
+ @Observed
7
+ export class TaroProgressElement extends TaroElement<ProgressProps> {
8
+ constructor() {
9
+ super('Progress')
10
+ }
11
+ }
@@ -3,6 +3,7 @@ import { TaroElement } from './element'
3
3
 
4
4
  import type { ScrollViewProps } from '@tarojs/components/types'
5
5
 
6
+ @Observed
6
7
  export class TaroScrollViewElement extends TaroElement<ScrollViewProps> {
7
8
  scroller: Scroller = new Scroller()
8
9
 
@@ -1,17 +1,10 @@
1
- import { TaroNode } from '../node'
2
1
  import { TaroElement } from './element'
3
2
 
4
3
  import type { TextProps } from '@tarojs/components/types'
5
4
 
5
+ @Observed
6
6
  export class TaroTextElement extends TaroElement<TextProps> {
7
7
  constructor() {
8
8
  super('Text')
9
9
  }
10
-
11
- public appendChild (child: TaroNode): TaroNode {
12
- super.appendChild(child)
13
-
14
- this.updateComponent()
15
- return child
16
- }
17
10
  }