@lightningjs/blits 1.1.0 → 1.3.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 (50) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/NOTICE +9 -0
  3. package/docs/_sidebar.md +1 -0
  4. package/docs/built-in/directives.md +4 -6
  5. package/docs/built-in/for-loop.md +6 -8
  6. package/docs/components/component_state.md +3 -5
  7. package/docs/components/computed_properties.md +3 -5
  8. package/docs/components/lifecycle_events.md +2 -4
  9. package/docs/components/methods.md +1 -3
  10. package/docs/components/props.md +3 -5
  11. package/docs/components/user_input.md +6 -8
  12. package/docs/components/utilities.md +1 -2
  13. package/docs/components/watchers.md +2 -4
  14. package/docs/essentials/application_root.md +1 -3
  15. package/docs/essentials/components.md +2 -4
  16. package/docs/essentials/displaying_images.md +4 -6
  17. package/docs/essentials/displaying_text.md +4 -6
  18. package/docs/essentials/element_attributes.md +10 -12
  19. package/docs/essentials/template_syntax.md +5 -7
  20. package/docs/getting_started/file_structure.md +9 -11
  21. package/docs/getting_started/getting_started.md +5 -7
  22. package/docs/plugins/language.md +172 -0
  23. package/docs/plugins/text-to-speech-announcer.md +2 -4
  24. package/docs/sidebar.json +4 -0
  25. package/docs/transitions_animations/transitions.md +5 -7
  26. package/index.d.ts +2 -0
  27. package/index.js +2 -0
  28. package/package.json +3 -2
  29. package/src/component/base/index.js +4 -1
  30. package/src/component/base/log.js +1 -1
  31. package/src/component/base/methods.js +1 -2
  32. package/src/component/setup/state.js +9 -13
  33. package/src/component.d.ts +6 -0
  34. package/src/component.js +30 -10
  35. package/src/components/FPScounter.js +56 -12
  36. package/src/components/index.js +0 -2
  37. package/src/components/index.orig.js +0 -2
  38. package/src/engines/L3/element.js +56 -66
  39. package/src/helpers/fetchJson.js +34 -0
  40. package/src/lib/codegenerator/generator.js +104 -28
  41. package/src/lib/codegenerator/generator.test.js +184 -0
  42. package/src/lib/colors/colors.js +6 -7
  43. package/src/lib/reactivity/reactive.js +3 -5
  44. package/src/lib/symbols.js +1 -0
  45. package/src/lib/templateparser/parser.js +1 -1
  46. package/src/plugin.d.ts +71 -0
  47. package/src/plugin.js +23 -0
  48. package/src/{components/Image.orig.js → plugins/index.js} +2 -17
  49. package/src/plugins/language.js +122 -0
  50. package/src/components/Image.js +0 -52
@@ -60,9 +60,11 @@ export default () =>
60
60
  elementConfig3['map'] = component.sprite
61
61
  elementConfig3['frame'] = 'fps'
62
62
 
63
+ const skip3 = []
63
64
  if (typeof cmp3 !== 'undefined') {
64
65
  for (let key in cmp3.config.props) {
65
66
  delete elementConfig3[cmp3.config.props[key]]
67
+ skip3.push(cmp3.config.props[key])
66
68
  }
67
69
  }
68
70
 
@@ -120,9 +122,11 @@ export default () =>
120
122
  elementConfig6['map'] = component.sprite
121
123
  elementConfig6['frame'] = component.fps[0]
122
124
 
125
+ const skip6 = []
123
126
  if (typeof cmp6 !== 'undefined') {
124
127
  for (let key in cmp6.config.props) {
125
128
  delete elementConfig6[cmp6.config.props[key]]
129
+ skip6.push(cmp6.config.props[key])
126
130
  }
127
131
  }
128
132
 
@@ -172,9 +176,11 @@ export default () =>
172
176
  elementConfig8['map'] = component.sprite
173
177
  elementConfig8['frame'] = component.fps[1]
174
178
 
179
+ const skip8 = []
175
180
  if (typeof cmp8 !== 'undefined') {
176
181
  for (let key in cmp8.config.props) {
177
182
  delete elementConfig8[cmp8.config.props[key]]
183
+ skip8.push(cmp8.config.props[key])
178
184
  }
179
185
  }
180
186
 
