@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,195 +1,195 @@
1
- # Supported Element attributes
2
-
3
- The core building block of a Blits template is the `<Element>`-tag. The Element tag corresponds directly to a node in the Lightning 3 Renderer. You can style and position Elements via _attributes_, much like you would do in plain HTML.
4
-
5
- Blits Elements have a specific set of attributes that can be used. The available attributes are loosely modeled after the properties of a Lightning 3 renderer node. In certain cases, Blits provides more developer friendly names or accepts a wider range of values, and transparently takes care of the translation into L3 renderer instructions.
6
-
7
- ## Positioning and Dimensions
8
-
9
- In order to position and set the dimensions of an Element, the following attributes can be used.
10
-
11
- - `x` - the x position of the Element in pixels, relative to its parent - allows negative values and decimals
12
- - `y` - the y position of the Element in pixels, relative to its parent - allows negative values and decimals
13
- - `z` - the z index of the element (optionally `zIndex` can be used as an alias)
14
- - `w` - the width of the element in pixels (optionally `width` can be used as an alias)
15
- - `h` - the height of the element in pixels (optionally `height` can be used as an alias)
16
-
17
- All positioning and dimension related attributes, when not specified, will default to `0`.
18
-
19
- ```xml
20
- <Element x="100" y="100" w="800" h="400">
21
- <Element x="40" y="80" w="300" h="300" z="10" />
22
- <Element x="60" y="120" w="200" h="200" z="0" />
23
- </Element>
24
- ```
25
-
26
- ### Using percentages
27
-
28
- Besides using values in pixels (i.e. `w="100" h="300"`), you can also specify _percentages_ for the positioning and dimensions attributes.
29
-
30
- ```xml
31
- <Element w="400" h="100" x="800" y="900" color="#0284c7">
32
- <Element w="42%" h="30%" y="5%" x="1%" color="#075985" />
33
- </Element>
34
- ```
35
-
36
- The percentage value specified for `w` and `x` will be calculated as the percentage of the _width_ (`w`) of the parent element.
37
- And the percentage specified for `h` and `y` will use the _height_ (`h`) of the parent element as the base of the percentage calculation.
38
-
39
- ### Predefined placement options
40
-
41
- In addition to the absolute positions that Blits and Lightning use, there are a few predefined placement options available. By adding the `placement`-attribute to an Element we can easily align it to the _center_, _left_, _right_, _top_, _bottom_, or even a combination like `{y: 'middle', x: 'left'}`, without having to calculate the positions yourself.
42
-
43
-
44
- On the `x`-axis the following _placement_ options can be used: `left` (default), `center` and `right`. On the `y`-axis the _placement_ attribute accepts `top` (default), `middle` and `bottom`.
45
-
46
- The _placement_ attribute also accepts an object with an `x` and a `y` key, to specify a placement for both axes.
47
-
48
- The placement of an Element is calculated based on the dimensions of its direct parent. This means that the containing Element _must_ have its own dimensions (i.e. a `w` and a `h` attribute).
49
-
50
- ```xml
51
- <Element w="300" h="300">
52
- <!-- x placement -->
53
- <Element w="40" h="40" placement="left" color="#818cf8" />
54
- <Element w="40" h="40" placement="center" color="#2563eb" />
55
- <Element w="40" h="40" placement="right" color="#1e40af" />
56
-
57
- <!-- y placement -->
58
- <Element w="40" h="40" x="54" placement="top" color="#f472b6" />
59
- <Element w="40" h="40" x="54" placement="middle" color="#db2777" />
60
- <Element w="40" h="40" x="54" placement="bottom" color="#be185d" />
61
-
62
- <!-- x/y placement -->
63
- <Element w="40" h="40" placement="{x: 'center', y: 'bottom'}" color="#a3e635" />
64
- <Element w="40" h="40" placement="{x: 'right', y: 'middle'}" color="#65a30d" />
65
- <Element w="40" h="40" placement="{x: 'center', y: 'middle'}" color="#4d7c0f" />
66
- </Element>
67
- ```
68
-
69
- > note: the `x` or `y` attributes on the Element are ignored for those axes defined in the `placement`-attribute
70
-
71
- ## Colors
72
-
73
- By default, Elements have a transparent background color. The `color` attribute can be used to give an Element a color.
74
-
75
- If you are familiar with Lightning 2: colors have gotten a lot easier with Blits. Under the hood, the Lightning 3 renderer still uses the somewhat unfamiliar (but efficient) `0xffc0ffee` syntax. In Blits, you can specify colors as you are used to in HTML and CSS.
76
-
77
- Blits accepts the following color formats and makes sure that they are converted in a way the Lightning 3 renderer can understand.
78
-
79
- - hexadecimal (i.e. `#ff4433`)
80
- - hexadecimal with an alpha channel (i.e `#55553380`)
81
- - hexadecimal shorthands (i.e. `#333`)
82
- - rgb (i.e. `rgb(180, 30, 50)`)
83
- - rgba (i.e `rgba(40, 30, 180, 0.5)`)
84
- - html color names (i.e. `red`, `blue`, `skyblue`, `tomato`)
85
-
86
- _HSL and HSLA formats are planned to be added in the future._
87
-
88
- ```xml
89
- <Element w="200" h="200" color="#ff4433" />
90
- <Element w="200" h="200" color="#55553380" />
91
- <Element w="200" h="200" color="#333" />
92
- <Element w="200" h="200" color="rgb(180, 30, 50)" />
93
- <Element w="200" h="200" color="rgba(40, 30, 180, 0.5)" />
94
- <Element w="200" h="200" color="black" />
95
- <Element w="200" h="200" color="red" />
96
- <Element w="200" h="200" color="skyblue" />
97
- ```
98
-
99
- ### Basic linear gradients
100
-
101
- The color attribute can also be used to specify basic linear gradients.
102
-
103
- A linear gradient can be defined by specifying an _object literal_ as the `color` attribute instead of a single color. The object can consist of a mix of `top`, `bottom`, `left`, `right` keys, with the color to use for that side as a value. If a specific side isn't specified, it defaults to `transparent`.
104
-
105
- Again, you can use "normal" notation for the colors (like hexadecimal or rgba) and you are free to mix and match formats.
106
-
107
- ```xml
108
- <Element w="200" h="200" color="{top: 'red', bottom: 'blue'}" />
109
- <Element w="200" h="200" color="{left: 'rgba(255,255,255,.5)', right: '#000'}" />
110
- <Element w="200" h="200" color="{left: '#aaa333', top: 'aqua', 'bottom: rgb(255,100,20)'}" />
111
- <Element w="200" h="200" color="{bottom: 'black'}" />
112
- ```
113
-
114
- ## Alpha and visibility
115
-
116
- The opacity of an Element can be controlled by setting the `alpha` attribute. This attribute accepts a value between `0` (fully transparent) and `1` (completely visible).
117
-
118
- The value of alpha is also applied recursively to the children of the Element that has its alpha set. If you just want the background color of an Element to be semi-transparent, you should set the alpha channel in the `color` instead of applying the `alpha` attribute.
119
-
120
- ```xml
121
- <Element w="200" h="200" color="blue" alpha="0.8">
122
- <Element w="100" h="100" color="red" alpha="0.3" />
123
- </Element>
124
- ```
125
-
126
- ## Rotation and scaling
127
-
128
- If you want to rotate an Element, you can use the `rotation` attribute. The rotation attribute in Blits accepts values in _degrees_.
129
-
130
- The rotation of an Element is also automatically applied to any children down the tree.
131
-
132
- ```xml
133
- <Element w="200" h="200" color="blue" rotation="90">
134
- <Element w="100" h="100" color="red" rotation="240" />
135
- </Element>
136
- ```
137
-
138
- For scaling an Element the `scale` attribute is used.
139
-
140
- This attribute either accepts a single numeric value for scaling evenly across width and height. Or an _object literal_, if you want to apply a different scaling for the `x` and the `y` axis.
141
-
142
- The value should be higher than `0` and the default value is `1`, which means no scaling.
143
-
144
- Any value below `1` will scale _down_ the element and values greater than `1` will scale the element _up_.
145
-
146
- Similar to rotation, scale is also applied recursively to children down the tree of the Element that has its `scale` attribute set.
147
-
148
- ```xml
149
- <Element w="200" h="200" color="blue" scale="0.5" />
150
- <Element w="200" h="200" color="#000" scale="2.3" />
151
- <Element w="200" h="200" color="#000" scale="{x: 1, y: 3.14}" />
152
- ```
153
-
154
- ## Mounting point
155
-
156
- For advanced positioning, the `mount` attribute can come in handy. By default when you set the `x` and `y` position of an Element, the _top-left_ corner will be set to that position. But in some cases, you may want to align the position starting at a different corner, or even any arbitrary point in between.
157
-
158
- The `mount` attribute accepts an _object literal_ that allows you to precisely control the mount position on the _x-axis_ and the mount position on the _y-axis_. The default value is `{x: 0, y: 0}`, which refers to the _top-left_ corner.
159
-
160
- In order to align the position starting at the _bottom-right_ corner, we would set `mount` to `{x: 1, y: 1}` and `{x: 0.5, y: 0.5}` would align the position at the _center_ of the Element.
161
-
162
- If you omit either the `x` or the `y` key from the _object literal_, its value will default to `0`.
163
-
164
- In the case where the `x` and `y` values are the same (i.e. centering with `{x: 0.5, y: 0.5}`), you can also just supply a single value (`mount="0.5"`) instead of the object literal notation.
165
-
166
- ```xml
167
- <Element w="200" h="200" x="20" y="100" color="#333" mount="{x: 0.5, y: 0.8}" />
168
- <Element w="200" h="200" x="800" y="400" color="#333" mount="{y: 1}" />
169
- <Element w="200" h="200" x="800" y="700" color="#333" mount="0.5" />
170
- ```
171
-
172
- ## Pivot point
173
-
174
- The pivot point of an Element comes into play when it's rotated or scaled. The pivot point defaults to the _center_ of the Element, which means that when setting `rotation` it rotates around the middle. And when the Element is scaled it scales from the center out.
175
-
176
- But sometimes you may want to rotate around the left corner, or scale from the right side out. This can be controlled by adding the `pivot` attribute to the Element and, similar to the `mount` attribute, specify an _object literal_ with an `x` and a `y` key.
177
-
178
- Both `y` and `x` values should be anything between `0` and `1`, where `{x: 0, y: 0}` sets the pivot point to the _top-left_ corner and `{x: 1, y: 1}` refers to the _bottom-right_ corner. The default pivot value is `{x: 0.5, y: 0.5}` (i.e. the center) and if you omit `x` or `y` in your pivot object, it will default to `0.5`.
179
-
180
- In the case where the `x` and `y` values are the same, you can also just supply a single value (`pivot="0.9"`) instead of the object literal notation.
181
-
182
-
183
- ```xml
184
- <Element w="200" h="200" x="20" y="100" pivot="{x: 0.5, y: 0.8}" rotation="69" />
185
- <Element w="200" h="200" x="800" y="400" pivot="{y: 1}" scale="3" />
186
- <Element w="200" h="200" x="800" y="700" pivot="0.9" rotation="42" />
187
- ```
188
-
189
- ## Clipping / overflow
190
-
191
- By default contents inside an Element (i.e. child Elements) will overflow the boundaries of the parent, even when you give the parent Element fixed dimensions.
192
-
193
- In order to contain / cut off the content inside an Element's `w` and `h`, you can add the `clipping="true"`-attribute. Setting `clipping` to `false` restores the default behaviour of content overflowing.
194
-
195
- Alternatively you can also use the `overflow`-attribute (and pass it `true` or `false`), which works similar to clipping just mapped inversly (i.e. `overflow="false"` ensures content that surpasses the parent dimensions is clipped-off).
1
+ # Supported Element attributes
2
+
3
+ The core building block of a Blits template is the `<Element>`-tag. The Element tag corresponds directly to a node in the Lightning 3 Renderer. You can style and position Elements via _attributes_, much like you would do in plain HTML.
4
+
5
+ Blits Elements have a specific set of attributes that can be used. The available attributes are loosely modeled after the properties of a Lightning 3 renderer node. In certain cases, Blits provides more developer friendly names or accepts a wider range of values, and transparently takes care of the translation into L3 renderer instructions.
6
+
7
+ ## Positioning and Dimensions
8
+
9
+ In order to position and set the dimensions of an Element, the following attributes can be used.
10
+
11
+ - `x` - the x position of the Element in pixels, relative to its parent - allows negative values and decimals
12
+ - `y` - the y position of the Element in pixels, relative to its parent - allows negative values and decimals
13
+ - `z` - the z index of the element (optionally `zIndex` can be used as an alias)
14
+ - `w` - the width of the element in pixels (optionally `width` can be used as an alias)
15
+ - `h` - the height of the element in pixels (optionally `height` can be used as an alias)
16
+
17
+ All positioning and dimension related attributes, when not specified, will default to `0`.
18
+
19
+ ```xml
20
+ <Element x="100" y="100" w="800" h="400">
21
+ <Element x="40" y="80" w="300" h="300" z="10" />
22
+ <Element x="60" y="120" w="200" h="200" z="0" />
23
+ </Element>
24
+ ```
25
+
26
+ ### Using percentages
27
+
28
+ Besides using values in pixels (i.e. `w="100" h="300"`), you can also specify _percentages_ for the positioning and dimensions attributes.
29
+
30
+ ```xml
31
+ <Element w="400" h="100" x="800" y="900" color="#0284c7">
32
+ <Element w="42%" h="30%" y="5%" x="1%" color="#075985" />
33
+ </Element>
34
+ ```
35
+
36
+ The percentage value specified for `w` and `x` will be calculated as the percentage of the _width_ (`w`) of the parent element.
37
+ And the percentage specified for `h` and `y` will use the _height_ (`h`) of the parent element as the base of the percentage calculation.
38
+
39
+ ### Predefined placement options
40
+
41
+ In addition to the absolute positions that Blits and Lightning use, there are a few predefined placement options available. By adding the `placement`-attribute to an Element we can easily align it to the _center_, _left_, _right_, _top_, _bottom_, or even a combination like `{y: 'middle', x: 'left'}`, without having to calculate the positions yourself.
42
+
43
+
44
+ On the `x`-axis the following _placement_ options can be used: `left` (default), `center` and `right`. On the `y`-axis the _placement_ attribute accepts `top` (default), `middle` and `bottom`.
45
+
46
+ The _placement_ attribute also accepts an object with an `x` and a `y` key, to specify a placement for both axes.
47
+
48
+ The placement of an Element is calculated based on the dimensions of its direct parent. This means that the containing Element _must_ have its own dimensions (i.e. a `w` and a `h` attribute).
49
+
50
+ ```xml
51
+ <Element w="300" h="300">
52
+ <!-- x placement -->
53
+ <Element w="40" h="40" placement="left" color="#818cf8" />
54
+ <Element w="40" h="40" placement="center" color="#2563eb" />
55
+ <Element w="40" h="40" placement="right" color="#1e40af" />
56
+
57
+ <!-- y placement -->
58
+ <Element w="40" h="40" x="54" placement="top" color="#f472b6" />
59
+ <Element w="40" h="40" x="54" placement="middle" color="#db2777" />
60
+ <Element w="40" h="40" x="54" placement="bottom" color="#be185d" />
61
+
62
+ <!-- x/y placement -->
63
+ <Element w="40" h="40" placement="{x: 'center', y: 'bottom'}" color="#a3e635" />
64
+ <Element w="40" h="40" placement="{x: 'right', y: 'middle'}" color="#65a30d" />
65
+ <Element w="40" h="40" placement="{x: 'center', y: 'middle'}" color="#4d7c0f" />
66
+ </Element>
67
+ ```
68
+
69
+ > note: the `x` or `y` attributes on the Element are ignored for those axes defined in the `placement`-attribute
70
+
71
+ ## Colors
72
+
73
+ By default, Elements have a transparent background color. The `color` attribute can be used to give an Element a color.
74
+
75
+ If you are familiar with Lightning 2: colors have gotten a lot easier with Blits. Under the hood, the Lightning 3 renderer still uses the somewhat unfamiliar (but efficient) `0xffc0ffee` syntax. In Blits, you can specify colors as you are used to in HTML and CSS.
76
+
77
+ Blits accepts the following color formats and makes sure that they are converted in a way the Lightning 3 renderer can understand.
78
+
79
+ - hexadecimal (i.e. `#ff4433`)
80
+ - hexadecimal with an alpha channel (i.e `#55553380`)
81
+ - hexadecimal shorthands (i.e. `#333`)
82
+ - rgb (i.e. `rgb(180, 30, 50)`)
83
+ - rgba (i.e `rgba(40, 30, 180, 0.5)`)
84
+ - html color names (i.e. `red`, `blue`, `skyblue`, `tomato`)
85
+
86
+ _HSL and HSLA formats are planned to be added in the future._
87
+
88
+ ```xml
89
+ <Element w="200" h="200" color="#ff4433" />
90
+ <Element w="200" h="200" color="#55553380" />
91
+ <Element w="200" h="200" color="#333" />
92
+ <Element w="200" h="200" color="rgb(180, 30, 50)" />
93
+ <Element w="200" h="200" color="rgba(40, 30, 180, 0.5)" />
94
+ <Element w="200" h="200" color="black" />
95
+ <Element w="200" h="200" color="red" />
96
+ <Element w="200" h="200" color="skyblue" />
97
+ ```
98
+
99
+ ### Basic linear gradients
100
+
101
+ The color attribute can also be used to specify basic linear gradients.
102
+
103
+ A linear gradient can be defined by specifying an _object literal_ as the `color` attribute instead of a single color. The object can consist of a mix of `top`, `bottom`, `left`, `right` keys, with the color to use for that side as a value. If a specific side isn't specified, it defaults to `transparent`.
104
+
105
+ Again, you can use "normal" notation for the colors (like hexadecimal or rgba) and you are free to mix and match formats.
106
+
107
+ ```xml
108
+ <Element w="200" h="200" color="{top: 'red', bottom: 'blue'}" />
109
+ <Element w="200" h="200" color="{left: 'rgba(255,255,255,.5)', right: '#000'}" />
110
+ <Element w="200" h="200" color="{left: '#aaa333', top: 'aqua', 'bottom: rgb(255,100,20)'}" />
111
+ <Element w="200" h="200" color="{bottom: 'black'}" />
112
+ ```
113
+
114
+ ## Alpha and visibility
115
+
116
+ The opacity of an Element can be controlled by setting the `alpha` attribute. This attribute accepts a value between `0` (fully transparent) and `1` (completely visible).
117
+
118
+ The value of alpha is also applied recursively to the children of the Element that has its alpha set. If you just want the background color of an Element to be semi-transparent, you should set the alpha channel in the `color` instead of applying the `alpha` attribute.
119
+
120
+ ```xml
121
+ <Element w="200" h="200" color="blue" alpha="0.8">
122
+ <Element w="100" h="100" color="red" alpha="0.3" />
123
+ </Element>
124
+ ```
125
+
126
+ ## Rotation and scaling
127
+
128
+ If you want to rotate an Element, you can use the `rotation` attribute. The rotation attribute in Blits accepts values in _degrees_.
129
+
130
+ The rotation of an Element is also automatically applied to any children down the tree.
131
+
132
+ ```xml
133
+ <Element w="200" h="200" color="blue" rotation="90">
134
+ <Element w="100" h="100" color="red" rotation="240" />
135
+ </Element>
136
+ ```
137
+
138
+ For scaling an Element the `scale` attribute is used.
139
+
140
+ This attribute either accepts a single numeric value for scaling evenly across width and height. Or an _object literal_, if you want to apply a different scaling for the `x` and the `y` axis.
141
+
142
+ The value should be higher than `0` and the default value is `1`, which means no scaling.
143
+
144
+ Any value below `1` will scale _down_ the element and values greater than `1` will scale the element _up_.
145
+
146
+ Similar to rotation, scale is also applied recursively to children down the tree of the Element that has its `scale` attribute set.
147
+
148
+ ```xml
149
+ <Element w="200" h="200" color="blue" scale="0.5" />
150
+ <Element w="200" h="200" color="#000" scale="2.3" />
151
+ <Element w="200" h="200" color="#000" scale="{x: 1, y: 3.14}" />
152
+ ```
153
+
154
+ ## Mounting point
155
+
156
+ For advanced positioning, the `mount` attribute can come in handy. By default when you set the `x` and `y` position of an Element, the _top-left_ corner will be set to that position. But in some cases, you may want to align the position starting at a different corner, or even any arbitrary point in between.
157
+
158
+ The `mount` attribute accepts an _object literal_ that allows you to precisely control the mount position on the _x-axis_ and the mount position on the _y-axis_. The default value is `{x: 0, y: 0}`, which refers to the _top-left_ corner.
159
+
160
+ In order to align the position starting at the _bottom-right_ corner, we would set `mount` to `{x: 1, y: 1}` and `{x: 0.5, y: 0.5}` would align the position at the _center_ of the Element.
161
+
162
+ If you omit either the `x` or the `y` key from the _object literal_, its value will default to `0`.
163
+
164
+ In the case where the `x` and `y` values are the same (i.e. centering with `{x: 0.5, y: 0.5}`), you can also just supply a single value (`mount="0.5"`) instead of the object literal notation.
165
+
166
+ ```xml
167
+ <Element w="200" h="200" x="20" y="100" color="#333" mount="{x: 0.5, y: 0.8}" />
168
+ <Element w="200" h="200" x="800" y="400" color="#333" mount="{y: 1}" />
169
+ <Element w="200" h="200" x="800" y="700" color="#333" mount="0.5" />
170
+ ```
171
+
172
+ ## Pivot point
173
+
174
+ The pivot point of an Element comes into play when it's rotated or scaled. The pivot point defaults to the _center_ of the Element, which means that when setting `rotation` it rotates around the middle. And when the Element is scaled it scales from the center out.
175
+
176
+ But sometimes you may want to rotate around the left corner, or scale from the right side out. This can be controlled by adding the `pivot` attribute to the Element and, similar to the `mount` attribute, specify an _object literal_ with an `x` and a `y` key.
177
+
178
+ Both `y` and `x` values should be anything between `0` and `1`, where `{x: 0, y: 0}` sets the pivot point to the _top-left_ corner and `{x: 1, y: 1}` refers to the _bottom-right_ corner. The default pivot value is `{x: 0.5, y: 0.5}` (i.e. the center) and if you omit `x` or `y` in your pivot object, it will default to `0.5`.
179
+
180
+ In the case where the `x` and `y` values are the same, you can also just supply a single value (`pivot="0.9"`) instead of the object literal notation.
181
+
182
+
183
+ ```xml
184
+ <Element w="200" h="200" x="20" y="100" pivot="{x: 0.5, y: 0.8}" rotation="69" />
185
+ <Element w="200" h="200" x="800" y="400" pivot="{y: 1}" scale="3" />
186
+ <Element w="200" h="200" x="800" y="700" pivot="0.9" rotation="42" />
187
+ ```
188
+
189
+ ## Clipping / overflow
190
+
191
+ By default contents inside an Element (i.e. child Elements) will overflow the boundaries of the parent, even when you give the parent Element fixed dimensions.
192
+
193
+ In order to contain / cut off the content inside an Element's `w` and `h`, you can add the `clipping="true"`-attribute. Setting `clipping` to `false` restores the default behaviour of content overflowing.
194
+
195
+ Alternatively you can also use the `overflow`-attribute (and pass it `true` or `false`), which works similar to clipping just mapped inversly (i.e. `overflow="false"` ensures content that surpasses the parent dimensions is clipped-off).
@@ -1,117 +1,117 @@
1
- # Application Settings
2
-
3
- Blits provides a flexible and performant way to configure your application at launch using the settings object passed to `Blits.Launch`. These settings allow you to fine-tune rendering, performance, input, fonts, and more.
4
-
5
- Below is a comprehensive overview of the available settings you can provide to a Blits Application:
6
-
7
- ## Basic Settings
8
-
9
- | Setting | Type | Description |
10
- |----------------|---------------------|-------------|
11
- | `w` | `number` | Width of the application (canvas) |
12
- | `h` | `number` | Height of the application (canvas) |
13
- | `debugLevel` | `number \| string[]`| Debug level for console log messages |
14
- | `multithreaded`| `boolean` | Enable multithreaded rendering |
15
-
16
- ## Fonts & Text
17
-
18
- | Setting | Type | Description |
19
- |----------------|-----------|-------------|
20
- | `fonts` | `Font[]` | Array of font objects to register |
21
- | `defaultFont` | `string` | Default font family to use |
22
-
23
- Example font object:
24
- ```js
25
- {
26
- family: 'lato',
27
- type: 'msdf', // or 'web'
28
- file: 'fonts/Lato-Regular.ttf',
29
- }
30
- ```
31
-
32
- ## Rendering & Performance
33
-
34
- | Setting | Type | Description |
35
- |----------------|-----------|-------------|
36
- | `renderQuality` | `'low' \| 'medium' \| 'high' \| 'retina' \| number` | Controls render quality (1 = 100%) |
37
- | `screenResolution` | `'hd' \| 'fhd' \| '4k' \| number` | Sets device screen resolution |
38
- | `pixelRatio` | `number` | Custom pixel ratio (overrides screenResolution) |
39
- | `canvasColor` | `string` | Background color of the canvas |
40
- | `fpsInterval` | `number` | Interval (ms) for FPS updates (0 disables) |
41
- | `webWorkersLimit` | `number`| Max number of web workers for image handling |
42
- | `gpuMemory` | `object` | GPU memory management (see below) |
43
- | `gpuMemoryLimit`| `number` | (Deprecated) Use `gpuMemory` instead |
44
- | `textureProcessingTimeLimit` | `number` | Max ms per frame for texture processing |
45
- | `viewportMargin`| `number \| [number,number,number,number]` | Extra margin for preloading elements |
46
- | `advanced` | `object` | Advanced renderer settings (use with care) |
47
-
48
- ### GPU Memory Example
49
- ```js
50
- {
51
- max: 200, // MB
52
- target: 0.8, // 80% of max
53
- cleanupInterval: 5000, // ms
54
- baseline: 25, // MB
55
- strict: false
56
- }
57
- ```
58
-
59
- ## Input & Focus
60
-
61
- | Setting | Type | Description |
62
- |----------------|-----------|-------------|
63
- | `keymap` | `object` | Custom key mapping for input events |
64
- | `holdTimeout` | `number` | Time (ms) to consider a key press as hold |
65
-
66
- ## Renderer
67
-
68
- | Setting | Type | Description |
69
- |----------------|-----------|-------------|
70
- | `renderMode` | `'webgl' \| 'canvas'` | Renderer mode (default: 'webgl') |
71
- | `canvas` | `HTMLCanvasElement` | Custom canvas to render to |
72
-
73
- ## Effects & Shaders
74
-
75
- | Setting | Type | Description |
76
- |----------------|-----------|-------------|
77
- | `effects` | `ShaderEffect[]` | Effects for DynamicShader |
78
- | `shaders` | `Shader[]` | Custom shaders |
79
-
80
- ## Inspector & Debugging
81
-
82
- | Setting | Type | Description |
83
- |----------------|-----------|-------------|
84
- | `inspector` | `boolean` | Enable the inspector tool |
85
-
86
- ## Accessibility
87
-
88
- | Setting | Type | Description |
89
- |----------------|-----------|-------------|
90
- | `announcer` | `boolean` | Enable/disable text-to-speech announcer |
91
-
92
- ## Example Usage
93
-
94
- ```js
95
- Blits.Launch(App, 'app', {
96
- w: 1920,
97
- h: 1080,
98
- debugLevel: 1,
99
- renderQuality: 'high',
100
- fonts: [
101
- { family: 'lato', type: 'msdf', file: 'fonts/Lato-Regular.ttf' },
102
- ],
103
- keymap: {
104
- ArrowLeft: 'left',
105
- ArrowRight: 'right',
106
- },
107
- gpuMemory: {
108
- max: 200,
109
- target: 0.8,
110
- cleanupInterval: 5000,
111
- baseline: 25,
112
- strict: false,
113
- },
114
- inspector: false,
115
- announcer: true,
116
- })
117
- ```
1
+ # Application Settings
2
+
3
+ Blits provides a flexible and performant way to configure your application at launch using the settings object passed to `Blits.Launch`. These settings allow you to fine-tune rendering, performance, input, fonts, and more.
4
+
5
+ Below is a comprehensive overview of the available settings you can provide to a Blits Application:
6
+
7
+ ## Basic Settings
8
+
9
+ | Setting | Type | Description |
10
+ |----------------|---------------------|-------------|
11
+ | `w` | `number` | Width of the application (canvas) |
12
+ | `h` | `number` | Height of the application (canvas) |
13
+ | `debugLevel` | `number \| string[]`| Debug level for console log messages |
14
+ | `multithreaded`| `boolean` | Enable multithreaded rendering |
15
+
16
+ ## Fonts & Text
17
+
18
+ | Setting | Type | Description |
19
+ |----------------|-----------|-------------|
20
+ | `fonts` | `Font[]` | Array of font objects to register |
21
+ | `defaultFont` | `string` | Default font family to use |
22
+
23
+ Example font object:
24
+ ```js
25
+ {
26
+ family: 'lato',
27
+ type: 'msdf', // or 'web'
28
+ file: 'fonts/Lato-Regular.ttf',
29
+ }
30
+ ```
31
+
32
+ ## Rendering & Performance
33
+
34
+ | Setting | Type | Description |
35
+ |----------------|-----------|-------------|
36
+ | `renderQuality` | `'low' \| 'medium' \| 'high' \| 'retina' \| number` | Controls render quality (1 = 100%) |
37
+ | `screenResolution` | `'hd' \| 'fhd' \| '4k' \| number` | Sets device screen resolution |
38
+ | `pixelRatio` | `number` | Custom pixel ratio (overrides screenResolution) |
39
+ | `canvasColor` | `string` | Background color of the canvas |
40
+ | `fpsInterval` | `number` | Interval (ms) for FPS updates (0 disables) |
41
+ | `webWorkersLimit` | `number`| Max number of web workers for image handling |
42
+ | `gpuMemory` | `object` | GPU memory management (see below) |
43
+ | `gpuMemoryLimit`| `number` | (Deprecated) Use `gpuMemory` instead |
44
+ | `textureProcessingTimeLimit` | `number` | Max ms per frame for texture processing |
45
+ | `viewportMargin`| `number \| [number,number,number,number]` | Extra margin for preloading elements |
46
+ | `advanced` | `object` | Advanced renderer settings (use with care) |
47
+
48
+ ### GPU Memory Example
49
+ ```js
50
+ {
51
+ max: 200, // MB
52
+ target: 0.8, // 80% of max
53
+ cleanupInterval: 5000, // ms
54
+ baseline: 25, // MB
55
+ strict: false
56
+ }
57
+ ```
58
+
59
+ ## Input & Focus
60
+
61
+ | Setting | Type | Description |
62
+ |----------------|-----------|-------------|
63
+ | `keymap` | `object` | Custom key mapping for input events |
64
+ | `holdTimeout` | `number` | Time (ms) to consider a key press as hold |
65
+
66
+ ## Renderer
67
+
68
+ | Setting | Type | Description |
69
+ |----------------|-----------|-------------|
70
+ | `renderMode` | `'webgl' \| 'canvas'` | Renderer mode (default: 'webgl') |
71
+ | `canvas` | `HTMLCanvasElement` | Custom canvas to render to |
72
+
73
+ ## Effects & Shaders
74
+
75
+ | Setting | Type | Description |
76
+ |----------------|-----------|-------------|
77
+ | `effects` | `ShaderEffect[]` | Effects for DynamicShader |
78
+ | `shaders` | `Shader[]` | Custom shaders |
79
+
80
+ ## Inspector & Debugging
81
+
82
+ | Setting | Type | Description |
83
+ |----------------|-----------|-------------|
84
+ | `inspector` | `boolean` | Enable the inspector tool |
85
+
86
+ ## Accessibility
87
+
88
+ | Setting | Type | Description |
89
+ |----------------|-----------|-------------|
90
+ | `announcer` | `boolean` | Enable/disable text-to-speech announcer |
91
+
92
+ ## Example Usage
93
+
94
+ ```js
95
+ Blits.Launch(App, 'app', {
96
+ w: 1920,
97
+ h: 1080,
98
+ debugLevel: 1,
99
+ renderQuality: 'high',
100
+ fonts: [
101
+ { family: 'lato', type: 'msdf', file: 'fonts/Lato-Regular.ttf' },
102
+ ],
103
+ keymap: {
104
+ ArrowLeft: 'left',
105
+ ArrowRight: 'right',
106
+ },
107
+ gpuMemory: {
108
+ max: 200,
109
+ target: 0.8,
110
+ cleanupInterval: 5000,
111
+ baseline: 25,
112
+ strict: false,
113
+ },
114
+ inspector: false,
115
+ announcer: true,
116
+ })
117
+ ```