@lightningjs/blits 1.30.2 → 1.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/CHANGELOG.md +1029 -1019
  2. package/LICENSE +202 -202
  3. package/NOTICE +12 -12
  4. package/README.md +33 -33
  5. package/bin/index.js +8 -8
  6. package/blits.d.ts +6 -6
  7. package/index.d.ts +1099 -1099
  8. package/index.js +28 -28
  9. package/package.json +57 -56
  10. package/public/assets/fps_sprite.base64.js +1 -1
  11. package/scripts/postpublish.js +59 -59
  12. package/scripts/prepublishOnly.js +84 -84
  13. package/scripts/prepush.js +78 -78
  14. package/src/announcer/announcer.js +162 -162
  15. package/src/announcer/speechSynthesis.js +107 -107
  16. package/src/application.js +100 -100
  17. package/src/component/base/announcer.js +27 -27
  18. package/src/component/base/events.js +69 -69
  19. package/src/component/base/index.js +33 -33
  20. package/src/component/base/methods.js +244 -244
  21. package/src/component/base/router.js +41 -41
  22. package/src/component/base/timeouts_intervals.js +99 -99
  23. package/src/component/base/utils.js +72 -72
  24. package/src/component/setup/computed.js +48 -48
  25. package/src/component/setup/index.js +62 -62
  26. package/src/component/setup/input.js +30 -30
  27. package/src/component/setup/methods.js +37 -37
  28. package/src/component/setup/props.js +62 -62
  29. package/src/component/setup/routes.js +42 -42
  30. package/src/component/setup/state.js +59 -59
  31. package/src/component/setup/watch.js +35 -35
  32. package/src/component.js +437 -437
  33. package/src/components/Circle.js +73 -73
  34. package/src/components/FPScounter.js +1510 -1510
  35. package/src/components/RouterView.js +81 -81
  36. package/src/components/Sprite.js +94 -94
  37. package/src/components/index.js +28 -28
  38. package/src/constants.js +21 -21
  39. package/src/engine.js +1 -1
  40. package/src/engines/L3/element.js +744 -744
  41. package/src/engines/L3/fontLoader.js +38 -38
  42. package/src/engines/L3/index.js +7 -7
  43. package/src/engines/L3/launch.js +123 -123
  44. package/src/engines/L3/shaderLoader.js +12 -12
  45. package/src/engines/index.js +1 -1
  46. package/src/focus.js +90 -90
  47. package/src/helpers/deepEqualArray.js +50 -50
  48. package/src/helpers/fetchJson.js +34 -34
  49. package/src/helpers/sequence.js +26 -26
  50. package/src/launch.js +123 -123
  51. package/src/lib/blitsfileconverter/blitsfileconverter.js +52 -52
  52. package/src/lib/codegenerator/generator.js +788 -788
  53. package/src/lib/colors/colors.js +92 -92
  54. package/src/lib/colors/htmlColors.js +168 -168
  55. package/src/lib/componentId.js +49 -49
  56. package/src/lib/eventListeners.js +123 -123
  57. package/src/lib/hooks.js +59 -59
  58. package/src/lib/lifecycle.js +85 -85
  59. package/src/lib/log.js +117 -117
  60. package/src/lib/precompiler/precompiler.js +73 -73
  61. package/src/lib/reactivity/effect.js +93 -93
  62. package/src/lib/reactivity/reactive.js +208 -208
  63. package/src/lib/reactivityguard/computedprops.js +218 -218
  64. package/src/lib/symbols.js +108 -108
  65. package/src/lib/templateparser/parser.js +386 -386
  66. package/src/lib/utils.js +27 -27
  67. package/src/plugin.js +27 -27
  68. package/src/plugins/appstate.js +26 -26
  69. package/src/plugins/index.js +20 -20
  70. package/src/plugins/language.js +152 -152
  71. package/src/plugins/log.js +25 -25
  72. package/src/plugins/theme.js +94 -94
  73. package/src/router/router.js +516 -514
  74. package/src/router/transitions/fadeIn.js +27 -27
  75. package/src/router/transitions/fadeInOut.js +33 -33
  76. package/src/router/transitions/index.js +21 -21
  77. package/src/router/transitions/slideIn.js +28 -28
  78. package/src/router/transitions/slideInOut.js +33 -33
  79. package/src/settings.js +40 -40
  80. package/vite/blitsFileConverter.js +67 -67
  81. package/vite/index.js +28 -28
  82. package/vite/msdfGenerator.js +269 -269
  83. package/vite/preCompiler.js +47 -42
  84. package/vite/reactivityGuard.js +45 -45
  85. package/vscode/data/template-attributes.json +589 -589
  86. package/.editorconfig +0 -7
  87. package/.eslintignore +0 -1
  88. package/.eslintrc.cjs +0 -65
  89. package/.github/workflows/comment-lint-results.yml +0 -125
  90. package/.github/workflows/comment-test-results.yml +0 -109
  91. package/.github/workflows/deploy-docs.yml +0 -27
  92. package/.github/workflows/run-blits-tests.yml +0 -142
  93. package/.github/workflows/run-lint.yml +0 -128
  94. package/.husky/pre-commit +0 -1
  95. package/.husky/pre-push +0 -1
  96. package/.vscode/extensions.json +0 -7
  97. package/.vscode/settings.json +0 -9
  98. package/COPYING +0 -1
  99. package/banner.png +0 -0
  100. package/docs/.nojekyll +0 -0
  101. package/docs/README.md +0 -19
  102. package/docs/_sidebar.md +0 -37
  103. package/docs/built-in/directives.md +0 -50
  104. package/docs/built-in/for-loop.md +0 -204
  105. package/docs/built-in/layout.md +0 -168
  106. package/docs/components/component_state.md +0 -90
  107. package/docs/components/computed_properties.md +0 -45
  108. package/docs/components/lifecycle_events.md +0 -42
  109. package/docs/components/methods.md +0 -45
  110. package/docs/components/props.md +0 -56
  111. package/docs/components/user_input.md +0 -186
  112. package/docs/components/utility_methods.md +0 -320
  113. package/docs/components/watchers.md +0 -34
  114. package/docs/essentials/application_root.md +0 -19
  115. package/docs/essentials/components.md +0 -68
  116. package/docs/essentials/displaying_images.md +0 -67
  117. package/docs/essentials/displaying_text.md +0 -135
  118. package/docs/essentials/element_attributes.md +0 -195
  119. package/docs/essentials/settings.md +0 -117
  120. package/docs/essentials/template_syntax.md +0 -83
  121. package/docs/getting_started/file_structure.md +0 -58
  122. package/docs/getting_started/getting_started.md +0 -45
  123. package/docs/getting_started/intro.md +0 -20
  124. package/docs/index.html +0 -47
  125. package/docs/performance/lazy-loading.md +0 -161
  126. package/docs/plugins/global_app_state.md +0 -98
  127. package/docs/plugins/language.md +0 -172
  128. package/docs/plugins/text-to-speech-announcer.md +0 -120
  129. package/docs/plugins/theme.md +0 -176
  130. package/docs/router/basics.md +0 -175
  131. package/docs/router/hooks.md +0 -70
  132. package/docs/router/transitions.md +0 -146
  133. package/docs/sidebar.json +0 -171
  134. package/docs/transitions_animations/transitions.md +0 -150
  135. package/jsconfig.json +0 -12
  136. package/src/component/setup/props.test.js +0 -238
  137. package/src/component.test.js +0 -388
  138. package/src/components/Circle.orig.js +0 -31
  139. package/src/components/FPScounter.orig.js +0 -121
  140. package/src/components/RouterView.orig.js +0 -54
  141. package/src/components/Sprite.orig.js +0 -58
  142. package/src/components/index.orig.js +0 -28
  143. package/src/engines/L3/element.test.js +0 -579
  144. package/src/helpers/deepEqualArray.test.js +0 -127
  145. package/src/lib/codegenerator/generator.test.js +0 -3801
  146. package/src/lib/colors/colors.test.js +0 -290
  147. package/src/lib/componentId.test.js +0 -84
  148. package/src/lib/eventListeners.test.js +0 -236
  149. package/src/lib/reactivity/effect.test.js +0 -35
  150. package/src/lib/reactivity/reactive.test.js +0 -27
  151. package/src/lib/templateparser/parser.test.js +0 -1411
  152. package/src/router/router.test.js +0 -473