@@ -224,9 +230,11 @@ export default () =>
224
230
  elementConfig10['map'] = component.sprite
225
231
  elementConfig10['frame'] = component.fps[2]
226
232
 
233
+ const skip10 = []
227
234
  if (typeof cmp10 !== 'undefined') {
228
235
  for (let key in cmp10.config.props) {
229
236
  delete elementConfig10[cmp10.config.props[key]]
237
+ skip10.push(cmp10.config.props[key])
230
238
  }
231
239
  }
232
240
 
@@ -284,9 +292,11 @@ export default () =>
284
292
  elementConfig13['map'] = component.sprite
285
293
  elementConfig13['frame'] = 'avg'
286
294
 
295
+ const skip13 = []
287
296
  if (typeof cmp13 !== 'undefined') {
288
297
  for (let key in cmp13.config.props) {
289
298
  delete elementConfig13[cmp13.config.props[key]]
299
+ skip13.push(cmp13.config.props[key])
290
300
  }
291
301
  }
292
302
 
@@ -345,9 +355,11 @@ export default () =>
345
355
  elementConfig16['map'] = component.sprite
346
356
  elementConfig16['frame'] = component.avgFps[0]
347
357
 
358
+ const skip16 = []
348
359
  if (typeof cmp16 !== 'undefined') {
349
360
  for (let key in cmp16.config.props) {
350
361
  delete elementConfig16[cmp16.config.props[key]]
362
+ skip16.push(cmp16.config.props[key])
351
363
  }
352
364
  }
353
365
 
@@ -397,9 +409,11 @@ export default () =>
397
409
  elementConfig18['map'] = component.sprite
398
410
  elementConfig18['frame'] = component.avgFps[1]
399
411
 
412
+ const skip18 = []
400
413
  if (typeof cmp18 !== 'undefined') {
401
414
  for (let key in cmp18.config.props) {
402
415
  delete elementConfig18[cmp18.config.props[key]]
416
+ skip18.push(cmp18.config.props[key])
403
417
  }
404
418
  }
405
419
 
@@ -449,9 +463,11 @@ export default () =>
449
463
  elementConfig20['map'] = component.sprite
450
464
  elementConfig20['frame'] = component.avgFps[2]
451
465
 
466
+ const skip20 = []
452
467
  if (typeof cmp20 !== 'undefined') {
453
468
  for (let key in cmp20.config.props) {
454
469
  delete elementConfig20[cmp20.config.props[key]]
470
+ skip20.push(cmp20.config.props[key])
455
471
  }
456
472
  }
457
473
 
@@ -510,9 +526,11 @@ export default () =>
510
526
  elementConfig23['map'] = component.sprite
511
527
  elementConfig23['frame'] = 'min'
512
528
 
529
+ const skip23 = []
513
530
  if (typeof cmp23 !== 'undefined') {
514
531
  for (let key in cmp23.config.props) {
515
532
  delete elementConfig23[cmp23.config.props[key]]
533
+ skip23.push(cmp23.config.props[key])
516
534
  }
517
535
  }
518
536
 
@@ -571,9 +589,11 @@ export default () =>
571
589
  elementConfig26['map'] = component.sprite
572
590
  elementConfig26['frame'] = component.minFps[0]
573
591
 
592
+ const skip26 = []
574
593
  if (typeof cmp26 !== 'undefined') {
575
594
  for (let key in cmp26.config.props) {
576
595
  delete elementConfig26[cmp26.config.props[key]]
596
+ skip26.push(cmp26.config.props[key])
577
597
  }
578
598
  }
579
599
 
@@ -623,9 +643,11 @@ export default () =>
623
643
  elementConfig28['map'] = component.sprite
624
644
  elementConfig28['frame'] = component.minFps[1]
625
645
 
646
+ const skip28 = []
626
647
  if (typeof cmp28 !== 'undefined') {
627
648
  for (let key in cmp28.config.props) {
628
649
  delete elementConfig28[cmp28.config.props[key]]
650
+ skip28.push(cmp28.config.props[key])
629
651
  }
630
652
  }
631
653
 
@@ -675,9 +697,11 @@ export default () =>
675
697
  elementConfig30['map'] = component.sprite
676
698
  elementConfig30['frame'] = component.minFps[2]
677
699
 
