@lightningjs/blits 1.30.1 → 1.30.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.
Files changed (149) hide show
  1. package/.editorconfig +7 -7
  2. package/.eslintignore +1 -1
  3. package/.eslintrc.cjs +65 -65
  4. package/.github/workflows/comment-lint-results.yml +124 -124
  5. package/.github/workflows/comment-test-results.yml +108 -108
  6. package/.github/workflows/deploy-docs.yml +27 -27
  7. package/.github/workflows/run-blits-tests.yml +141 -141
  8. package/.github/workflows/run-lint.yml +127 -127
  9. package/.husky/pre-commit +1 -1
  10. package/.vscode/extensions.json +7 -7
  11. package/.vscode/settings.json +9 -9
  12. package/CHANGELOG.md +1019 -1012
  13. package/COPYING +1 -0
  14. package/LICENSE +202 -202
  15. package/NOTICE +12 -12
  16. package/README.md +33 -33
  17. package/bin/index.js +8 -8
  18. package/blits.d.ts +6 -6
  19. package/docs/README.md +19 -19
  20. package/docs/_sidebar.md +37 -37
  21. package/docs/built-in/directives.md +50 -50
  22. package/docs/built-in/for-loop.md +203 -203
  23. package/docs/built-in/layout.md +168 -168
  24. package/docs/components/component_state.md +90 -90
  25. package/docs/components/computed_properties.md +45 -45
  26. package/docs/components/lifecycle_events.md +42 -42
  27. package/docs/components/methods.md +45 -45
  28. package/docs/components/props.md +56 -56
  29. package/docs/components/user_input.md +186 -186
  30. package/docs/components/utility_methods.md +320 -320
  31. package/docs/components/watchers.md +34 -34
  32. package/docs/essentials/application_root.md +19 -19
  33. package/docs/essentials/components.md +68 -68
  34. package/docs/essentials/displaying_images.md +67 -67
  35. package/docs/essentials/displaying_text.md +135 -135
  36. package/docs/essentials/element_attributes.md +195 -195
  37. package/docs/essentials/settings.md +117 -117
  38. package/docs/essentials/template_syntax.md +83 -83
  39. package/docs/getting_started/file_structure.md +58 -58
  40. package/docs/getting_started/getting_started.md +45 -45
  41. package/docs/getting_started/intro.md +20 -20
  42. package/docs/index.html +47 -47
  43. package/docs/performance/lazy-loading.md +161 -161
  44. package/docs/plugins/global_app_state.md +98 -98
  45. package/docs/plugins/language.md +172 -172
  46. package/docs/plugins/text-to-speech-announcer.md +119 -119
  47. package/docs/plugins/theme.md +176 -176
  48. package/docs/router/basics.md +175 -175
  49. package/docs/router/hooks.md +70 -70
  50. package/docs/router/transitions.md +146 -146
  51. package/docs/sidebar.json +171 -171
  52. package/docs/transitions_animations/transitions.md +150 -150
  53. package/index.d.ts +1099 -1099
  54. package/index.js +28 -28
  55. package/jsconfig.json +12 -12
  56. package/package.json +56 -56
  57. package/public/assets/fps_sprite.base64.js +1 -1
  58. package/scripts/postpublish.js +59 -59
  59. package/scripts/prepublishOnly.js +84 -84
  60. package/scripts/prepush.js +78 -78
  61. package/src/announcer/announcer.js +162 -162
  62. package/src/announcer/speechSynthesis.js +107 -107
  63. package/src/application.js +100 -100
  64. package/src/component/base/announcer.js +27 -27
  65. package/src/component/base/events.js +69 -69
  66. package/src/component/base/index.js +33 -33
  67. package/src/component/base/methods.js +244 -244
  68. package/src/component/base/router.js +41 -41
  69. package/src/component/base/timeouts_intervals.js +99 -99
  70. package/src/component/base/utils.js +72 -72
  71. package/src/component/setup/computed.js +48 -48
  72. package/src/component/setup/index.js +62 -62
  73. package/src/component/setup/input.js +30 -30
  74. package/src/component/setup/methods.js +37 -37
  75. package/src/component/setup/props.js +62 -62
  76. package/src/component/setup/props.test.js +238 -238
  77. package/src/component/setup/routes.js +42 -42
  78. package/src/component/setup/state.js +59 -59
  79. package/src/component/setup/watch.js +35 -35
  80. package/src/component.js +437 -437
  81. package/src/component.test.js +388 -388
  82. package/src/components/Circle.js +73 -73
  83. package/src/components/Circle.orig.js +31 -31
  84. package/src/components/FPScounter.js +1510 -1510
  85. package/src/components/FPScounter.orig.js +121 -121
  86. package/src/components/RouterView.js +81 -81
  87. package/src/components/RouterView.orig.js +54 -54
  88. package/src/components/Sprite.js +94 -94
  89. package/src/components/Sprite.orig.js +58 -58
  90. package/src/components/index.js +28 -28
  91. package/src/components/index.orig.js +28 -28
  92. package/src/constants.js +21 -21
  93. package/src/engine.js +1 -1
  94. package/src/engines/L3/element.js +744 -744
  95. package/src/engines/L3/element.test.js +579 -579
  96. package/src/engines/L3/fontLoader.js +38 -38
  97. package/src/engines/L3/index.js +7 -7
  98. package/src/engines/L3/launch.js +123 -123
  99. package/src/engines/L3/shaderLoader.js +12 -12
  100. package/src/engines/index.js +1 -1
  101. package/src/focus.js +90 -90
  102. package/src/helpers/deepEqualArray.js +50 -50
  103. package/src/helpers/deepEqualArray.test.js +127 -127
  104. package/src/helpers/fetchJson.js +34 -34
  105. package/src/helpers/sequence.js +26 -26
  106. package/src/launch.js +123 -123
  107. package/src/lib/blitsfileconverter/blitsfileconverter.js +52 -52
  108. package/src/lib/codegenerator/generator.js +788 -788
  109. package/src/lib/codegenerator/generator.test.js +3801 -3801
  110. package/src/lib/colors/colors.js +92 -92
  111. package/src/lib/colors/colors.test.js +290 -290
  112. package/src/lib/colors/htmlColors.js +168 -168
  113. package/src/lib/componentId.js +49 -49
  114. package/src/lib/componentId.test.js +84 -84
  115. package/src/lib/eventListeners.js +123 -123
  116. package/src/lib/eventListeners.test.js +236 -236
  117. package/src/lib/hooks.js +59 -59
  118. package/src/lib/lifecycle.js +85 -85
  119. package/src/lib/log.js +117 -117
  120. package/src/lib/precompiler/precompiler.js +73 -73
  121. package/src/lib/reactivity/effect.js +93 -93
  122. package/src/lib/reactivity/effect.test.js +35 -35
  123. package/src/lib/reactivity/reactive.js +208 -208
  124. package/src/lib/reactivity/reactive.test.js +27 -27
  125. package/src/lib/reactivityguard/computedprops.js +218 -218
  126. package/src/lib/symbols.js +108 -108
  127. package/src/lib/templateparser/parser.js +386 -386
  128. package/src/lib/templateparser/parser.test.js +1411 -1411
  129. package/src/lib/utils.js +27 -27
  130. package/src/plugin.js +27 -27
  131. package/src/plugins/appstate.js +26 -26
  132. package/src/plugins/index.js +20 -20
  133. package/src/plugins/language.js +152 -152
  134. package/src/plugins/log.js +25 -25
  135. package/src/plugins/theme.js +94 -94
  136. package/src/router/router.js +514 -514
  137. package/src/router/router.test.js +473 -473
  138. package/src/router/transitions/fadeIn.js +27 -27
  139. package/src/router/transitions/fadeInOut.js +33 -33
  140. package/src/router/transitions/index.js +21 -21
  141. package/src/router/transitions/slideIn.js +28 -28
  142. package/src/router/transitions/slideInOut.js +33 -33
  143. package/src/settings.js +40 -40
  144. package/vite/blitsFileConverter.js +67 -67
  145. package/vite/index.js +28 -28
  146. package/vite/msdfGenerator.js +269 -269
  147. package/vite/preCompiler.js +42 -42
  148. package/vite/reactivityGuard.js +45 -45
  149. package/vscode/data/template-attributes.json +589 -589