@@ -1,68 +0,0 @@
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 +0,0 @@
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,135 +0,0 @@
1
- # Displaying Text
2
-
3
- Besides displaying images, it is also very common to have _texts_ in an App.
4
-
5
- Blits comes with a built-in `<Text>`-tag for displaying and styling texts in a simple and intuitive way.
6
-
7
- ```xml
8
- <Text
9
- content="Hello world"
10
- font="ComicSans"
11
- size="$fontSize"
12
- :color="$changingColor"
13
- />
14
-
15
- ```
16
- You can use the Text-tag anywhere in your template, without the need to explicitly import and register it in your Component.
17
-
18
- ## Available attributes on the Text tag
19
-
20
- The Text-tag accepts the following attributes:
21
-
22
- - `content` - the text to be displayed. Can be a hardcoded text, a dynamic value, or a reactive value
23
- - `font` - the font family, defaults to `sans-serif`, or the default font specified in the launch settings
24
- - `size` - the font size, defaults to `32`
25
- - `color` - the color to display for the text, defaults to `white` and can be any of the supported Blits color formats (HTML, hexadecimal or rgb(a))
26
- - `letterspacing` - letterspacing in pixels, defaults to `0`
27
- - `align` - the alignment of the text, can be `left`, `right`, or `center`, defaults to `left`. Centering text and aligning text to the right requires the `maxwidth` attribute to be set as well.
28
- - `maxwidth` - the max length of a line of text in pixels, words surpassing this length will be broken and wrapped onto the next line. This attribute is required when aligning center or right. Previously this attribute was `wordwrap`, which has now been deprecated in favour of `maxwidth`.
29
- - `maxlines` - maximum number of lines that will be displayed
30
- - `maxheight` - maximum height of a text block, lines that don't fit within this height will not be displayed
31
- - `lineheight` - the spacing between lines in pixels
32
- - `contain` - the strategy for containing text within the bounds, can be `none` (default), `width`, or `both`. In most cases, the value of this attribute will automatically be set by Blits, based on the other specified attributes
33
- - `textoverflow` - the suffix to be added when text is cropped due to bounds limits, defaults to `...` (see more details [here](#text-overflow))
34
-
35
- ## Text dimensions
36
-
37
- When you want to center your Text element, or properly position other Elements around your text, it is useful to know the exact dimensions of your text.
38
-
39
- Similar to the Image element (i.e. an Element with a `src`), Text elements also accept the `@loaded` attribute. This event is called, as soon as the text is rendered, and passes in the dimensions of the generated text texture.
40
-
41
- The example below shows how to use the `@loaded`-attribute to position an Element as an underline, under a piece of text.
42
-
43
- ```js
44
- export default Blits.Component('MyComponent', {
45
- template: `
46
- <Element>
47
- <Text :content="$myText" @loaded="$textLoaded" />
48
- <!-- gray underline -->
49
- <Element :w="$w" h="2" y="$y" color="#333" />
50
- </Element>
51
- `,
52
- props: ['myText'],
53
- state() {
54
- return {
55
- w: 0,
56
- y: 0,
57
- }
58
- },
59
- methods: {
60
- textLoaded(dimensions) {
61
- console.log(`The text has a width of ${dimensions.w} and a height of ${dimensions.h}`)
62
- // set the underline width to the exact width of the text
63
- this.w = dimensions.w
64
- // position the underline 8px below the text
65
- this.y = dimensions.h + 8
66
- }
67
- }
68
- ```
69
-
70
- ## Text overflow
71
-
72
- The text renderer offers the ability to display a _text overflow suffix_ when the text exceeds the bounds of the Text component.
73
-
74
- This functionality is automatically enabled, but requires that both a _horizontal_ boundary (using `maxwidth`) and a _vertical_ boundary (using `maxlines` or `maxheight`) are specified on the Text component.
75
-
76
- The `textoverflow`-attribute itself is not required, unless you want to use another suffix than the standard `...`. If you want _no suffix_ (and just a hard cutoff), the`textoverflow`-attribute should be set to `false` or an _empty string_.
77
-
78
- ## SDF and Canvas2d
79
-
80
- Compared to Lightning 2, texts have improved a lot in Lightning 3, thanks to the SDF (Signed Distance Field) Text renderer.
81
-
82
- With the SDF text renderer, texts appear a lot _sharper_ on screen. The SDF technique also allows for better scaling of texts, without them becoming blurry - a well-known painpoint in Lightning 2 Apps.
83
-
84
- In general, it's recommended to use the SDF text renderer, but Lightning 3 still has a Canvas2d text renderer as a backup, and you can use both text renderers within the same App.
85
-
86
- ## Using custom fonts
87
-
88
- The `font`-attribute on the `<Text>`-tag is used to define which font family should be used for a certain piece of text.
89
-
90
- When you create a new Blits app using the available [getting started boilerplate](../getting_started/getting_started.md) you'll be able to use the `lato` (Lato regular) and `raleway` (Raleway ExtraBold) fonts out of the box.
91
-
92
- But of course, you can also use any custom font that you want, to give your App the unique look and feel that fits with the design.
93
-
94
- Adding a custom font to a Blits App is quite straightforward. First, you'll need to place a `.ttf`, `.woff` or `.otf` version of your font in the `public` folder (i.e. `public/fonts/comic-sans.ttf`).
95
-
96
- Then you'll need to register the custom font in the Launch settings of your app (in `src/index.js`). The `fonts`-key in the settings is an `Array` that specifies all available fonts in your App.
97
-
98
- Just add a new font object with the necessary details:
99
-
100
- ```js
101
- fonts: [
102
- // ...
103
- {
104
- family: 'ComicSans', // the font name used in your App
105
- type: 'msdf', // type of text renderer to use (msdf or web)
106
- file: 'fonts/Comic-Sans.ttf', // location of the ttf file
107
- },
108
- // ..
109
- ],
110
- ```
111
-
112
- From this moment on you'll be able to use the font `ComicSans` anywhere in your App:
113
-
114
- ```xml
115
- <Text font="ComicSans" content="I'm Comic Sans font!" />
116
- ```
117
-
118
- ### Custom characters
119
-
120
- For MSDF font, a font atlas is created. By default this atlas includes all printable main ASCII characters. If you know beforehand that you won't need certain characters, it would be more optimal to generate only those characters that are actually needed.
121
-
122
- Similarly, if you need characters outside of the default set, like accents or other special characters, then these will need to be included in the generated font atlas.
123
-
124
- In order to control which characters are generated for a specific font, you can add a _font config file_ per font inside the `assets/fonts` folder. Its name should match the name of the font file, like so: `myfont.config.json`.
125
-
126
- The config file should look something like this:
127
-
128
- ```json
129
- {
130
- "charset": "0123456789éåaü"
131
- }
132
- ```
133
- With the configuration above, only numbers and the specified letters with accents will be generated (i.e. the default character set is overwritten).
134
-
135
- > Please note that only special characters and accents that are part of the original font can be added to the generated font atlas. Other characters will show up as a `?`.
@@ -1,195 +0,0 @@
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 +0,0 @@
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,83 +0,0 @@
1
- # Template syntax
2
-
3
- Blits uses an easy-to-read _XML-style_ template syntax. The syntax is inspired by frameworks like VueJS, so if you are familiar with Vue, you will probably recognize certain concepts.
4
-
5
- The `template` key in the _Component configuration object_ is used to specify a string with this XML-like template structure. Templates can often span multiple lines. In those cases, it's advisable to use `template literals` (enclosed by backticks).
6
-
7
- Similar to HTML, you can use arguments and nested tags. Self-closing tags and HTML-style comments are also supported in Blits templates.
8
-
9
- The default tag that can be used in templates is the `<Element>` tag. The Element tag corresponds to a node in the Lightning 3 renderer.
10
-
11
- For each element, there is a set of predefined render properties, such as `x`, `y`, `w`, `color` that define how the element looks and where it is positioned. Detailed information on all the attributes supported by the `<Element>` tag can be found [here](./element_attributes.md).
12
-
13
- Now let's consider the following template example:
14
-
15
- ```xml
16
- <Element x="20" y="20">
17
- <Element w="100" h="100" x="360" color="#0891b2" />
18
- <Element w="$width" h="$height" color="$color" />
19
- <Element :w="$changingWidth" :h="Math.floor($height / 5)" :color="$highlight" />
20
- </Element>
21
- ```
22
-
23
- ## Hardcoded arguments
24
-
25
- In the template above, you'll observe certain arguments with hardcoded values (i.e. `w="100"` and `color="#0891b2"`).
26
- You can use hardcoded arguments to configure the parts of your template that you know will never change.
27
-
28
- ## Dynamic arguments
29
-
30
- Additionally, some arguments contain a value prefixed with a dollar sign (`$`). These are so called _dynamic_ arguments.
31
-
32
- The `$`-sign used in a template refers to a (state) variable on the Component. And when the template renders, it automatically populates
33
- these arguments with dynamic values based on the initial state of your Component.
34
-
35
- It's important to realize that dynamic arguments are only set _once_. Changing a value used in a dynamic argument, won't be reflected
36
- on screen. For that you will need to use _reactive_ arguments.
37
-
38
- ## Reactive arguments
39
-
40
- If you look at the template example above you'll notice that certain arguments are prefixed with a colon sign (`:`). Prefixing an argument
41
- with a colon makes it not only dynamic but also _reactive_.
42
-
43
- Reactive arguments are set with the initial state value when your component first renders, exactly as a dynamic argument does.
44
-
45
- The difference is that a _re-render_ of (a portion of) the template will be triggered whenever the referenced value in your Component's internal state changes.
46
-
47
- This concept of _reactive data binding_ eliminates the need for manual template patching and allows for a declarative way of programming.
48
-
49
- Reactive arguments also support _interpolation_. This enables the use of simple JavaScript instructions, such as ternary conditions or basic String and Math manipulations, right inside your template arguments.
50
-
51
- For more complex logic, it's recommended to abstract this into a [Component method](../components/methods.md) or a [Computed property](../components/computed_properties.md).
52
-
53
- # Abstracting template portions to custom components
54
-
55
- As your template grows in complexity, you may want to organize your codebase with custom components, abstracting a complex template into smaller, reusable pieces.
56
-
57
- When you've abstracted a portion of a template into a separate component, a _Menu_ component for example, you'll first need to `import` the file that contains the Menu component.
58
-
59
- Next, you have to _register_ the imported custom component. The `components`-key in the _configuration object_ is used for this.
60
-
61
- The `components` key is an _object literal_, where the value is the reference to the custom Blits component and the key will correspond with the _tag_ that can be used in the template to insert the component.
62
-
63
- Once this is done, the tag (`<Menu>` for example) is available for use in your component's template. You can use the component tag as many times as you want. For each tag, a new Component instance will be created.
64
-
65
- The example below shows how to use a custom `Menu` and `Button` (aliased to `MyButton`) component inside a template.
66
-
67
- ```js
68
- import Menu from './components/menu.js'
69
- import Button from './components/button.js'
70
-
71
- export default Blits.Component('MyComponent', {
72
- components: {
73
- Menu, // makes <Menu /> available for use in the template
74
- MyButton: Button, // makes Button available as <MyButton /> in the template
75
- },
76
- template: `
77
- <Element>
78
- <Menu />
79
- <MyButton />
80
- </Element>
81
- `
82
- })
83
- ```