@lightningjs/blits 1.4.0 → 1.4.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.4.2
4
+
5
+ _24 sept 2024_
6
+
7
+ - Fixed timing issue with calculation of percentages
8
+ - Improved check to see if object is a Blits component, so it's more robust in case of code minification
9
+
10
+ ## v1.4.1
11
+
12
+ _18 sept 2024_
13
+
14
+ - Fixed support for inspector, compatible with renderer 2.x changes
15
+
3
16
  ## v1.4.0
4
17
 
5
18
  _16 sept 2024_
@@ -24,7 +24,7 @@ It is very useful in combination with API driven Apps, where the type of Compone
24
24
  The `is`-component should always be used together with the built-in `Component`-tag.
25
25
 
26
26
  ```js
27
- export default Blits('DynamicComponents', {
27
+ export default Blits.Component('DynamicComponents', {
28
28
  template: `
29
29
  <Element>
30
30
  <Component is="$firstComponent" />
@@ -14,7 +14,7 @@ The for loop take an `Array` of data, loops over it and for each Array-item an E
14
14
  The for-loop directive should be added as an attribute on the Element or Component that you want to repeat for each item in your Array. In the template syntax a `for ... in` construct is used. This ultimately transpiles down to a classic, optimized for loop.
15
15
 
16
16
  ```js
17
- export default Blits('ForLoop', {
17
+ export default Blits.Component('ForLoop', {
18
18
  template: `
19
19
  <Element>
20
20
  <Element :for="item in $items" w="100" h="100" color="lime" />
@@ -40,7 +40,7 @@ All we need to do is declare the `index` in the `for`-directive and subsequently
40
40
  You may choose any name for the `index` variable (like `i` or `forIndex`). This may be useful when you already have the `index`-key specified as a `state` or `prop` variable on your component, causing a conflict.
41
41
 
42
42
  ```js
43
- export default Blits('ForLoop', {
43
+ export default Blits.Component('ForLoop', {
44
44
  template: `
45
45
  <Element>
46
46
  <Element :for="(item, index) in $items" w="100" h="100" color="lime" :x="$index * 150" />
@@ -64,7 +64,7 @@ When iterating over an Array in the for loop, you can reference the current Arra
64
64
  Consider the example below, that loops over an array of _Objects_, and _also_ references the `alpha` state variable.
65
65
 
66
66
  ```js
67
- export default Blits('ForLoop', {
67
+ export default Blits.Component('ForLoop', {
68
68
  template: `
69
69
  <Element>
70
70
  <Element
@@ -113,7 +113,7 @@ It's important that the `key`-attribute is _unique_ for each Array item. Also be
113
113
 
114
114
 
115
115
  ```js
116
- export default Blits('ForLoop', {
116
+ export default Blits.Component('ForLoop', {
117
117
  template: `
118
118
  <Element>
119
119
  <Element
@@ -13,7 +13,7 @@ You can reference your Component's methods in the template by using a `$`-sign (
13
13
  In the javascript code of a Component, you can reference methods directly on the `this`-scope (i.e. `this.getData()`). Similar to `internal` state and `props`, there is no need to prefix with `methods`, for easy access.
14
14
 
15
15
  ```js
16
- export default Blits('Carousel', {
16
+ export default Blits.Component('Carousel', {
17
17
  template: `
18
18
  <Element>
19
19
  <!-- .... -->
@@ -35,7 +35,7 @@ A basic Blits component will then look something like this:
35
35
 
36
36
  ```js
37
37
  // src/components/Loader.js
38
- export default Blits('Loader', {
38
+ export default Blits.Component('Loader', {
39
39
  template: `
40
40
  <Element x="880" y="500" :show="$active">
41
41
  <Element x="$offset" w="40" h="40" color="#94a3b8" :alpha="$alpha" />
