@lightningjs/blits 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/NOTICE +9 -0
- package/docs/_sidebar.md +1 -0
- package/docs/built-in/directives.md +4 -6
- package/docs/built-in/for-loop.md +6 -8
- package/docs/components/component_state.md +3 -5
- package/docs/components/computed_properties.md +3 -5
- package/docs/components/lifecycle_events.md +2 -4
- package/docs/components/methods.md +1 -3
- package/docs/components/props.md +3 -5
- package/docs/components/user_input.md +6 -8
- package/docs/components/utilities.md +1 -2
- package/docs/components/watchers.md +2 -4
- package/docs/essentials/application_root.md +1 -3
- package/docs/essentials/components.md +2 -4
- package/docs/essentials/displaying_images.md +4 -6
- package/docs/essentials/displaying_text.md +4 -6
- package/docs/essentials/element_attributes.md +10 -12
- package/docs/essentials/template_syntax.md +5 -7
- package/docs/getting_started/file_structure.md +9 -11
- package/docs/getting_started/getting_started.md +5 -7
- package/docs/plugins/language.md +172 -0
- package/docs/plugins/text-to-speech-announcer.md +2 -4
- package/docs/sidebar.json +4 -0
- package/docs/transitions_animations/transitions.md +5 -7
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +3 -2
- package/src/component/base/index.js +4 -1
- package/src/component/base/log.js +1 -1
- package/src/component/base/methods.js +1 -2
- package/src/component/setup/state.js +9 -13
- package/src/component.d.ts +6 -0
- package/src/component.js +30 -10
- package/src/components/FPScounter.js +56 -12
- package/src/components/index.js +0 -2
- package/src/components/index.orig.js +0 -2
- package/src/engines/L3/element.js +56 -66
- package/src/helpers/fetchJson.js +34 -0
- package/src/lib/codegenerator/generator.js +104 -28
- package/src/lib/codegenerator/generator.test.js +184 -0
- package/src/lib/colors/colors.js +6 -7
- package/src/lib/reactivity/reactive.js +3 -5
- package/src/lib/symbols.js +1 -0
- package/src/lib/templateparser/parser.js +1 -1
- package/src/plugin.d.ts +71 -0
- package/src/plugin.js +23 -0
- package/src/{components/Image.orig.js → plugins/index.js} +2 -17
- package/src/plugins/language.js +122 -0
- package/src/components/Image.js +0 -52
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v1.3.0
|
|
4
|
+
|
|
5
|
+
_19 aug 2024_
|
|
6
|
+
|
|
7
|
+
- Fixed bug in for-loop when key is not a string but a number
|
|
8
|
+
- Added `$shallow`-modifier to for-loop
|
|
9
|
+
- Added several performance optimizations
|
|
10
|
+
- Added support for dynamic arguments in object notation (i.e. `mount="{x: $x, y: $y}"`)
|
|
11
|
+
|
|
12
|
+
## v1.2.0
|
|
13
|
+
|
|
14
|
+
_5 aug 2024_
|
|
15
|
+
|
|
16
|
+
- Added plugin system for Blits
|
|
17
|
+
- Added Language plugin, modeled after L2-SDK Language plugin
|
|
18
|
+
- Removed unused built-in Image component
|
|
19
|
+
- Marked `this.trigger()`-method as deprecated in definition file
|
|
20
|
+
- Removed double assignment of `this.node` during element creation
|
|
21
|
+
|
|
3
22
|
## v1.1.0
|
|
4
23
|
|
|
5
24
|
_25 july 2024_
|
package/NOTICE
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
1
|
This component contains software that is Copyright 2023 Comcast Cable Communications Management, LLC.
|
|
2
2
|
The component is licensed to you under the Apache License, Version 2.0 (the "License").
|
|
3
3
|
You may not use the component except in compliance with the License.
|
|
4
|
+
|
|
5
|
+
The component may include material which is licensed under other licenses / copyrights as
|
|
6
|
+
listed below. Your use of this material within the component is also subject to the terms and
|
|
7
|
+
conditions of these licenses. The LICENSE file contains the text of all the licenses which apply
|
|
8
|
+
within this component.
|
|
9
|
+
|
|
10
|
+
This repository uses components from the Lightning-SDK. Any components from the Lightning-SDK are:
|
|
11
|
+
Copyright (c) 2020 Metrological
|
|
12
|
+
Licensed under the Apache License, Version 2.0
|
package/docs/_sidebar.md
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
## Directives
|
|
1
|
+
# Directives
|
|
4
2
|
|
|
5
3
|
Blits comes with a few built-in attributes that tap into specific behaviour provided by the framework - also known as _directives_. Most of them can be used in the template on both Elements and Components.
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
## Show-directive
|
|
8
6
|
|
|
9
7
|
The `show` attribute allows you to conditionally show and hide Components and Elements.
|
|
10
8
|
|
|
@@ -17,7 +15,7 @@ When passed a _truthy_ value, such as `true` or `1`, the element will be made vi
|
|
|
17
15
|
</Element>
|
|
18
16
|
```
|
|
19
17
|
|
|
20
|
-
|
|
18
|
+
## Is-directive
|
|
21
19
|
|
|
22
20
|
The `is` directive allows you to dynamically instantiate a Component based on a `state` variable or a passed `prop`.
|
|
23
21
|
|
|
@@ -39,7 +37,7 @@ export default Blits('DynamicComponents', {
|
|
|
39
37
|
|
|
40
38
|
At the moment it's not possible to use the `is`-attribute as a _reactive_ attribute and have a component change type after instantiation.
|
|
41
39
|
|
|
42
|
-
|
|
40
|
+
## Ref-attribute
|
|
43
41
|
|
|
44
42
|
The declarative coding style that is promoted in Blits components, should generally remove the need to directly interact with individual Elements or Components in your template. However, in some cases you may need to reference them directly. For example, in order to delegate the focus.
|
|
45
43
|
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
## For loop
|
|
1
|
+
# For loop
|
|
4
2
|
|
|
5
3
|
The for loop is technically also a [directive](../directives.md), but such an important one that it deserves it's own section.
|
|
6
4
|
|
|
@@ -11,7 +9,7 @@ The for loop take an `Array` of data, loops over it and for each Array-item an E
|
|
|
11
9
|
> Important: the for loop is a powerful and often used directive. Within Blits it's optimized to be as performant as possible. But if used incorrectly, it can be the cause of slow performance. So please read carefully through this entire section.
|
|
12
10
|
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
## Basic syntax
|
|
15
13
|
|
|
16
14
|
The for-loop directive should be added as an attribute on the Element or Component that you want to repeat for each item in your Array. In the template syntax a `for ... in` construct is used. This ultimately transpiles down to a classic, optimized for loop.
|
|
17
15
|
|
|
@@ -33,7 +31,7 @@ export default Blits('ForLoop', {
|
|
|
33
31
|
The example above will generate 3 _lime green_ elements, based on the array of `items` in the Component state. They will appear on top of each other though, since they have no `x` and `y` positioning (which default to 0).
|
|
34
32
|
|
|
35
33
|
|
|
36
|
-
|
|
34
|
+
## Using the index
|
|
37
35
|
|
|
38
36
|
In order to fix the example above and make all 3 elements visible, we can use the `index` of the Array, to position each item correctly.
|
|
39
37
|
|
|
@@ -59,7 +57,7 @@ export default Blits('ForLoop', {
|
|
|
59
57
|
You will now see that each Element is positioned next to each other, with a 50px space in between.
|
|
60
58
|
|
|
61
59
|
|
|
62
|
-
|
|
60
|
+
## Using variables inside a for loop
|
|
63
61
|
|
|
64
62
|
When iterating over an Array in the for loop, you can reference the current Array item under the name specified in the for-in construct, prefixed with a `$`-sign. Besides this scoped Array item context, you _also_ have access to any `prop`, `state` or `computed` variable as you loop over an Array.
|
|
65
63
|
|
|
@@ -99,7 +97,7 @@ export default Blits('ForLoop', {
|
|
|
99
97
|
|
|
100
98
|
This will generate 3 squares aligned next to each other, each with a differrent color and they will use the _alpha_ specific in the Component state.
|
|
101
99
|
|
|
102
|
-
|
|
100
|
+
## The importance of using the key attribute
|
|
103
101
|
|
|
104
102
|
The examples above have demonstrated the basic usage of the for-loop. But they are all missing one _very important_ ingredient to make sure that for-loops that are subject to change, continue to perform well. Meet the `key`-attribute.
|
|
105
103
|
|
|
@@ -160,7 +158,7 @@ In the example above we have added the `key`-attribute in the template. Now when
|
|
|
160
158
|
|
|
161
159
|
If we would ommit the `key`-attribute, then whenever we push a new item to the Array, the for-loop would dispose all the old Elements and create new instances for _each_ item in the array.
|
|
162
160
|
|
|
163
|
-
|
|
161
|
+
## Referencing elements in the for loop
|
|
164
162
|
|
|
165
163
|
When you specify a `for`-attribute on an Element or a Component, it will effectively create multiple Elements / Components depending
|
|
166
164
|
on the length of the Array.
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
## Component State
|
|
1
|
+
# Component State
|
|
4
2
|
|
|
5
3
|
In Blits, a component can be as simple as a template with fixed, hardcoded values. However, for dynamic behavior and logic, you'll often want to give your components an _internal state_.
|
|
6
4
|
|
|
@@ -36,13 +34,13 @@ export default Blits.Component('MyComponent', {
|
|
|
36
34
|
})
|
|
37
35
|
```
|
|
38
36
|
|
|
39
|
-
|
|
37
|
+
## Accessing State in Templates
|
|
40
38
|
|
|
41
39
|
As explained in the [template section](../essentials/template_syntax.md), you can refer to state variables in a template by prefixing the state variable name with a _dollar sign_ (e.g., `$alpha`). Think of the `$`-sign as a reference to the `this`-scope of the component.
|
|
42
40
|
|
|
43
41
|
For nested objects, you can use _dot notation_ (e.g., `$style.dimensions.w`).
|
|
44
42
|
|
|
45
|
-
|
|
43
|
+
## Accessing State in Component Code
|
|
46
44
|
|
|
47
45
|
In your component's code, you can reference state variables directly within the `this`-scope. For instance, a state variable named `color` can be accessed (and modified) by referencing `this.color`.
|
|
48
46
|
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
## Computed properties
|
|
1
|
+
# Computed properties
|
|
4
2
|
|
|
5
3
|
So far we've learned how to utilize a Component's [internal state](./component_state.md) and [props](./props.md) passed by a parent into a child component.
|
|
6
4
|
|
|
@@ -10,7 +8,7 @@ However, as these operations become more complex it's more clear and more mainta
|
|
|
10
8
|
Computed properties are a powerful tool for enhancing the readability of your component code. By abstracting complex or frequently used calculations from your template into computed properties, you can make your code more concise and easier to understand.
|
|
11
9
|
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
## Defining computed properties
|
|
14
12
|
|
|
15
13
|
Within the `computed`-key of the Component configuration object, you can specify an object of `functions`. Each function name you define (`offset()` for example) becomes accessible as a _computed property_.
|
|
16
14
|
|
|
@@ -35,7 +33,7 @@ export default Blits.Component('MyComponent', {
|
|
|
35
33
|
})
|
|
36
34
|
```
|
|
37
35
|
|
|
38
|
-
|
|
36
|
+
## Reactivity
|
|
39
37
|
|
|
40
38
|
Within a computed property, you can reference one or more state variables or props and _return_ a value based on calculations or logical operations.
|
|
41
39
|
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
## Hooking into Lifecycle Events
|
|
1
|
+
# Hooking into Lifecycle Events
|
|
4
2
|
|
|
5
3
|
Blits components follow a defined flow of lifecycle events. You can integrate specific logic into these events by specifying them in the `hooks` key of the Component configuration object.
|
|
6
4
|
|
|
7
5
|
For each available lifecycle event, you can define a function with the same name as the event itself. This function will then execute each time the lifecycle event is triggered for your component's instance. It's essential to use a regular function instead of an arrow function if you intend to access the `this` scope of your component instance.
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
## Lifecycle Events
|
|
10
8
|
|
|
11
9
|
The following lifecycle events are available in Blits components.
|
|
12
10
|
|
package/docs/components/props.md
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
## Props
|
|
1
|
+
# Props
|
|
4
2
|
|
|
5
3
|
Components in Blits have their own [internal state](./component_state.md) and logic, and as such a Component is self-contained. However, as each component is part of a larger App scope, they may need to display different behaviors or appearances based on the rest of the app.
|
|
6
4
|
|
|
7
5
|
To achieve this, components can receive `props` from their parent component.
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
## Defining and passing props
|
|
10
8
|
|
|
11
9
|
In the Component configuration object, you can specify exactly which props a component accepts. These props are passed to the component via attributes in the parent component's template. Any attributes that are not explicitly defined as a prop will be ignored.
|
|
12
10
|
|
|
@@ -27,7 +25,7 @@ there is no need to specifically reference the `props`-key. Blits automatically
|
|
|
27
25
|
|
|
28
26
|
Since props are used to pass information from a parent to a child, it's important not to attempt to _modify_ props inside your child component. If changes based on the prop from the parent are needed, you should probably use the prop in a so called [computed property](./computed_properties.md).
|
|
29
27
|
|
|
30
|
-
|
|
28
|
+
## Advanced usage
|
|
31
29
|
|
|
32
30
|
For more advanced usage, you can define props using an array with an `object` for each prop, instead of just a string with the accepted name. Within each prop object, you can:
|
|
33
31
|
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
## Handling User Input
|
|
1
|
+
# Handling User Input
|
|
4
2
|
|
|
5
3
|
In order to allow users to interact with your app, you will want to capture and handle _user input_. If you are developing a TV based app this will
|
|
6
4
|
often be key input via a remote control.
|
|
7
5
|
|
|
8
6
|
Blits offers an intuitive and straightforward interface to handle key input in Components.
|
|
9
7
|
|
|
10
|
-
|
|
8
|
+
## Focus
|
|
11
9
|
|
|
12
10
|
Before diving into the specifics of key handling, it is important to understand the basic concept of _focus_.
|
|
13
11
|
|
|
@@ -17,7 +15,7 @@ The component that has focus, is the one that is responsible for handling the us
|
|
|
17
15
|
|
|
18
16
|
For example, when a user clicks the _right_ or _left_ button while a _Poster Component_ has focus, it is that instance of the Poster Component that will _receive_ the first key press event.
|
|
19
17
|
|
|
20
|
-
|
|
18
|
+
## Configuring Input Handling
|
|
21
19
|
|
|
22
20
|
Within the Component configuration object, the `input` key is used to define how the component should react to specific key presses when it has focus. The `input` key should be an `object literal` of `functions` for each input event that the component wants to handle.
|
|
23
21
|
|
|
@@ -40,7 +38,7 @@ export default Blits.Component('MyComponent', {
|
|
|
40
38
|
}
|
|
41
39
|
```
|
|
42
40
|
|
|
43
|
-
|
|
41
|
+
## Catch-All Handling
|
|
44
42
|
|
|
45
43
|
To allow a focused component to respond to any key and act as a _catch-all_, you can add an `any()` function to the input object. As it receives the `InputEvent` object as the first argument, you can abstract the key press in there and handle (or ignore) it as you wish.
|
|
46
44
|
|
|
@@ -54,7 +52,7 @@ To allow a focused component to respond to any key and act as a _catch-all_, you
|
|
|
54
52
|
}
|
|
55
53
|
```
|
|
56
54
|
|
|
57
|
-
|
|
55
|
+
## Event Handling Chain
|
|
58
56
|
|
|
59
57
|
If the currently focused component does not handle a key press, Blits will traverse up the component hierarchy, checking for any _parent_ component that does have a function defined for that key press in the `input`-key. This input event handling chain continues until it reaches the root Application component.
|
|
60
58
|
|
|
@@ -75,7 +73,7 @@ When a component handles a key press by having a corresponding function specifie
|
|
|
75
73
|
}
|
|
76
74
|
```
|
|
77
75
|
|
|
78
|
-
|
|
76
|
+
## Custom Keycode mapping
|
|
79
77
|
|
|
80
78
|
Blits comes with a default keycode mapping. This mapping is a sensible default that works in your desktop browser and with most RDK based devices.
|
|
81
79
|
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
## Watchers
|
|
1
|
+
# Watchers
|
|
4
2
|
|
|
5
3
|
In some cases, you may want to execute specific actions whenever the value of a state variable, a prop, or a computed property changes. These actions could involve dispatching an event or updating another state variable.
|
|
6
4
|
|
|
@@ -8,7 +6,7 @@ You might be tempted to handle this functionality inside a computed property, bu
|
|
|
8
6
|
|
|
9
7
|
Instead, Blits allows you to specify **watchers** to trigger functionality when certain variables change.
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
## Using Watchers
|
|
12
10
|
|
|
13
11
|
Within the `watch` key of the _Component configuration object_, you can define an object of _watcher functions_.
|
|
14
12
|
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
## Components
|
|
1
|
+
# Components
|
|
4
2
|
|
|
5
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
|
|
6
4
|
reusable pieces of code and logic.
|
|
@@ -14,7 +12,7 @@ Components in Blits follow a clearly defined structure, which helps keep your co
|
|
|
14
12
|
|
|
15
13
|
This universal structure is also valuable for creating drop-in components that can be easily shared across projects.
|
|
16
14
|
|
|
17
|
-
|
|
15
|
+
## Creating a new Component
|
|
18
16
|
|
|
19
17
|
Let's see how to create a new component and explore the basic anatomy of a component.
|
|
20
18
|
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
## Displaying Images
|
|
1
|
+
# Displaying Images
|
|
4
2
|
|
|
5
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.
|
|
6
4
|
|
|
@@ -15,13 +13,13 @@ Remote images are also supported and can be linked directly (e.g., `http://mycdn
|
|
|
15
13
|
<Element src="http://mycdn.com/artists/jimi_hendrix/woodstock.jpg" w="1920" h="1080" />
|
|
16
14
|
```
|
|
17
15
|
|
|
18
|
-
|
|
16
|
+
## Sizing and Scaling
|
|
19
17
|
|
|
20
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
|
|
21
19
|
|
|
22
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.
|
|
23
21
|
|
|
24
|
-
|
|
22
|
+
## Colorization
|
|
25
23
|
|
|
26
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.
|
|
27
25
|
|
|
@@ -36,7 +34,7 @@ By default, all Elements with a `src` attribute get a solid white background, wi
|
|
|
36
34
|
/>
|
|
37
35
|
```
|
|
38
36
|
|
|
39
|
-
|
|
37
|
+
## Asynchronous Loading
|
|
40
38
|
|
|
41
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.
|
|
42
40
|
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
## Displaying Text
|
|
1
|
+
# Displaying Text
|
|
4
2
|
|
|
5
3
|
Besides displaying images, it is also very common to have _texts_ in an App.
|
|
6
4
|
|
|
@@ -17,7 +15,7 @@ Blits comes with a built-in `<Text>`-tag for displaying and styling texts in a s
|
|
|
17
15
|
```
|
|
18
16
|
You can use the Text-tag anywhere in your template, without the need to explicitly import and register it in your Component.
|
|
19
17
|
|
|
20
|
-
|
|
18
|
+
## Available attributes on the Text tag
|
|
21
19
|
|
|
22
20
|
The Text-tag accepts the following attributes:
|
|
23
21
|
|
|
@@ -35,7 +33,7 @@ The Text-tag accepts the following attributes:
|
|
|
35
33
|
- `textoverflow` - the suffix to be added when text is cropped due to bounds limits, defaults to `...`
|
|
36
34
|
|
|
37
35
|
|
|
38
|
-
|
|
36
|
+
## SDF and Canvas2d
|
|
39
37
|
|
|
40
38
|
Compared to Lightning 2, texts have improved a lot in Lightning 3, thanks to the SDF (Signed Distance Field) Text renderer.
|
|
41
39
|
|
|
@@ -43,7 +41,7 @@ With the SDF text renderer, texts appear a lot _sharper_ on screen. The SDF tech
|
|
|
43
41
|
|
|
44
42
|
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.
|
|
45
43
|
|
|
46
|
-
|
|
44
|
+
## Using custom fonts
|
|
47
45
|
|
|
48
46
|
The `font`-attribute on the `<Text>`-tag is used to define which font family should be used for a certain piece of text.
|
|
49
47
|
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
## Supported Element attributes
|
|
1
|
+
# Supported Element attributes
|
|
4
2
|
|
|
5
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.
|
|
6
4
|
|
|
7
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.
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
## Positioning and Dimensions
|
|
10
8
|
|
|
11
9
|
In order to position and set the dimensions of an Element, the following attributes can be used.
|
|
12
10
|
|
|
@@ -25,7 +23,7 @@ All positioning and dimension related attributes, when not specified, will defau
|
|
|
25
23
|
</Element>
|
|
26
24
|
```
|
|
27
25
|
|
|
28
|
-
|
|
26
|
+
### Using percentages
|
|
29
27
|
|
|
30
28
|
Besides using values in pixels (i.e. `w="100" h="300"`), you can also specify _percentages_ for the positioning and dimensions attributes.
|
|
31
29
|
|
|
@@ -38,7 +36,7 @@ Besides using values in pixels (i.e. `w="100" h="300"`), you can also specify _p
|
|
|
38
36
|
The percentage value specified for `w` and `x` will be calculated as the percentage of the _width_ (`w`) of the parent element.
|
|
39
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.
|
|
40
38
|
|
|
41
|
-
|
|
39
|
+
## Colors
|
|
42
40
|
|
|
43
41
|
By default, Elements have a transparent background color. The `color` attribute can be used to give an Element a color.
|
|
44
42
|
|
|
@@ -66,7 +64,7 @@ _HSL and HSLA formats are planned to be added in the future._
|
|
|
66
64
|
<Element w="200" h="200" color="skyblue" />
|
|
67
65
|
```
|
|
68
66
|
|
|
69
|
-
|
|
67
|
+
### Basic linear gradients
|
|
70
68
|
|
|
71
69
|
The color attribute can also be used to specify basic linear gradients.
|
|
72
70
|
|
|
@@ -81,7 +79,7 @@ Again, you can use "normal" notation for the colors (like hexadecimal or rgba) a
|
|
|
81
79
|
<Element w="200" h="200" color="{bottom: 'black'}" />
|
|
82
80
|
```
|
|
83
81
|
|
|
84
|
-
|
|
82
|
+
## Alpha and visibility
|
|
85
83
|
|
|
86
84
|
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).
|
|
87
85
|
|
|
@@ -93,7 +91,7 @@ The value of alpha is also applied recursively to the children of the Element th
|
|
|
93
91
|
</Element>
|
|
94
92
|
```
|
|
95
93
|
|
|
96
|
-
|
|
94
|
+
## Rotation and scaling
|
|
97
95
|
|
|
98
96
|
If you want to rotate an Element, you can use the `rotation` attribute. The rotation attribute in Blits accepts values in _degrees_.
|
|
99
97
|
|
|
@@ -121,7 +119,7 @@ Similar to rotation, scale is also applied recursively to children down the tree
|
|
|
121
119
|
<Element w="200" h="200" color="#000" scale="{x: 1, y: 3.14}" />
|
|
122
120
|
```
|
|
123
121
|
|
|
124
|
-
|
|
122
|
+
## Mounting point
|
|
125
123
|
|
|
126
124
|
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.
|
|
127
125
|
|
|
@@ -139,7 +137,7 @@ In the case where the `x` and `y` values are the same (i.e. centering with `{x:
|
|
|
139
137
|
<Element w="200" h="200" x="800" y="700" color="#333" mount="0.5" />
|
|
140
138
|
```
|
|
141
139
|
|
|
142
|
-
|
|
140
|
+
## Pivot point
|
|
143
141
|
|
|
144
142
|
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.
|
|
145
143
|
|
|
@@ -156,7 +154,7 @@ In the case where the `x` and `y` values are the same, you can also just supply
|
|
|
156
154
|
<Element w="200" h="200" x="800" y="700" pivot="0.9" rotation="42" />
|
|
157
155
|
```
|
|
158
156
|
|
|
159
|
-
|
|
157
|
+
## Clipping / overflow
|
|
160
158
|
|
|
161
159
|
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.
|
|
162
160
|
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
## Template syntax
|
|
1
|
+
# Template syntax
|
|
4
2
|
|
|
5
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.
|
|
6
4
|
|
|
@@ -22,12 +20,12 @@ Now let's consider the following template example:
|
|
|
22
20
|
</Element>
|
|
23
21
|
```
|
|
24
22
|
|
|
25
|
-
|
|
23
|
+
## Hardcoded arguments
|
|
26
24
|
|
|
27
25
|
In the template above, you'll observe certain arguments with hardcoded values (i.e. `w="100"` and `color="#0891b2"`).
|
|
28
26
|
You can use hardcoded arguments to configure the parts of your template that you know will never change.
|
|
29
27
|
|
|
30
|
-
|
|
28
|
+
## Dynamic arguments
|
|
31
29
|
|
|
32
30
|
Additionally, some arguments contain a value prefixed with a dollar sign (`$`). These are so called _dynamic_ arguments.
|
|
33
31
|
|
|
@@ -37,7 +35,7 @@ these arguments with dynamic values based on the initial state of your Component
|
|
|
37
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
|
|
38
36
|
on screen. For that you will need to use _reactive_ arguments.
|
|
39
37
|
|
|
40
|
-
|
|
38
|
+
## Reactive arguments
|
|
41
39
|
|
|
42
40
|
If you look at the template example above you'll notice that certain arguments are prefixed with a colon sign (`:`). Prefixing an argument
|
|
43
41
|
with a colon makes it not only dynamic but also _reactive_.
|
|
@@ -52,7 +50,7 @@ Reactive arguments also support _interpolation_. This enables the use of simple
|
|
|
52
50
|
|
|
53
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).
|
|
54
52
|
|
|
55
|
-
|
|
53
|
+
# Abstracting template portions to custom components
|
|
56
54
|
|
|
57
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.
|
|
58
56
|
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
## File structure
|
|
1
|
+
# File structure
|
|
4
2
|
|
|
5
3
|
Once you have created a new Blits App using the boilerplate described in the [Getting started](getting_started.md), you should have a project with all the basics you need.
|
|
6
4
|
|
|
7
5
|
Let's review the basic file structure, and take a closer look at the important ones.
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
## package.json
|
|
10
8
|
|
|
11
9
|
In the root of your newly created app, you will obviously find a `package.json` with all the necessary (dev) dependencies.
|
|
12
10
|
|
|
@@ -14,23 +12,23 @@ In order to build a Blits based Lightning 3 app, all you need is `@lightningjs/b
|
|
|
14
12
|
|
|
15
13
|
Feel free to install and import any custom library that your App may need. But always be mindful of the size and impact an external dependency may have - especially when developing for low powered devices (as is often the case with Lightning apps).
|
|
16
14
|
|
|
17
|
-
|
|
15
|
+
## index.html
|
|
18
16
|
|
|
19
17
|
You will also find an `index.html` at the root of your project. This is where the browser will be pointed to, in order to launch your Blits App.
|
|
20
18
|
|
|
21
19
|
If you inspect the source you will see some minimal HTML. The essential parts of the HTML are the `<div>` where the canvas will be injected into, and the `<script>`-tag that points to the `index.js` of the App.
|
|
22
20
|
|
|
23
|
-
|
|
21
|
+
## public
|
|
24
22
|
|
|
25
23
|
There is also a `public` folder in your project. This folder is used for storing public assets, such as App images and fonts.
|
|
26
24
|
|
|
27
25
|
During development, your assets are loaded directly from this folder. And if you run a production build, the entire `public` folder is copied over to the distributable version.
|
|
28
26
|
|
|
29
|
-
|
|
27
|
+
## src
|
|
30
28
|
|
|
31
29
|
The `src`-folder is where all your custom App code lives.
|
|
32
30
|
|
|
33
|
-
|
|
31
|
+
### index.js
|
|
34
32
|
|
|
35
33
|
`src/index.js` is the entry point of your App. This file imports the Blits `Launch`-method which initializes the App.
|
|
36
34
|
|
|
@@ -40,11 +38,11 @@ The `Blits.Launch()`-method accepts 3 parameters:
|
|
|
40
38
|
2) `target` - the HTML target to append the canvas to. This can either be an `id` of an HTML element in `index.html`, or you can pass a reference to HTML element itself
|
|
41
39
|
3) `settings` - an `object` with settings
|
|
42
40
|
|
|
43
|
-
|
|
41
|
+
### App.js
|
|
44
42
|
|
|
45
43
|
`src/App.js` is the default file where the root application component lives. It's expected to export a `Blits.Application()`-instance, which is the base component of your App.
|
|
46
44
|
|
|
47
|
-
|
|
45
|
+
## components and pages folder
|
|
48
46
|
|
|
49
47
|
The rest of your App can be built out using components. You are free to organize your components as you wish, but we recommend using a separate file for each component and placing them in the `src/components`-folder.
|
|
50
48
|
|
|
@@ -54,7 +52,7 @@ Feel free to further organize and possibly nest your Component files to your own
|
|
|
54
52
|
|
|
55
53
|
Pages in your App are technically just Blits components as well. But to keep things clear, we often place them in a separate `pages`-folder alongside the `components`-folder (e.g. `src/pages/Home.js` and `src/pages/Details.js`)
|
|
56
54
|
|
|
57
|
-
|
|
55
|
+
### Custom code
|
|
58
56
|
|
|
59
57
|
If your App needs libraries for specific (business) logic that can be shared across components (such as API calls) you can place them anywhere in your `src` folder. For example in a folder named `src/lib` or `src/api`.
|
|
60
58
|
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
## Getting Started
|
|
1
|
+
# Getting Started
|
|
4
2
|
|
|
5
3
|
To get started with Blits, follow these simple steps to set up your development environment and create your first Lightning 3 App.
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
## Installation
|
|
8
6
|
|
|
9
7
|
1. Open your terminal or command prompt.
|
|
10
8
|
|
|
@@ -23,7 +21,7 @@ cd my_blits_app
|
|
|
23
21
|
npm install
|
|
24
22
|
```
|
|
25
23
|
|
|
26
|
-
|
|
24
|
+
## Running Your App
|
|
27
25
|
|
|
28
26
|
4. After installing the dependencies, you can start your development server by running:
|
|
29
27
|
|
|
@@ -35,13 +33,13 @@ This command will create an application bundle and launch a development server u
|
|
|
35
33
|
|
|
36
34
|
Once the server is up and running, open your web browser and navigate to the URL displayed in the console. Congratulations! You now have your brand new Blits Lightning 3 App up and running.
|
|
37
35
|
|
|
38
|
-
|
|
36
|
+
## Coding environment
|
|
39
37
|
|
|
40
38
|
You can use any code editor of your preference to further develop your Blits App.
|
|
41
39
|
|
|
42
40
|
We recommend using VS code, since we have a dedicated [VS code extension for Blits](https://marketplace.visualstudio.com/items?itemName=LightningJS.lightning-blits) that provides better syntax highlighting, code completion, error
|
|
43
41
|
checking, and other features to make working with Blits easier.
|
|
44
42
|
|
|
45
|
-
|
|
43
|
+
## Next steps
|
|
46
44
|
|
|
47
45
|
You are now ready to dive into the world of App development using Blits. In the following sections, we will explore the core concepts and guide you through building your TV applications step by step.
|