@lightningjs/blits 0.9.9 → 0.10.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.10.0
4
+
5
+ _17 june 2024_
6
+
7
+ - Updated renderer to version v0.9.1
8
+ - Updated font generation to use the new `@lightningjs/msdf-generator`-package with required font metrics
9
+ - Added queue mechanism to font generation to prevent hanging process
10
+ - Added functionality to pass a component into the Component `:is` attribute
11
+
12
+ Please read refer to the [breaking changes](https://github.com/lightning-js/renderer/releases/tag/v0.9.0) in the
13
+ renderer related to MSDF fonts. When you have custom msdf fonts in your `/public` folder you may need to regenerate
14
+ them (or remove the files and let Blits take care of [generating for you from a `.ttf`](https://lightning-js.github.io/blits/#/essentials/displaying_text?id=using-custom-fonts))
15
+
16
+
3
17
  ## v0.9.9
4
18
 
5
19
  _22 may 2024_
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "@lightningjs/blits",
3
- "version": "0.9.9",
3
+ "version": "0.10.0",
4
4
  "description": "Blits: The Lightning 3 App Development Framework",
5
5
  "bin": "bin/index.js",
6
6
  "exports": {
7
7
  ".": "./index.js",
8
8
  "./vite": "./vite/index.js",
9
- "./fontloader": "./src/fontLoader.js",
10
9
  "./transitions": "./src/router/transitions/index.js"
11
10
  },
12
11
  "scripts": {
@@ -45,11 +44,11 @@
45
44
  "tape": "^5.5.0"
46
45
  },
47
46
  "dependencies": {
48
- "@lightningjs/renderer": "^0.8.4",
47
+ "@lightningjs/msdf-generator": "^1.0.1",
48
+ "@lightningjs/renderer": "0.9.1",
49
49
  "@lightningjs/vite-plugin-import-chunk-url": "^0.3.0",
50
50
  "execa": "^8.0.1",
51
51
  "kolorist": "^1.8.0",
52
- "msdf-bmfont-xml": "^2.7.0",
53
52
  "ora": "^7.0.1",
54
53
  "prompts": "^2.4.2",
55
54
  "replace-in-file": "^6.1.0",
@@ -96,13 +96,19 @@ export default () =>
96
96
  if (!elms[4]) {
97
97
  const componentType = props4['is'] || 'Sprite'
98
98
 
99
- elms[4] = (
100
- (context.components && context.components[componentType]) ||
101
- components[componentType] ||
102
- (() => {
103
- console.error('component Sprite not found')
104
- })
105
- ).call(null, { props: props4 }, elms[3], component)
99
+ let component4
100
+ if (typeof componentType === 'string') {
101
+ component4 =
102
+ (context.components && context.components[componentType]) || components[componentType]
103
+ if (!component4) {
104
+ throw new Error('Component "Sprite" not found')
105
+ }
106
+ } else if (typeof componentType === 'function' && componentType.name === 'factory') {
107
+ component4 = componentType
108
+ }
109
+
110
+ elms[4] = component4.call(null, { props: props4 }, elms[3], component)
111
+
106
112
  if (elms[4][Symbol.for('slots')][0]) {
107
113
  parent = elms[4][Symbol.for('slots')][0]
108
114
  component = elms[4]
@@ -162,13 +168,19 @@ export default () =>
162
168
  if (!elms[7]) {
163
169
  const componentType = props7['is'] || 'Sprite'
164
170
 
165
- elms[7] = (
166
- (context.components && context.components[componentType]) ||
167
- components[componentType] ||
168
- (() => {
169
- console.error('component Sprite not found')
170
- })
171
- ).call(null, { props: props7 }, elms[6], component)
171
+ let component7
172
+ if (typeof componentType === 'string') {
173
+ component7 =
174
+ (context.components && context.components[componentType]) || components[componentType]
175
+ if (!component7) {
176
+ throw new Error('Component "Sprite" not found')
177
+ }
178
+ } else if (typeof componentType === 'function' && componentType.name === 'factory') {
179
+ component7 = componentType
180
+ }
181
+
182
+ elms[7] = component7.call(null, { props: props7 }, elms[6], component)
183
+
172
184
  if (elms[7][Symbol.for('slots')][0]) {
173
185
  parent = elms[7][Symbol.for('slots')][0]
174
186
  component = elms[7]
@@ -214,13 +226,19 @@ export default () =>
214
226
  if (!elms[9]) {
215
227
  const componentType = props9['is'] || 'Sprite'
216
228
 
217
- elms[9] = (
218
- (context.components && context.components[componentType]) ||
219
- components[componentType] ||
220
- (() => {
221
- console.error('component Sprite not found')
222
- })
223
- ).call(null, { props: props9 }, elms[8], component)
229
+ let component9
230
+ if (typeof componentType === 'string') {
231
+ component9 =
232
+ (context.components && context.components[componentType]) || components[componentType]
233
+ if (!component9) {
234
+ throw new Error('Component "Sprite" not found')
235
+ }
236
+ } else if (typeof componentType === 'function' && componentType.name === 'factory') {
237
+ component9 = componentType
238
+ }
239
+
240
+ elms[9] = component9.call(null, { props: props9 }, elms[8], component)
241
+
224
242
  if (elms[9][Symbol.for('slots')][0]) {
225
243
  parent = elms[9][Symbol.for('slots')][0]
226
244
  component = elms[9]
@@ -266,13 +284,19 @@ export default () =>
266
284
  if (!elms[11]) {
267
285
  const componentType = props11['is'] || 'Sprite'
268
286
 
269
- elms[11] = (
270
- (context.components && context.components[componentType]) ||
271
- components[componentType] ||
272
- (() => {
273
- console.error('component Sprite not found')
274
- })
275
- ).call(null, { props: props11 }, elms[10], component)
287
+ let component11
288
+ if (typeof componentType === 'string') {
289
+ component11 =
290
+ (context.components && context.components[componentType]) || components[componentType]
291
+ if (!component11) {
292
+ throw new Error('Component "Sprite" not found')
293
+ }
294
+ } else if (typeof componentType === 'function' && componentType.name === 'factory') {
295
+ component11 = componentType
296
+ }
297
+
298
+ elms[11] = component11.call(null, { props: props11 }, elms[10], component)
299
+
276
300
  if (elms[11][Symbol.for('slots')][0]) {
277
301
  parent = elms[11][Symbol.for('slots')][0]
278
302
  component = elms[11]
@@ -332,13 +356,19 @@ export default () =>
332
356
  if (!elms[14]) {
333
357
  const componentType = props14['is'] || 'Sprite'
334
358
 
335
- elms[14] = (
336
- (context.components && context.components[componentType]) ||
337
- components[componentType] ||
338
- (() => {
339
- console.error('component Sprite not found')
340
- })
341
- ).call(null, { props: props14 }, elms[13], component)
359
+ let component14
360
+ if (typeof componentType === 'string') {
361
+ component14 =
362
+ (context.components && context.components[componentType]) || components[componentType]
363
+ if (!component14) {
364
+ throw new Error('Component "Sprite" not found')
365
+ }
366
+ } else if (typeof componentType === 'function' && componentType.name === 'factory') {
367
+ component14 = componentType
368
+ }
369
+
370
+ elms[14] = component14.call(null, { props: props14 }, elms[13], component)
371
+
342
372
  if (elms[14][Symbol.for('slots')][0]) {
343
373
  parent = elms[14][Symbol.for('slots')][0]
344
374
  component = elms[14]
@@ -398,13 +428,19 @@ export default () =>
398
428
  if (!elms[17]) {
399
429
  const componentType = props17['is'] || 'Sprite'
400
430
 
401
- elms[17] = (
402
- (context.components && context.components[componentType]) ||
403
- components[componentType] ||
404
- (() => {
405
- console.error('component Sprite not found')
406
- })
407
- ).call(null, { props: props17 }, elms[16], component)
431
+ let component17
432
+ if (typeof componentType === 'string') {
433
+ component17 =
434
+ (context.components && context.components[componentType]) || components[componentType]
435
+ if (!component17) {
436
+ throw new Error('Component "Sprite" not found')
437
+ }
438
+ } else if (typeof componentType === 'function' && componentType.name === 'factory') {
439
+ component17 = componentType
440
+ }
441
+
442
+ elms[17] = component17.call(null, { props: props17 }, elms[16], component)
443
+
408
444
  if (elms[17][Symbol.for('slots')][0]) {
409
445
  parent = elms[17][Symbol.for('slots')][0]
410
446
  component = elms[17]
@@ -450,13 +486,19 @@ export default () =>
450
486
  if (!elms[19]) {
451
487
  const componentType = props19['is'] || 'Sprite'
452
488
 
453
- elms[19] = (
454
- (context.components && context.components[componentType]) ||
455
- components[componentType] ||
456
- (() => {
457
- console.error('component Sprite not found')
458
- })
459
- ).call(null, { props: props19 }, elms[18], component)
489
+ let component19
490
+ if (typeof componentType === 'string') {
491
+ component19 =
492
+ (context.components && context.components[componentType]) || components[componentType]
493
+ if (!component19) {
494
+ throw new Error('Component "Sprite" not found')
495
+ }
496
+ } else if (typeof componentType === 'function' && componentType.name === 'factory') {
497
+ component19 = componentType
498
+ }
499
+
500
+ elms[19] = component19.call(null, { props: props19 }, elms[18], component)
501
+
460
502
  if (elms[19][Symbol.for('slots')][0]) {
461
503
  parent = elms[19][Symbol.for('slots')][0]
462
504
  component = elms[19]
@@ -502,13 +544,19 @@ export default () =>
502
544
  if (!elms[21]) {
503
545
  const componentType = props21['is'] || 'Sprite'
504
546
 
505
- elms[21] = (
506
- (context.components && context.components[componentType]) ||
507
- components[componentType] ||
508
- (() => {
509
- console.error('component Sprite not found')
510
- })
511
- ).call(null, { props: props21 }, elms[20], component)
547
+ let component21
548
+ if (typeof componentType === 'string') {
549
+ component21 =
550
+ (context.components && context.components[componentType]) || components[componentType]
551
+ if (!component21) {
552
+ throw new Error('Component "Sprite" not found')
553
+ }
554
+ } else if (typeof componentType === 'function' && componentType.name === 'factory') {
555
+ component21 = componentType
556
+ }
557
+
558
+ elms[21] = component21.call(null, { props: props21 }, elms[20], component)
559
+
512
560
  if (elms[21][Symbol.for('slots')][0]) {
513
561
  parent = elms[21][Symbol.for('slots')][0]
514
562
  component = elms[21]
@@ -569,13 +617,19 @@ export default () =>
569
617
  if (!elms[24]) {
570
618
  const componentType = props24['is'] || 'Sprite'
571
619
 
572
- elms[24] = (
573
- (context.components && context.components[componentType]) ||
574
- components[componentType] ||
575
- (() => {
576
- console.error('component Sprite not found')
577
- })
578
- ).call(null, { props: props24 }, elms[23], component)
620
+ let component24
621
+ if (typeof componentType === 'string') {
622
+ component24 =
623
+ (context.components && context.components[componentType]) || components[componentType]
624
+ if (!component24) {
625
+ throw new Error('Component "Sprite" not found')
626
+ }
627
+ } else if (typeof componentType === 'function' && componentType.name === 'factory') {
628
+ component24 = componentType
629
+ }
630
+
631
+ elms[24] = component24.call(null, { props: props24 }, elms[23], component)
632
+
579
633
  if (elms[24][Symbol.for('slots')][0]) {
580
634
  parent = elms[24][Symbol.for('slots')][0]
581
635
  component = elms[24]
@@ -635,13 +689,19 @@ export default () =>
635
689
  if (!elms[27]) {
636
690
  const componentType = props27['is'] || 'Sprite'
637
691
 
638
- elms[27] = (
639
- (context.components && context.components[componentType]) ||
640
- components[componentType] ||
641
- (() => {
642
- console.error('component Sprite not found')
643
- })
644
- ).call(null, { props: props27 }, elms[26], component)
692
+ let component27
693
+ if (typeof componentType === 'string') {
694
+ component27 =
695
+ (context.components && context.components[componentType]) || components[componentType]
696
+ if (!component27) {
697
+ throw new Error('Component "Sprite" not found')
698
+ }
699
+ } else if (typeof componentType === 'function' && componentType.name === 'factory') {
700
+ component27 = componentType
701
+ }
702
+
703
+ elms[27] = component27.call(null, { props: props27 }, elms[26], component)
704
+
645
705
  if (elms[27][Symbol.for('slots')][0]) {
646
706
  parent = elms[27][Symbol.for('slots')][0]
647
707
  component = elms[27]
@@ -687,13 +747,19 @@ export default () =>
687
747
  if (!elms[29]) {
688
748
  const componentType = props29['is'] || 'Sprite'
689
749
 
690
- elms[29] = (
691
- (context.components && context.components[componentType]) ||
692
- components[componentType] ||
693
- (() => {
694
- console.error('component Sprite not found')
695
- })
696
- ).call(null, { props: props29 }, elms[28], component)
750
+ let component29
751
+ if (typeof componentType === 'string') {
752
+ component29 =
753
+ (context.components && context.components[componentType]) || components[componentType]
754
+ if (!component29) {
755
+ throw new Error('Component "Sprite" not found')
756
+ }
757
+ } else if (typeof componentType === 'function' && componentType.name === 'factory') {
758
+ component29 = componentType
759
+ }
760
+
761
+ elms[29] = component29.call(null, { props: props29 }, elms[28], component)
762
+
697
763
  if (elms[29][Symbol.for('slots')][0]) {
698
764
  parent = elms[29][Symbol.for('slots')][0]
699
765
  component = elms[29]
@@ -739,13 +805,19 @@ export default () =>
739
805
  if (!elms[31]) {
740
806
  const componentType = props31['is'] || 'Sprite'
741
807
 
742
- elms[31] = (
743
- (context.components && context.components[componentType]) ||
744
- components[componentType] ||
745
- (() => {
746
- console.error('component Sprite not found')
747
- })
748
- ).call(null, { props: props31 }, elms[30], component)
808
+ let component31
809
+ if (typeof componentType === 'string') {
810
+ component31 =
811
+ (context.components && context.components[componentType]) || components[componentType]
812
+ if (!component31) {
813
+ throw new Error('Component "Sprite" not found')
814
+ }
815
+ } else if (typeof componentType === 'function' && componentType.name === 'factory') {
816
+ component31 = componentType
817
+ }
818
+
819
+ elms[31] = component31.call(null, { props: props31 }, elms[30], component)
820
+
749
821
  if (elms[31][Symbol.for('slots')][0]) {
750
822
  parent = elms[31][Symbol.for('slots')][0]
751
823
  component = elms[31]
@@ -804,13 +876,19 @@ export default () =>
804
876
  if (!elms[34]) {
805
877
  const componentType = props34['is'] || 'Sprite'
806
878
 
807
- elms[34] = (
808
- (context.components && context.components[componentType]) ||
809
- components[componentType] ||
810
- (() => {
811
- console.error('component Sprite not found')
812
- })
813
- ).call(null, { props: props34 }, elms[33], component)
879
+ let component34
880
+ if (typeof componentType === 'string') {
881
+ component34 =
882
+ (context.components && context.components[componentType]) || components[componentType]
883
+ if (!component34) {
884
+ throw new Error('Component "Sprite" not found')
885
+ }
886
+ } else if (typeof componentType === 'function' && componentType.name === 'factory') {
887
+ component34 = componentType
888
+ }
889
+
890
+ elms[34] = component34.call(null, { props: props34 }, elms[33], component)
891
+
814
892
  if (elms[34][Symbol.for('slots')][0]) {
815
893
  parent = elms[34][Symbol.for('slots')][0]
816
894
  component = elms[34]
@@ -870,13 +948,19 @@ export default () =>
870
948
  if (!elms[37]) {
871
949
  const componentType = props37['is'] || 'Sprite'
872
950
 
873
- elms[37] = (
874
- (context.components && context.components[componentType]) ||
875
- components[componentType] ||
876
- (() => {
877
- console.error('component Sprite not found')
878
- })
879
- ).call(null, { props: props37 }, elms[36], component)
951
+ let component37
952
+ if (typeof componentType === 'string') {
953
+ component37 =
954
+ (context.components && context.components[componentType]) || components[componentType]
955
+ if (!component37) {
956
+ throw new Error('Component "Sprite" not found')
957
+ }
958
+ } else if (typeof componentType === 'function' && componentType.name === 'factory') {
959
+ component37 = componentType
960
+ }
961
+
962
+ elms[37] = component37.call(null, { props: props37 }, elms[36], component)
963
+
880
964
  if (elms[37][Symbol.for('slots')][0]) {
881
965
  parent = elms[37][Symbol.for('slots')][0]
882
966
  component = elms[37]
@@ -922,13 +1006,19 @@ export default () =>
922
1006
  if (!elms[39]) {
923
1007
  const componentType = props39['is'] || 'Sprite'
924
1008
 
925
- elms[39] = (
926
- (context.components && context.components[componentType]) ||
927
- components[componentType] ||
928
- (() => {
929
- console.error('component Sprite not found')
930
- })
931
- ).call(null, { props: props39 }, elms[38], component)
1009
+ let component39
1010
+ if (typeof componentType === 'string') {
1011
+ component39 =
1012
+ (context.components && context.components[componentType]) || components[componentType]
1013
+ if (!component39) {
1014
+ throw new Error('Component "Sprite" not found')
1015
+ }
1016
+ } else if (typeof componentType === 'function' && componentType.name === 'factory') {
1017
+ component39 = componentType
1018
+ }
1019
+
1020
+ elms[39] = component39.call(null, { props: props39 }, elms[38], component)
1021
+
932
1022
  if (elms[39][Symbol.for('slots')][0]) {
933
1023
  parent = elms[39][Symbol.for('slots')][0]
934
1024
  component = elms[39]
@@ -974,13 +1064,19 @@ export default () =>
974
1064
  if (!elms[41]) {
975
1065
  const componentType = props41['is'] || 'Sprite'
976
1066
 
977
- elms[41] = (
978
- (context.components && context.components[componentType]) ||
979
- components[componentType] ||
980
- (() => {
981
- console.error('component Sprite not found')
982
- })
983
- ).call(null, { props: props41 }, elms[40], component)
1067
+ let component41
1068
+ if (typeof componentType === 'string') {
1069
+ component41 =
1070
+ (context.components && context.components[componentType]) || components[componentType]
1071
+ if (!component41) {
1072
+ throw new Error('Component "Sprite" not found')
1073
+ }
1074
+ } else if (typeof componentType === 'function' && componentType.name === 'factory') {
1075
+ component41 = componentType
1076
+ }
1077
+
1078
+ elms[41] = component41.call(null, { props: props41 }, elms[40], component)
1079
+
984
1080
  if (elms[41][Symbol.for('slots')][0]) {
985
1081
  parent = elms[41][Symbol.for('slots')][0]
986
1082
  component = elms[41]
@@ -16,10 +16,24 @@ export default () => {
16
16
  font.json = font.file.replace(/\.[^.]+$/, `.${font.type}.json`)
17
17
  }
18
18
  stage.fontManager.addFontFace(
19
- new SdfTrFontFace(font.family, {}, font.type, stage, font.png, font.json)
19
+ new SdfTrFontFace(font.type, {
20
+ fontFamily: font.family,
21
+ descriptors: {},
22
+ atlasUrl: font.png,
23
+ atlasDataUrl: font.json,
24
+ stage,
25
+ metrics: font.metrics,
26
+ })
20
27
  )
21
28
  } else if (font.type === 'web') {
22
- stage.fontManager.addFontFace(new WebTrFontFace(font.family, {}, font.file))
29
+ stage.fontManager.addFontFace(
30
+ new WebTrFontFace({
31
+ fontFamily: font.family,
32
+ fontUrl: font.file,
33
+ descriptors: {},
34
+ metrics: font.metrics,
35
+ })
36
+ )
23
37
  }
24
38
  })
25
39
  }
@@ -175,9 +175,18 @@ const generateComponentCode = function (
175
175
  templateObject[Symbol.for('componentType')]
176
176
  }'
177
177
 
178
- ${elm} = (context.components && context.components[componentType] || components[componentType] || (() => { console.error('component ${
179
- templateObject[Symbol.for('componentType')]
180
- } not found')})).call(null, {props: props${counter}}, ${parent}, component)
178
+ let component${counter}
179
+ if(typeof componentType === 'string') {
180
+ component${counter} = context.components && context.components[componentType] || components[componentType]
181
+ if(!component${counter}) {
182
+ throw new Error('Component "${templateObject[Symbol.for('componentType')]}" not found')
183
+ }
184
+ } else if(typeof componentType === 'function' && componentType.name === 'factory') {
185
+ component${counter} = componentType
186
+ }
187
+
188
+ ${elm} = component${counter}.call(null, {props: props${counter}}, ${parent}, component)
189
+
181
190
  if (${elm}[Symbol.for('slots')][0]) {
182
191
  parent = ${elm}[Symbol.for('slots')][0]
183
192
  component = ${elm}