@@ -75,7 +75,7 @@ Again, you can use "normal" notation for the colors (like hexadecimal or rgba) a
75
75
  ```xml
76
76
  <Element w="200" h="200" color="{top: 'red', bottom: 'blue'}" />
77
77
  <Element w="200" h="200" color="{left: 'rgba(255,255,255,.5)', right: '#000'}" />
78
- <Element w="200" h="200" color="{left: '#aaa333', top: 'aqua', bottom: rgb(255,100,20)'}" />
78
+ <Element w="200" h="200" color="{left: '#aaa333', top: 'aqua', 'bottom: rgb(255,100,20)'}" />
79
79
  <Element w="200" h="200" color="{bottom: 'black'}" />
80
80
  ```
81
81
 
@@ -6,7 +6,7 @@ been rather static so far.
6
6
  We did learn how to _reactively_ changes values and trigger rerenders based on that. So if you try the example below, you'll see that indeed our golden element changes position. But it just jumps from one place to another:
7
7
 
8
8
  ```js
9
- export default Blits('Gold', {
9
+ export default Blits.Component('Gold', {
10
10
  template: `
11
11
  <Element color="gold" w="100" h="100" :x="$x" :y="$y" />
12
12
  `,
@@ -31,7 +31,7 @@ Using _transitions_ we really make our App come alive.
31
31
  Blits offers an easy and intuitive way to apply transitions. All you need to do is add the `.transition` modifier to a reactive attribute, and now whenever you change the value referenced in the attribute, it will automatically _smooth_ into the new value.
32
32
 
33
33
  ```js
34
- export default Blits('Gold', {
34
+ export default Blits.Component('Gold', {
35
35
  template: `
36
36
  <Element color="gold" w="100" h="100" :x.transition="$x" :y.transition="$y" />
37
37
  `,
@@ -111,7 +111,7 @@ You can easily hook into these transition events by adding a `start` and `end` k
111
111
  The `start` function will be called when the transition actually starts (after a possible specified delay) and the `end` function is called as soon as the transition is finished.
112
112
 
113
113
  ```js
114
- export default Blits('Gold', {
114
+ export default Blits.Component('Gold', {
115
115
  template: `
116
116
  <Element color="gold" w="100" h="100"
117
117
  :x.transition="{value: $x, start: $transitionBegin, end: $transitionEnd}"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightningjs/blits",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "Blits: The Lightning 3 App Development Framework",
5
5
  "bin": "bin/index.js",
6
6
  "exports": {
package/src/component.js CHANGED
@@ -260,6 +260,9 @@ const Component = (name = required('name'), config = required('config')) => {
260
260
  // during the code generation step
261
261
  factory.config = config
262
262
 
263
+ // To determine whether dynamic component is actual Blits component or not
264
+ factory[symbols.isComponent] = true
265
+
263
266
  return factory
264
267
  }
265
268
 
@@ -86,7 +86,10 @@ export default () =>
86
86
  if (!component4) {
87
87
  throw new Error('Component "Sprite" not found')
88
88
  }
89
- } else if (typeof componentType === 'function' && componentType.name === 'factory') {
89
+ } else if (
90
+ typeof componentType === 'function' &&
91
+ componentType[Symbol.for('isComponent')] === true
92
+ ) {
90
93
  component4 = componentType
91
94
  }
92
95
 
@@ -149,7 +152,10 @@ export default () =>
149
152
  if (!component7) {
150
153
  throw new Error('Component "Sprite" not found')
151
154
  }
152
- } else if (typeof componentType === 'function' && componentType.name === 'factory') {
155
+ } else if (
156
+ typeof componentType === 'function' &&
157
+ componentType[Symbol.for('isComponent')] === true
158
+ ) {
153
159
  component7 = componentType
154
160
  }
155
161
 
@@ -203,7 +209,10 @@ export default () =>
203
209
  if (!component9) {
204
210
  throw new Error('Component "Sprite" not found')
205
211
  }
206
- } else if (typeof componentType === 'function' && componentType.name === 'factory') {
212
+ } else if (
213
+ typeof componentType === 'function' &&
214
+ componentType[Symbol.for('isComponent')] === true
215
+ ) {
207
216
  component9 = componentType
208
217
  }
209
218
 
@@ -257,7 +266,10 @@ export default () =>
257
266
  if (!component11) {
258
267
  throw new Error('Component "Sprite" not found')
259
268
  }
260
- } else if (typeof componentType === 'function' && componentType.name === 'factory') {
269
+ } else if (
270
+ typeof componentType === 'function' &&
271
+ componentType[Symbol.for('isComponent')] === true
272
+ ) {
261
273
  component11 = componentType
262
274
  }
263
275
 
@@ -319,7 +331,10 @@ export default () =>
319
331
  if (!component14) {
320
332
  throw new Error('Component "Sprite" not found')
321
333
  }
322
- } else if (typeof componentType === 'function' && componentType.name === 'factory') {
334
+ } else if (
335
+ typeof componentType === 'function' &&
336
+ componentType[Symbol.for('isComponent')] === true
337
+ ) {
323
338
  component14 = componentType
324
339
  }
