@lightningjs/blits 1.30.1 → 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 (70) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/package.json +4 -3
  3. package/src/router/router.js +2 -0
  4. package/vite/preCompiler.js +6 -1
  5. package/.editorconfig +0 -7
  6. package/.eslintignore +0 -1
  7. package/.eslintrc.cjs +0 -65
  8. package/.github/workflows/comment-lint-results.yml +0 -125
  9. package/.github/workflows/comment-test-results.yml +0 -109
  10. package/.github/workflows/deploy-docs.yml +0 -27
  11. package/.github/workflows/run-blits-tests.yml +0 -142
  12. package/.github/workflows/run-lint.yml +0 -128
  13. package/.husky/pre-commit +0 -1
  14. package/.husky/pre-push +0 -1
  15. package/.vscode/extensions.json +0 -7
  16. package/.vscode/settings.json +0 -9
  17. package/banner.png +0 -0
  18. package/docs/.nojekyll +0 -0
  19. package/docs/README.md +0 -19
  20. package/docs/_sidebar.md +0 -37
  21. package/docs/built-in/directives.md +0 -50
  22. package/docs/built-in/for-loop.md +0 -204
  23. package/docs/built-in/layout.md +0 -168
  24. package/docs/components/component_state.md +0 -90
  25. package/docs/components/computed_properties.md +0 -45
  26. package/docs/components/lifecycle_events.md +0 -42
  27. package/docs/components/methods.md +0 -45
  28. package/docs/components/props.md +0 -56
  29. package/docs/components/user_input.md +0 -186
  30. package/docs/components/utility_methods.md +0 -320
  31. package/docs/components/watchers.md +0 -34
  32. package/docs/essentials/application_root.md +0 -19
  33. package/docs/essentials/components.md +0 -68
  34. package/docs/essentials/displaying_images.md +0 -67
  35. package/docs/essentials/displaying_text.md +0 -135
  36. package/docs/essentials/element_attributes.md +0 -195
  37. package/docs/essentials/settings.md +0 -117
  38. package/docs/essentials/template_syntax.md +0 -83
  39. package/docs/getting_started/file_structure.md +0 -58
  40. package/docs/getting_started/getting_started.md +0 -45
  41. package/docs/getting_started/intro.md +0 -20
  42. package/docs/index.html +0 -47
  43. package/docs/performance/lazy-loading.md +0 -161
  44. package/docs/plugins/global_app_state.md +0 -98
  45. package/docs/plugins/language.md +0 -172
  46. package/docs/plugins/text-to-speech-announcer.md +0 -120
  47. package/docs/plugins/theme.md +0 -176
  48. package/docs/router/basics.md +0 -175
  49. package/docs/router/hooks.md +0 -70
  50. package/docs/router/transitions.md +0 -146
  51. package/docs/sidebar.json +0 -171
  52. package/docs/transitions_animations/transitions.md +0 -150
  53. package/jsconfig.json +0 -12
  54. package/src/component/setup/props.test.js +0 -238
  55. package/src/component.test.js +0 -388
  56. package/src/components/Circle.orig.js +0 -31
  57. package/src/components/FPScounter.orig.js +0 -121
  58. package/src/components/RouterView.orig.js +0 -54
  59. package/src/components/Sprite.orig.js +0 -58
  60. package/src/components/index.orig.js +0 -28
  61. package/src/engines/L3/element.test.js +0 -579
  62. package/src/helpers/deepEqualArray.test.js +0 -127
  63. package/src/lib/codegenerator/generator.test.js +0 -3801
  64. package/src/lib/colors/colors.test.js +0 -290
  65. package/src/lib/componentId.test.js +0 -84
  66. package/src/lib/eventListeners.test.js +0 -236
  67. package/src/lib/reactivity/effect.test.js +0 -35
  68. package/src/lib/reactivity/reactive.test.js +0 -27
  69. package/src/lib/templateparser/parser.test.js +0 -1411
  70. package/src/router/router.test.js +0 -473
@@ -1,19 +0,0 @@
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 +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
- ```