@@ -1,34 +1,34 @@
1
- # Watchers
2
-
3
- In some cases, you may want to execute specific actions whenever the value of a state variable, a prop, or a computed property changes. These actions could involve dispatching an event or updating another state variable.
4
-
5
- You might be tempted to handle this functionality inside a computed property, but this is not recommended. Computed properties should not have side effects, to prevent the risk of falling into an endless loop.
6
-
7
- Instead, Blits allows you to specify **watchers** to trigger functionality when certain variables change.
8
-
9
- ## Using Watchers
10
-
11
- Within the `watch` key of the _Component configuration object_, you can define an object of _watcher functions_.
12
-
13
- The name of each function should correspond with the name of the state variable, the prop, or the computed property that you want to observe. Whenever the value of the observed target changes, the respective watcher function will be invoked.
14
-
15
- The watcher function receives two arguments: the _new value_ and the _old value_ of the observed property. This allows you to perform specific actions based on the changes.
16
-
17
- ```javascript
18
- {
19
- state() {
20
- return {
21
- alpha: 0.2
22
- }
23
- },
24
- watch: {
25
- alpha(value, oldValue) {
26
- if(value > oldValue) {
27
- // Execute some logic when the 'alpha' value increases
28
- }
29
- },
30
- }
31
- }
32
- ```
33
-
34
- In this example, whenever the value of state variable `alpha` changes, the `alpha` watcher function will be invoked. The function checks if the new value is greater than the old value and executes custom logic accordingly.
1
+ # Watchers
2
+
3
+ In some cases, you may want to execute specific actions whenever the value of a state variable, a prop, or a computed property changes. These actions could involve dispatching an event or updating another state variable.
4
+
5
+ You might be tempted to handle this functionality inside a computed property, but this is not recommended. Computed properties should not have side effects, to prevent the risk of falling into an endless loop.
6
+
7
+ Instead, Blits allows you to specify **watchers** to trigger functionality when certain variables change.
8
+
9
+ ## Using Watchers
10
+
11
+ Within the `watch` key of the _Component configuration object_, you can define an object of _watcher functions_.
12
+
13
+ The name of each function should correspond with the name of the state variable, the prop, or the computed property that you want to observe. Whenever the value of the observed target changes, the respective watcher function will be invoked.
14
+
15
+ The watcher function receives two arguments: the _new value_ and the _old value_ of the observed property. This allows you to perform specific actions based on the changes.
16
+
17
+ ```javascript
18
+ {
19
+ state() {
20
+ return {
21
+ alpha: 0.2
22
+ }
23
+ },
24
+ watch: {
25
+ alpha(value, oldValue) {
26
+ if(value > oldValue) {
27
+ // Execute some logic when the 'alpha' value increases
28
+ }
29
+ },
30
+ }
31
+ }
32
+ ```
33
+
34
+ In this example, whenever the value of state variable `alpha` changes, the `alpha` watcher function will be invoked. The function checks if the new value is greater than the old value and executes custom logic accordingly.
@@ -1,19 +1,19 @@
1
- # Application root
2
-
3
- Every Blits App starts with a base Application component.
4
-
5
- Ultimately this Application is a component like any regular Blits component. But it is augmented with some extra functionality. `Blits.Application` is responsible for setting up the listeners for keyhandling for example.
6
-
7
- You can only have 1 Application component per App. By default, this file is named `App.js` and it is placed in the root of the `src`-folder.
8
-
9
- `src/App.js` will look something like this:
10
-
11
- ```js
12
- import Blits from '@lightningjs/blits'
13
-
14
- export default Blits.Application({
15
- template: `
16
- <Element></Element>
17
- `,
18
- })
19
- ```
1
+ # Application root
2
+
3
+ Every Blits App starts with a base Application component.
4
+
5
+ Ultimately this Application is a component like any regular Blits component. But it is augmented with some extra functionality. `Blits.Application` is responsible for setting up the listeners for keyhandling for example.
6
+
7
+ You can only have 1 Application component per App. By default, this file is named `App.js` and it is placed in the root of the `src`-folder.
8
+
9
+ `src/App.js` will look something like this:
10
+
11
+ ```js
12
+ import Blits from '@lightningjs/blits'
13
+
14
+ export default Blits.Application({
15
+ template: `
16
+ <Element></Element>
17
+ `,
18
+ })
19
+ ```
@@ -1,68 +1,68 @@
1
- # Components
2
-
3
- Like any modern front-end framework, Blits is built around the concept of Components. Components allow you to split the UI of your App into
4
- reusable pieces of code and logic.
5
-
6
- As you get started building your App, you're free to put all your elements and logic right in the root Application component.
7
- This is great for quickly playing around with Blits and Lightning.
8
-
9
- But soon you'll find that it's beneficial to start organizing the different parts of your App into separate components. Blits Components can be nested into a tree of components.
10
-
11
- Components in Blits follow a clearly defined structure, which helps keep your code clean and guides you to quickly build your components.
12
-
13
- This universal structure is also valuable for creating drop-in components that can be easily shared across projects.
14
-
15
- ## Creating a new Component
16
-
17
- Let's see how to create a new component and explore the basic anatomy of a component.
18
-
19
- A new component is created using the `Blits.Component()` function that is exported from the `@lightningjs/blits` package. This function accepts two arguments:
20
-
21
- - The first argument is the _name_ of the component. This name will be used in debug log messages, so make sure to choose a unique and descriptive name for your component, such as `Homepage`, `Loader`, or `SidebarMenuItem`.
22
-
23
- - The second argument is a _Component configuration object_, represented as an `object literal`. This Component configuration object can contain a predefined set of key-value pairs, that define how your Component looks and behaves.
24
-
25
- Some of the commonly used Component configuration options include:
26
-
27
- - `template`: to define the template for the component.
28
- - `state`: to specify the component instance's internal state.
29
- - `props`: to define the props that can be passed into the component.
30
- - `hooks`: allowing you to hook into different lifecycle events of the component.
31
- - `input`: used to tap into user input.
32
- - `methods`: used to define more complex functionality of the component
33
-
34
- A basic Blits component will then look something like this:
35
-
36
- ```js
37
- // src/components/Loader.js
38
- export default Blits.Component('Loader', {
39
- template: `
40
- <Element x="880" y="500" :show="$active">
41
- <Element x="$offset" w="40" h="40" color="#94a3b8" :alpha="$alpha" />
42
- </Element>
43
- `,
44
- props: ['type', 'size'],
45
- state() {
46
- return {
47
- active: false,
48
- alpha: 0.4,
49
- offset: 100
50
- }
51
- },
52
- hooks: {
53
- ready() {
54
- this.$setTimeout(() => {
55
- this.active = true
56
- }, 300)
57
- }
58
- },
59
- input: {
60
- enter() {
61
- this.alpha = 1
62
- }
63
- }
64
- })
65
- ```
66
-
67
- In the next sections, we will go into the details of each of the component configuration options.
68
-
1
+ # Components
2
+
3
+ Like any modern front-end framework, Blits is built around the concept of Components. Components allow you to split the UI of your App into
4
+ reusable pieces of code and logic.
5
+
6
+ As you get started building your App, you're free to put all your elements and logic right in the root Application component.
7
+ This is great for quickly playing around with Blits and Lightning.
8
+
9
+ But soon you'll find that it's beneficial to start organizing the different parts of your App into separate components. Blits Components can be nested into a tree of components.
10
+
11
+ Components in Blits follow a clearly defined structure, which helps keep your code clean and guides you to quickly build your components.
12
+
13
+ This universal structure is also valuable for creating drop-in components that can be easily shared across projects.
14
+
15
+ ## Creating a new Component
16
+
17
+ Let's see how to create a new component and explore the basic anatomy of a component.
18
+
19
+ A new component is created using the `Blits.Component()` function that is exported from the `@lightningjs/blits` package. This function accepts two arguments:
20
+
21
+ - The first argument is the _name_ of the component. This name will be used in debug log messages, so make sure to choose a unique and descriptive name for your component, such as `Homepage`, `Loader`, or `SidebarMenuItem`.
22
+
23
+ - The second argument is a _Component configuration object_, represented as an `object literal`. This Component configuration object can contain a predefined set of key-value pairs, that define how your Component looks and behaves.
24
+
25
+ Some of the commonly used Component configuration options include:
26
+
27
+ - `template`: to define the template for the component.
28
+ - `state`: to specify the component instance's internal state.
29
+ - `props`: to define the props that can be passed into the component.
30
+ - `hooks`: allowing you to hook into different lifecycle events of the component.
31
+ - `input`: used to tap into user input.
32
+ - `methods`: used to define more complex functionality of the component
33
+
34
+ A basic Blits component will then look something like this:
35
+
36
+ ```js
37
+ // src/components/Loader.js
38
+ export default Blits.Component('Loader', {
39
+ template: `
40
+ <Element x="880" y="500" :show="$active">
41
+ <Element x="$offset" w="40" h="40" color="#94a3b8" :alpha="$alpha" />
42
+ </Element>
43
+ `,
44
+ props: ['type', 'size'],
45
+ state() {
46
+ return {
47
+ active: false,
48
+ alpha: 0.4,
49
+ offset: 100
50
+ }
51
+ },
52
+ hooks: {
53
+ ready() {
54
+ this.$setTimeout(() => {
55
+ this.active = true
56
+ }, 300)
57
+ }
58
+ },
59
+ input: {
60
+ enter() {
61
+ this.alpha = 1
62
+ }
63
+ }
64
+ })
65
+ ```
66
+
67
+ In the next sections, we will go into the details of each of the component configuration options.
68
+
@@ -1,67 +1,67 @@
1
- # Displaying Images
2
-
3
- Now that we've covered the basics of creating Elements, as well as styling and positioning them, it's time to move away from these boring rectangles and explore how you can incorporate _images_ into your App.
4
-
5
- In Blits, it is very easy to display an image. Simply add the `src` attribute to an Element, specifying the image's location.
6
-
7
- For local images, make sure to place them in the `public` folder of your App (e.g., `public/assets/background.jpg` or `public/images/logo.png`) and refer to them with a _relative_ path (but omitting the `public` folder as root).
8
-
9
- Remote images are also supported and can be linked directly (e.g., `http://mycdn.com/artists/jimi_hendrix/woodstock.jpg`).
10
-
11
- ```xml
12
- <Element src="images/logo.png" w="100" h="80" />
13
- <Element src="http://mycdn.com/artists/jimi_hendrix/woodstock.jpg" w="1920" h="1080" />
14
- ```
15
-
16
- ## Sizing and Scaling
17
-
18
- Make sure to give your Element a width (`w` ) and a height (`h`) attribute. Images will _not_ be rendered if they don't have both attributes present. The Lightning renderer will scale the image to fit these exact dimensions.
19
-
20
- For the best performance, it's important to keep your source images as small as possible. If you're displaying an image at `200px x 200px`, make sure the image is exactly that size or _smaller_. The latter option may lead to some quality loss, but can positively impact the overall performance of your App.
21
-
22
- ## Colorization
23
-
24
- You also have the option to _colorize_ an image on the fly. Just add a `color` attribute to the Element with a `src` attribute. You can use a single color, or apply a gradient.
25
-
26
- By default, all Elements with a `src` attribute get a solid white background, with the result that the actual colors of the image will be shown.
27
-
28
- ```xml
29
- <Element
30
- w="200"
31
- h="300"
32
- :src="$src"
33
- color="{top: '#fff', bottom: '#000'}"
34
- />
35
- ```
36
-
37
- ## Asynchronous Loading
38
-
39
- All images are loaded asynchronously (and can possibly fail to load), even those local to your App. Blits allows you to easily hook into the `loaded` and `error` events of image Elements.
40
-
41
- You can use this, for example, to only make something visible once an image is fully loaded. Or to display a fallback image when a remote image can't be retrieved.
42
-
43
- ```xml
44
- <Element src="http://mycdn.com/lightning.jpg" @loaded="$revealPage" @error="$showFallback" />
45
- ```
46
-
47
- > Note how events are prefixed with a `@` sign.
48
-
49
- Considering the template above you would do something like the following in the `methods` key of your Component configuration object:
50
-
51
- ```js
52
- {
53
- //...
54
- methods: {
55
- revealPage(dimensions) {
56
- this.$log.info('Image dimensions', dimensions.w, dimensions.h)
57
- this.show = true
58
- },
59
- showFallback(error) {
60
- this.$log.error('Image failed to load', error)
61
- this.showBackupImage()
62
- }
63
- }
64
- }
65
- ```
66
-
67
- The `loaded` event receives image dimensions as its argument and the `error` event receives an error message explaining the failure.
1
+ # Displaying Images
2
+
3
+ Now that we've covered the basics of creating Elements, as well as styling and positioning them, it's time to move away from these boring rectangles and explore how you can incorporate _images_ into your App.
4
+
5
+ In Blits, it is very easy to display an image. Simply add the `src` attribute to an Element, specifying the image's location.
6
+
7
+ For local images, make sure to place them in the `public` folder of your App (e.g., `public/assets/background.jpg` or `public/images/logo.png`) and refer to them with a _relative_ path (but omitting the `public` folder as root).
8
+
9
+ Remote images are also supported and can be linked directly (e.g., `http://mycdn.com/artists/jimi_hendrix/woodstock.jpg`).
10
+
11
+ ```xml
12
+ <Element src="images/logo.png" w="100" h="80" />
13
+ <Element src="http://mycdn.com/artists/jimi_hendrix/woodstock.jpg" w="1920" h="1080" />
14
+ ```
15
+
16
+ ## Sizing and Scaling
17
+
18
+ Make sure to give your Element a width (`w` ) and a height (`h`) attribute. Images will _not_ be rendered if they don't have both attributes present. The Lightning renderer will scale the image to fit these exact dimensions.
19
+
20
+ For the best performance, it's important to keep your source images as small as possible. If you're displaying an image at `200px x 200px`, make sure the image is exactly that size or _smaller_. The latter option may lead to some quality loss, but can positively impact the overall performance of your App.
21
+
22
+ ## Colorization
23
+
24
+ You also have the option to _colorize_ an image on the fly. Just add a `color` attribute to the Element with a `src` attribute. You can use a single color, or apply a gradient.
25
+
26
+ By default, all Elements with a `src` attribute get a solid white background, with the result that the actual colors of the image will be shown.
27
+
28
+ ```xml
29
+ <Element
30
+ w="200"
31
+ h="300"
32
+ :src="$src"
33
+ color="{top: '#fff', bottom: '#000'}"
34
+ />
35
+ ```
36
+
37
+ ## Asynchronous Loading
38
+
39
+ All images are loaded asynchronously (and can possibly fail to load), even those local to your App. Blits allows you to easily hook into the `loaded` and `error` events of image Elements.
40
+
41
+ You can use this, for example, to only make something visible once an image is fully loaded. Or to display a fallback image when a remote image can't be retrieved.
42
+
43
+ ```xml
44
+ <Element src="http://mycdn.com/lightning.jpg" @loaded="$revealPage" @error="$showFallback" />
45
+ ```
46
+
47
+ > Note how events are prefixed with a `@` sign.
48
+
49
+ Considering the template above you would do something like the following in the `methods` key of your Component configuration object:
50
+
51
+ ```js
52
+ {
53
+ //...
54
+ methods: {
55
+ revealPage(dimensions) {
56
+ this.$log.info('Image dimensions', dimensions.w, dimensions.h)
57
+ this.show = true
58
+ },
59
+ showFallback(error) {
60
+ this.$log.error('Image failed to load', error)
61
+ this.showBackupImage()
62
+ }
63
+ }
64
+ }
65
+ ```
66
+
67
+ The `loaded` event receives image dimensions as its argument and the `error` event receives an error message explaining the failure.