325
340
 
@@ -382,7 +397,10 @@ export default () =>
382
397
  if (!component17) {
383
398
  throw new Error('Component "Sprite" not found')
384
399
  }
385
- } else if (typeof componentType === 'function' && componentType.name === 'factory') {
400
+ } else if (
401
+ typeof componentType === 'function' &&
402
+ componentType[Symbol.for('isComponent')] === true
403
+ ) {
386
404
  component17 = componentType
387
405
  }
388
406
 
@@ -436,7 +454,10 @@ export default () =>
436
454
  if (!component19) {
437
455
  throw new Error('Component "Sprite" not found')
438
456
  }
439
- } else if (typeof componentType === 'function' && componentType.name === 'factory') {
457
+ } else if (
458
+ typeof componentType === 'function' &&
459
+ componentType[Symbol.for('isComponent')] === true
460
+ ) {
440
461
  component19 = componentType
441
462
  }
442
463
 
@@ -490,7 +511,10 @@ export default () =>
490
511
  if (!component21) {
491
512
  throw new Error('Component "Sprite" not found')
492
513
  }
493
- } else if (typeof componentType === 'function' && componentType.name === 'factory') {
514
+ } else if (
515
+ typeof componentType === 'function' &&
516
+ componentType[Symbol.for('isComponent')] === true
517
+ ) {
494
518
  component21 = componentType
495
519
  }
496
520
 
@@ -553,7 +577,10 @@ export default () =>
553
577
  if (!component24) {
554
578
  throw new Error('Component "Sprite" not found')
555
579
  }
556
- } else if (typeof componentType === 'function' && componentType.name === 'factory') {
580
+ } else if (
581
+ typeof componentType === 'function' &&
582
+ componentType[Symbol.for('isComponent')] === true
583
+ ) {
557
584
  component24 = componentType
558
585
  }
559
586
 
@@ -616,7 +643,10 @@ export default () =>
616
643
  if (!component27) {
617
644
  throw new Error('Component "Sprite" not found')
618
645
  }
619
- } else if (typeof componentType === 'function' && componentType.name === 'factory') {
646
+ } else if (
647
+ typeof componentType === 'function' &&
648
+ componentType[Symbol.for('isComponent')] === true
649
+ ) {
620
650
  component27 = componentType
621
651
  }
622
652
 
@@ -670,7 +700,10 @@ export default () =>
670
700
  if (!component29) {
671
701
  throw new Error('Component "Sprite" not found')
672
702
  }
673
- } else if (typeof componentType === 'function' && componentType.name === 'factory') {
703
+ } else if (
704
+ typeof componentType === 'function' &&
705
+ componentType[Symbol.for('isComponent')] === true
706
+ ) {
674
707
  component29 = componentType
675
708
  }
676
709
 
@@ -724,7 +757,10 @@ export default () =>
724
757
  if (!component31) {
725
758
  throw new Error('Component "Sprite" not found')
726
759
  }
727
- } else if (typeof componentType === 'function' && componentType.name === 'factory') {
760
+ } else if (
761
+ typeof componentType === 'function' &&
762
+ componentType[Symbol.for('isComponent')] === true
763
+ ) {
728
764
  component31 = componentType
729
765
  }
730
766
 
@@ -785,7 +821,10 @@ export default () =>
785
821
  if (!component34) {
786
822
  throw new Error('Component "Sprite" not found')
787
823
  }