700
+ const skip30 = []
678
701
  if (typeof cmp30 !== 'undefined') {
679
702
  for (let key in cmp30.config.props) {
680
703
  delete elementConfig30[cmp30.config.props[key]]
704
+ skip30.push(cmp30.config.props[key])
681
705
  }
682
706
  }
683
707
 
@@ -735,9 +759,11 @@ export default () =>
735
759
  elementConfig33['map'] = component.sprite
736
760
  elementConfig33['frame'] = 'max'
737
761
 
762
+ const skip33 = []
738
763
  if (typeof cmp33 !== 'undefined') {
739
764
  for (let key in cmp33.config.props) {
740
765
  delete elementConfig33[cmp33.config.props[key]]
766
+ skip33.push(cmp33.config.props[key])
741
767
  }
742
768
  }
743
769
 
@@ -795,9 +821,11 @@ export default () =>
795
821
  elementConfig36['map'] = component.sprite
796
822
  elementConfig36['frame'] = component.maxFps[0]
797
823
 
824
+ const skip36 = []
798
825
  if (typeof cmp36 !== 'undefined') {
799
826
  for (let key in cmp36.config.props) {
800
827
  delete elementConfig36[cmp36.config.props[key]]
828
+ skip36.push(cmp36.config.props[key])
801
829
  }
802
830
  }
803
831
 
@@ -847,9 +875,11 @@ export default () =>
847
875
  elementConfig38['map'] = component.sprite
848
876
  elementConfig38['frame'] = component.maxFps[1]
849
877
 
878
+ const skip38 = []
850
879
  if (typeof cmp38 !== 'undefined') {
851
880
  for (let key in cmp38.config.props) {
852
881
  delete elementConfig38[cmp38.config.props[key]]
882
+ skip38.push(cmp38.config.props[key])
853
883
  }
854
884
  }
855
885
 
@@ -899,9 +929,11 @@ export default () =>
899
929
  elementConfig40['map'] = component.sprite
900
930
  elementConfig40['frame'] = component.maxFps[2]
901
931
 
932
+ const skip40 = []
902
933
  if (typeof cmp40 !== 'undefined') {
903
934
  for (let key in cmp40.config.props) {
904
935
  delete elementConfig40[cmp40.config.props[key]]
936
+ skip40.push(cmp40.config.props[key])
905
937
  }
906
938
  }
907
939
 
@@ -941,73 +973,85 @@ export default () =>
941
973
  },