788
- } else if (typeof componentType === 'function' && componentType.name === 'factory') {
824
+ } else if (
825
+ typeof componentType === 'function' &&
826
+ componentType[Symbol.for('isComponent')] === true
827
+ ) {
789
828
  component34 = componentType
790
829
  }
791
830
 
@@ -848,7 +887,10 @@ export default () =>
848
887
  if (!component37) {
849
888
  throw new Error('Component "Sprite" not found')
850
889
  }
851
- } else if (typeof componentType === 'function' && componentType.name === 'factory') {
890
+ } else if (
891
+ typeof componentType === 'function' &&
892
+ componentType[Symbol.for('isComponent')] === true
893
+ ) {
852
894
  component37 = componentType
853
895
  }
854
896
 
@@ -902,7 +944,10 @@ export default () =>
902
944
  if (!component39) {
903
945
  throw new Error('Component "Sprite" not found')
904
946
  }
905
- } else if (typeof componentType === 'function' && componentType.name === 'factory') {
947
+ } else if (
948
+ typeof componentType === 'function' &&
949
+ componentType[Symbol.for('isComponent')] === true
950
+ ) {
906
951
  component39 = componentType
907
952
  }
908
953
 
@@ -956,7 +1001,10 @@ export default () =>
956
1001
  if (!component41) {
957
1002
  throw new Error('Component "Sprite" not found')
958
1003
  }
959
- } else if (typeof componentType === 'function' && componentType.name === 'factory') {
1004
+ } else if (
1005
+ typeof componentType === 'function' &&
1006
+ componentType[Symbol.for('isComponent')] === true
1007
+ ) {
960
1008
  component41 = componentType
961
1009
  }
962
1010
 
@@ -39,9 +39,9 @@ const parsePercentage = function (v, base) {
39
39
  return v
40
40
  } else if (v.indexOf('%') === v.length - 1) {
41
41
  return (
42
- this.element.parent &&
43
- this.element.parent[base] &&
44
- this.element.parent[base] * (parseFloat(v) / 100)
42
+ (this.element.config.parent &&
43
+ (this.element.config.parent.node[base] || 0) * (parseFloat(v) / 100)) ||
44
+ 0
45
45
  )
46
46
  }
47
47
  return v
@@ -18,6 +18,7 @@
18
18
  import { RendererMain } from '@lightningjs/renderer'
19
19
  import { WebGlCoreRenderer, SdfTextRenderer } from '@lightningjs/renderer/webgl'
20
20
  import { CanvasCoreRenderer, CanvasTextRenderer } from '@lightningjs/renderer/canvas'
21
+ import { Inspector } from '@lightningjs/renderer/inspector'
21
22
 
22
23
  import { Log } from '../../lib/log.js'
23
24
  import { SCREEN_RESOLUTIONS } from '../../constants.js'
@@ -50,7 +51,7 @@ export default (App, target, settings = {}) => {
50
51
  ? settings.webWorkersLimit
51
52
  : window.navigator.hardwareConcurrency || 2,
52
53
  clearColor: (settings.canvasColor && colors.normalize(settings.canvasColor)) || 0x00000000,
53
- enableInspector: settings.inspector || false,
54
+ inspector: settings.inspector === true ? Inspector : undefined,
54
55
  boundsMargin: settings.viewportMargin || 0,
55
56
  // gpu memory limit, converted from mb to bytes - defaults to 200mb
56
57
  txMemByteThreshold:
@@ -234,7 +234,7 @@ const generateComponentCode = function (
234
234
  if(!component${counter}) {
235
235
  throw new Error('Component "${templateObject[Symbol.for('componentType')]}" not found')
236
236
  }
237
- } else if(typeof componentType === 'function' && componentType.name === 'factory') {
237
+ } else if(typeof componentType === 'function' && componentType[Symbol.for('isComponent')] === true) {
238
238
  component${counter} = componentType
239
239
  }
240
240
 
@@ -44,4 +44,6 @@ export default {
44
44
  slots: Symbol.for('slots'),
45
45
  // Symbol 'componentType' utilized within generated code
46
46
  componentType: Symbol.for('componentType'),
47
+ // Symbol 'isComponent' utilized within generated code
48
+ isComponent: Symbol.for('isComponent'),
47
49
  }