942
974
  effects: [
943
975
  function anonymous(component, elms, context, components, rootComponent, effect) {
944
- elms[6].set('frame', component.fps[0])
976
+ if (typeof skip6 === 'undefined' || skip6.indexOf('frame') === -1)
977
+ elms[6].set('frame', component.fps[0])
945
978
  },
946
979
  function anonymous(component, elms, context, components, rootComponent, effect) {
947
980
  elms[7][Symbol.for('props')]['frame'] = component.fps[0]
948
981
  },
949
982
  function anonymous(component, elms, context, components, rootComponent, effect) {
950
- elms[8].set('frame', component.fps[1])
983
+ if (typeof skip8 === 'undefined' || skip8.indexOf('frame') === -1)
984
+ elms[8].set('frame', component.fps[1])
951
985
  },
952
986
  function anonymous(component, elms, context, components, rootComponent, effect) {
953
987
  elms[9][Symbol.for('props')]['frame'] = component.fps[1]
954
988
  },
955
989
  function anonymous(component, elms, context, components, rootComponent, effect) {
956
- elms[10].set('frame', component.fps[2])
990
+ if (typeof skip10 === 'undefined' || skip10.indexOf('frame') === -1)
991
+ elms[10].set('frame', component.fps[2])
957
992
  },
958
993
  function anonymous(component, elms, context, components, rootComponent, effect) {
959
994
  elms[11][Symbol.for('props')]['frame'] = component.fps[2]
960
995
  },
961
996
  function anonymous(component, elms, context, components, rootComponent, effect) {
962
- elms[16].set('frame', component.avgFps[0])
997
+ if (typeof skip16 === 'undefined' || skip16.indexOf('frame') === -1)
998
+ elms[16].set('frame', component.avgFps[0])
963
999
  },
964
1000
  function anonymous(component, elms, context, components, rootComponent, effect) {
965
1001
  elms[17][Symbol.for('props')]['frame'] = component.avgFps[0]
966
1002
  },
967
1003
  function anonymous(component, elms, context, components, rootComponent, effect) {
968
- elms[18].set('frame', component.avgFps[1])
1004
+ if (typeof skip18 === 'undefined' || skip18.indexOf('frame') === -1)
1005
+ elms[18].set('frame', component.avgFps[1])
969
1006
  },
970
1007
  function anonymous(component, elms, context, components, rootComponent, effect) {
971
1008
  elms[19][Symbol.for('props')]['frame'] = component.avgFps[1]
972
1009
  },
973
1010
  function anonymous(component, elms, context, components, rootComponent, effect) {
974
- elms[20].set('frame', component.avgFps[2])
1011
+ if (typeof skip20 === 'undefined' || skip20.indexOf('frame') === -1)
1012
+ elms[20].set('frame', component.avgFps[2])
975
1013
  },
976
1014
  function anonymous(component, elms, context, components, rootComponent, effect) {
977
1015
  elms[21][Symbol.for('props')]['frame'] = component.avgFps[2]
978
1016
  },
979
1017
  function anonymous(component, elms, context, components, rootComponent, effect) {
980
- elms[26].set('frame', component.minFps[0])
1018
+ if (typeof skip26 === 'undefined' || skip26.indexOf('frame') === -1)
1019
+ elms[26].set('frame', component.minFps[0])
981
1020
  },
982
1021
  function anonymous(component, elms, context, components, rootComponent, effect) {
983
1022
  elms[27][Symbol.for('props')]['frame'] = component.minFps[0]
984
1023
  },
985
1024
  function anonymous(component, elms, context, components, rootComponent, effect) {
986
- elms[28].set('frame', component.minFps[1])
1025
+ if (typeof skip28 === 'undefined' || skip28.indexOf('frame') === -1)
1026
+ elms[28].set('frame', component.minFps[1])
987
1027
  },
988
1028
  function anonymous(component, elms, context, components, rootComponent, effect) {
989
1029
  elms[29][Symbol.for('props')]['frame'] = component.minFps[1]
990
1030
  },
991
1031
  function anonymous(component, elms, context, components, rootComponent, effect) {
992
- elms[30].set('frame', component.minFps[2])
1032
+ if (typeof skip30 === 'undefined' || skip30.indexOf('frame') === -1)
1033
+ elms[30].set('frame', component.minFps[2])
993
1034
  },
994
1035
  function anonymous(component, elms, context, components, rootComponent, effect) {
995
1036
  elms[31][Symbol.for('props')]['frame'] = component.minFps[2]
996
1037
  },
997
1038
  function anonymous(component, elms, context, components, rootComponent, effect) {
998
- elms[36].set('frame', component.maxFps[0])
1039
+ if (typeof skip36 === 'undefined' || skip36.indexOf('frame') === -1)
1040
+ elms[36].set('frame', component.maxFps[0])
999
1041
  },
1000
1042
  function anonymous(component, elms, context, components, rootComponent, effect) {
1001
1043
  elms[37][Symbol.for('props')]['frame'] = component.maxFps[0]
1002
1044
  },
1003
1045
  function anonymous(component, elms, context, components, rootComponent, effect) {
1004
- elms[38].set('frame', component.maxFps[1])
1046
+ if (typeof skip38 === 'undefined' || skip38.indexOf('frame') === -1)
1047
+ elms[38].set('frame', component.maxFps[1])
1005
1048
  },
1006
1049
  function anonymous(component, elms, context, components, rootComponent, effect) {
1007
1050
  elms[39][Symbol.for('props')]['frame'] = component.maxFps[1]
1008
1051
  },
1009
1052
  function anonymous(component, elms, context, components, rootComponent, effect) {
1010
- elms[40].set('frame', component.maxFps[2])
1053
+ if (typeof skip40 === 'undefined' || skip40.indexOf('frame') === -1)
1054
+ elms[40].set('frame', component.maxFps[2])
1011
1055
  },
1012
1056
  function anonymous(component, elms, context, components, rootComponent, effect) {
1013
1057
  elms[41][Symbol.for('props')]['frame'] = component.maxFps[2]
@@ -15,7 +15,6 @@
15
15
  * SPDX-License-Identifier: Apache-2.0
16
16
  */
17
17
 
18
- import Image from './Image.js'
19
18
  import Circle from './Circle.js'
20
19
  import RouterView from './RouterView.js'
21
20
  import Sprite from './Sprite.js'
@@ -23,7 +22,6 @@ import FPScounter from './FPScounter.js'
23
22
  import Layout from './Layout.js'
24
23
 
25
24
  export default () => ({
26
- Image: Image(),
27
25
  Circle: Circle(),
28
26
  RouterView: RouterView(),
29
27
  Sprite: Sprite(),
@@ -15,7 +15,6 @@
15
15
  * SPDX-License-Identifier: Apache-2.0
16
16
  */
17
17
 
18
- import Image from './Image.js'
19
18
  import Circle from './Circle.js'
20
19
  import RouterView from './RouterView.js'
21
20
  import Sprite from './Sprite.js'
@@ -23,7 +22,6 @@ import FPScounter from './FPScounter.js'
23
22
  import Layout from './Layout.js'
24
23
 
25
24
  export default () => ({
26
- Image: Image(),
27
25
  Circle: Circle(),
28
26
  RouterView: RouterView(),
29
27
  Sprite: Sprite(),
@@ -23,7 +23,7 @@ import symbols from '../../lib/symbols.js'
23
23
  import Settings from '../../settings.js'
24
24
 
25
25
  const isTransition = (value) => {
26
- return value !== null && typeof value === 'object' && 'transition' in value
26
+ return value !== null && typeof value === 'object' && 'transition' in value === true
27
27
  }
28
28
 
29
29
  const isObjectString = (str) => {
@@ -48,13 +48,12 @@ const parsePercentage = function (v, base) {
48
48
  }
49
49
 
50
50
  const unpackTransition = (v) => {
51
- if (v === null) return v
52
- if (typeof v === 'string') return v
53
- else if (typeof v === 'number') return v
54
- else if (typeof v === 'object' && v.constructor === Object) {
55
- if ('value' in v) {
51
+ if (typeof v !== 'object' || v === null) return v
52
+ if (v.constructor === Object) {
53
+ if ('value' in v === true) {
56
54
  return v.value
57
- } else if ('transition' in v) {
55
+ }
56
+ if ('transition' in v === true) {
58
57
  return unpackTransition(v.transition)
59
58
  }
60
59
  }
@@ -68,7 +67,7 @@ const colorMap = {
68
67
  right: 'colorRight',
69
68
  }
70
69
 
71
- let textDefaults
70
+ let textDefaults = null
72
71
 
73
72
  const propsTransformer = {
74
73
  set parent(v) {
@@ -102,9 +101,9 @@ const propsTransformer = {
102
101
  this.props['zIndex'] = v
103
102
  },
104
103
  set color(v) {
105
- if (typeof v === 'string' && v.indexOf('{') === -1) {
104
+ if (typeof v === 'string' && v.startsWith('{') === false) {
106
105
  this.props['color'] = colors.normalize(v)
107
- } else if (typeof v === 'object' || (isObjectString(v) && (v = parseToObject(v)))) {
106
+ } else if (typeof v === 'object' || (isObjectString(v) === true && (v = parseToObject(v)))) {
108
107
  this.props['color'] = 0
109
108
  Object.entries(v).forEach((color) => {
110
109
  this.props[colorMap[color[0]]] = colors.normalize(color[1])
@@ -113,31 +112,31 @@ const propsTransformer = {
113
112
  },
114
113
  set src(v) {
115
114
  this.props['src'] = v
116
- if (this.raw.get('color') === undefined) {
115
+ if (this.raw['color'] === undefined) {
117
116
  this.props['color'] = 0xffffffff
118
117
  }
119
118
  },
120
119
  set texture(v) {
121
120
  this.props['texture'] = v
122
121
 
123
- if (this.raw.get('color') === undefined && (v === null || v === undefined)) {
122
+ if (this.raw['color'] === undefined && (v === null || v === undefined)) {
124
123
  this.props['color'] = 0x00000000
125
- } else if (this.raw.get('color') === undefined) {
124
+ } else if (this.raw['color'] === undefined) {
126
125
  this.props['color'] = 0xffffffff
127
126
  }
128
127
  },
129
128
  set rtt(v) {
130
129
  this.props['rtt'] = v
131
- if (v === true && this.raw.get('color') === undefined) {
130
+ if (v === true && this.raw['color'] === undefined) {
132
131
  this.props['color'] = 0xffffffff
133
132
  }
134
133
  },
135
134
  set mount(v) {
136
- if (typeof v === 'object' || (isObjectString(v) && (v = parseToObject(v)))) {
137
- if ('x' in v) {
135
+ if (typeof v === 'object' || (isObjectString(v) === true && (v = parseToObject(v)))) {
136
+ if ('x' in v === true) {
138
137
  this.props['mountX'] = v.x
139
138
  }
140
- if ('y' in v) {
139
+ if ('y' in v === true) {
141
140
  this.props['mountY'] = v.y
142
141
  }
143
142
  } else {
@@ -146,11 +145,11 @@ const propsTransformer = {
146
145
  }
147
146
  },
148
147
  set pivot(v) {
149
- if (typeof v === 'object' || (isObjectString(v) && (v = parseToObject(v)))) {
150
- if ('x' in v) {
148
+ if (typeof v === 'object' || (isObjectString(v) === true && (v = parseToObject(v)))) {
149
+ if ('x' in v === true) {
151
150
  this.props['pivotX'] = v.x
152
151
  }
153
- if ('y' in v) {
152
+ if ('y' in v === true) {
154
153
  this.props['pivotY'] = v.y
155
154
  }
156
155
  } else {
@@ -159,11 +158,11 @@ const propsTransformer = {
159
158
  }
160
159
  },
161
160
  set scale(v) {
162
- if (typeof v === 'object' || (isObjectString(v) && (v = parseToObject(v)))) {
163
- if ('x' in v) {
161
+ if (typeof v === 'object' || (isObjectString(v) === true && (v = parseToObject(v)))) {
162
+ if ('x' in v === true) {
164
163
  this.props['scaleX'] = v.x
165
164
  }
166
- if ('y' in v) {
165
+ if ('y' in v === true) {
167
166
  this.props['scaleY'] = v.y
168
167
  }
169
168
  } else {
@@ -185,12 +184,7 @@ const propsTransformer = {
185
184
  },
186
185
  set effects(v) {
187
186
  this.props['shader'] = renderer.createShader('DynamicShader', {
188
- effects: v.map((eff) => {
189
- if (eff.props && eff.props.color) {
190
- eff.props.color = colors.normalize(eff.props.color)
191
- }
192
- return eff
193
- }),
187
+ effects: v,
194
188
  })
195
189
  },
196
190
  set clipping(v) {
@@ -238,24 +232,22 @@ const propsTransformer = {
238
232
 
239
233
  const Element = {
240
234
  populate(data) {
241
- const props = {
242
- ...this.config,
243
- ...data,
244
- }
235
+ const props = data
236
+ props['node'] = this.config.node
245
237
 
246
- if (props[symbols.isSlot]) {
238
+ if (props[symbols.isSlot] === true) {
247
239
  this[symbols.isSlot] = true
248
240
  }
249
241
 
250
242
  this.props.element = this
251
243
 
252
- const propKeys = Object.keys(props)
253
- const length = propKeys.length
254
-
255
- this.props['parent'] = props.parent
244
+ this.props['parent'] = this.config.parent
256
245
  delete props.parent
257
246
 
258
- this.props.raw = new Map(Object.entries(props))
247
+ this.props.raw = data
248
+
249
+ const propKeys = Object.keys(props)
250
+ const length = propKeys.length
259
251
 
260
252
  for (let i = 0; i < length; i++) {
261
253
  const key = propKeys[i]
@@ -266,65 +258,63 @@ const Element = {
266
258
  }
267
259
 
268
260
  // correct for default white nodes (but not for text nodes)
269
- if (this.props.props['color'] === undefined && !('__textnode' in props)) {
261
+ if (this.props.props['color'] === undefined && '__textnode' in props === false) {
270
262
  this.props.props['color'] = 0
271
263
  }
272
264
 
273
265
  this.node = props.__textnode
274
266
  ? renderer.createTextNode({ ...textDefaults, ...this.props.props })
275
- : (this.node = renderer.createNode(this.props.props))
267
+ : renderer.createNode(this.props.props)
276
268
 
277
- if (props['@loaded']) {
269
+ if (props['@loaded'] !== undefined && typeof props['@loaded'] === 'function') {
278
270
  this.node.on('loaded', (el, { type, dimensions }) => {
279
271
  props['@loaded']({ w: dimensions.width, h: dimensions.height, type }, this)
280
272
  })
281
273
  }
282
274
 
283
- if (props['@error']) {
275
+ if (props['@error'] !== undefined && typeof props['@error'] === 'function') {
284
276
  this.node.on('failed', (el, error) => {
285
277
  props['@error'](error, this)
286
278
  })
287
279
  }
288
280
 
289
- if (this.component && this.component.___layout) {
290
- this.node.on('loaded', () => {
291
- this.component.___layout()
292
- })
293
- }
281
+ // if (this.component && this.component.___layout) {
282
+ // this.node.on('loaded', () => {
283
+ // this.component.___layout()
284
+ // })
285
+ // }
294
286
  },
295
287
  set(prop, value) {
296
288
  if (value === undefined) return
297
- if (this.props.raw.get(prop) === value) return
298
-
299
- this.props.raw.set(prop, value)
289
+ if (this.props.raw[prop] === value) return
290
+ this.props.raw[prop] = value
300
291
 
301
292
  this.props.props = {}
302
293
  this.props[prop] = unpackTransition(value)
303
- const props = Object.entries(this.props.props)
304
294
 
305
- if (props.length === 1) {
306
- const [p, v] = props[0]
307
- if (isTransition(value)) {
308
- return this.animate(p, v, value.transition)
295
+ const propsKeys = Object.keys(this.props.props)
296
+
297
+ if (propsKeys.length === 1) {
298
+ if (isTransition(value) === true) {
299
+ return this.animate(propsKeys[0], this.props.props[propsKeys[0]], value.transition)
309
300
  }
310
301
  // set the prop to the value on the node
311
- this.node[p] = v
302
+ this.node[propsKeys[0]] = this.props.props[propsKeys[0]]
312
303
  } else {
313
- for (let i = 0; i < props.length; i++) {
304
+ for (let i = 0; i < propsKeys.length; i++) {
314
305
  // todo: fix code duplication
315
- const [p, v] = props[i]
316
- if (isTransition(value)) {
317
- return this.animate(p, v, value.transition)
306
+ if (isTransition(value) === true) {
307
+ return this.animate(propsKeys[i], this.props.props[propsKeys[i]], value.transition)
318
308
  }
319
309
  // set the prop to the value on the node
320
- this.node[p] = v
310
+ this.node[propsKeys[i]] = this.props.props[propsKeys[i]]
321
311
  }
322
312
  }
323
313
 
324
314
  // todo: review naming
325
- if (this.component && this.component.___layout) {
326
- this.component.___layout()
327
- }
315
+ // if (this.component && this.component.___layout) {
316
+ // this.component.___layout()
317
+ // }
328
318
  },
329
319
  animate(prop, value, transition) {
330
320
  // if current value is the same as the value to animate to, instantly resolve
@@ -409,7 +399,7 @@ const Element = {
409
399
  }
410
400
 
411
401
  export default (config, component) => {
412
- if (!textDefaults) {
402
+ if (textDefaults === null) {
413
403
  textDefaults = {
414
404
  fontSize: 32,
415
405
  fontFamily: Settings.get('defaultFont', 'sans-serif'),
@@ -0,0 +1,34 @@
1
+ /*
2
+ * If not stated otherwise in this file or this component's LICENSE file the
3
+ * following copyright and licenses apply:
4
+ *
5
+ * Copyright 2020 Metrological
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the License);
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ export default (file) => {
21
+ return new Promise((resolve, reject) => {
22
+ const xhr = new XMLHttpRequest()
23
+ xhr.onreadystatechange = function () {
24
+ if (xhr.readyState == XMLHttpRequest.DONE) {
25
+ // file protocol returns 0
26
+ // http(s) protocol returns 200
27
+ if (xhr.status === 0 || xhr.status === 200) resolve(JSON.parse(xhr.responseText))
28
+ else reject(xhr.statusText)
29
+ }
30
+ }
31
+ xhr.open('GET', file)
32
+ xhr.send(null)
33
+ })
34
+ }